-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from DRJTechnology/Development
Addition of bank statement upload
- Loading branch information
Showing
26 changed files
with
475 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/PropertyPortfolioManager.Client/Interfaces/IBankStatementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using PropertyPortfolioManager.Models.Model.Document; | ||
|
||
namespace PropertyPortfolioManager.Client.Interfaces | ||
{ | ||
public interface IBankStatementService : IGenericDataService | ||
{ | ||
Task UploadBankStatement(Stream content, string filename); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/PropertyPortfolioManager.Client/Pages/UploadBankStatement.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@page "/uploadstatement" | ||
|
||
<SectionContent SectionName="top-bar"> | ||
<div class="row"> | ||
<div class="col"> | ||
<div>Upload bank statement</div> | ||
</div> | ||
</div> | ||
</SectionContent> | ||
|
||
<div class="page-content"> | ||
<InputFile OnChange="HandleFileSelection" /> | ||
</div> | ||
|
||
@if (file != null) | ||
{ | ||
<div class="page-content"> | ||
<p><strong>File Name:</strong> @file.Name</p> | ||
<p><strong>File Size:</strong> @file.Size bytes</p> | ||
</div> | ||
} |
21 changes: 21 additions & 0 deletions
21
src/PropertyPortfolioManager.Client/Pages/UploadBankStatement.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Forms; | ||
using PropertyPortfolioManager.Client.Interfaces; | ||
|
||
namespace PropertyPortfolioManager.Client.Pages | ||
{ | ||
public partial class UploadBankStatement | ||
{ | ||
[Inject] | ||
public IBankStatementService bankStatementService { get; set; } | ||
|
||
private IBrowserFile file; | ||
|
||
private async Task HandleFileSelection(InputFileChangeEventArgs e) | ||
{ | ||
file = e.File; | ||
var stream = file.OpenReadStream(); | ||
await bankStatementService.UploadBankStatement(stream, file.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/PropertyPortfolioManager.Client/Services/BankStatementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using PropertyPortfolioManager.Client.Interfaces; | ||
|
||
namespace PropertyPortfolioManager.Client.Services | ||
{ | ||
public class BankStatementService : GenericDataService, IBankStatementService | ||
{ | ||
public BankStatementService(HttpClient httpClient) | ||
: base(httpClient) | ||
{ | ||
ApiControllerName = "BankStatement"; | ||
} | ||
|
||
public async Task UploadBankStatement(Stream content, string filename) | ||
{ | ||
var formContent = new MultipartFormDataContent(); | ||
formContent.Add(new StreamContent(content), "File", filename); | ||
|
||
var response = await httpClient.PostAsync($"api/BankStatement/UploadBankStatement", formContent); | ||
|
||
if (response == null || !response.IsSuccessStatusCode) | ||
{ | ||
throw new Exception($"Failed to upload bank statement."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/PropertyPortfolioManager.Database/Scripts/Transactions with running balance.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
DECLARE | ||
@PortfolioId int, | ||
@FromDate datetime = null, | ||
@ToDate datetime = null, | ||
@AccountId int = null, | ||
@TransactionTypeId int = null | ||
|
||
SET @PortfolioId = 2 | ||
SET @FromDate = '01 Sep 2023' | ||
SET @ToDate = '01 Oct 2023' | ||
SET @AccountId = 1020 | ||
|
||
DECLARE @StartingBalance MONEY | ||
IF (@FromDate IS NOT NULL) | ||
BEGIN | ||
SELECT @StartingBalance = SUM(amount * direction) | ||
FROM finance.TransactionDetail td | ||
INNER JOIN finance.[Transaction] t ON td.TransactionId = t.Id | ||
INNER JOIN finance.[TransactionType] tt ON t.TransactionTypeId = tt.Id | ||
INNER JOIN finance.Account a on td.AccountId = a.Id | ||
WHERE t.PortfolioId = @PortfolioId | ||
AND (td.[Date] < @FromDate) | ||
AND (ISNULL(@AccountId, 0) = 0 OR td.AccountId = @AccountId) | ||
AND (ISNULL(@TransactionTypeId, 0) = 0 OR t.TransactionTypeId = @TransactionTypeId) | ||
END | ||
|
||
|
||
SELECT @StartingBalance AS StartingBalance | ||
|
||
SELECT td.Id, | ||
td.TransactionId, | ||
-- tt.[Type], | ||
td.[Date], | ||
t.Reference, | ||
-- td.AccountId, | ||
-- a.[Name] AS Account, | ||
td.[Description], | ||
CASE WHEN direction = 1 THEN td.amount ELSE 0 END AS Debit, | ||
CASE WHEN direction = -1 THEN td.amount ELSE 0 END AS Credit | ||
, (SUM(td.amount * td.direction) OVER (ORDER BY td.[Date]) + @StartingBalance) * -1 AS running_total | ||
FROM finance.TransactionDetail td | ||
INNER JOIN finance.[Transaction] t ON td.TransactionId = t.Id | ||
-- INNER JOIN finance.[TransactionType] tt ON t.TransactionTypeId = tt.Id | ||
-- INNER JOIN finance.Account a on td.AccountId = a.Id | ||
WHERE t.PortfolioId = @PortfolioId | ||
AND (@FromDate IS NULL OR td.[Date] >= @FromDate) | ||
AND (@ToDate IS NULL OR td.[Date] < DATEADD(DAY, 1, @ToDate)) | ||
AND (ISNULL(@AccountId, 0) = 0 OR td.AccountId = @AccountId) | ||
AND (ISNULL(@TransactionTypeId, 0) = 0 OR t.TransactionTypeId = @TransactionTypeId) | ||
ORDER BY td.[Date] --DESC--, td.TransactionId, a.[Name], Credit, Debit | ||
|
16 changes: 16 additions & 0 deletions
16
src/PropertyPortfolioManager.Database/Stored Procedures/finance/BankStatement_Upload.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- ========================================================== | ||
-- Author: Dave Brown | ||
-- Create date: 12 Dec 2023 | ||
-- Description: Creates an account record | ||
-- ========================================================== | ||
CREATE PROCEDURE [finance].[BankStatement_Upload] | ||
@AccountId INT, | ||
@Statement finance.StatementTableType READONLY, | ||
@CurrentUserId INT | ||
AS | ||
INSERT INTO [finance].[BankAccountDetail] (AccountId, Date, Amount, Description, TransactionType, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate) | ||
SELECT @AccountId, Date, Amount, Description, TransactionType, 0, @CurrentUserId, SYSDATETIME(), @CurrentUserId, SYSDATETIME() | ||
FROM @Statement | ||
|
||
RETURN 0 | ||
|
16 changes: 16 additions & 0 deletions
16
src/PropertyPortfolioManager.Database/Tables/finance/BankAccountDetail.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE TABLE [finance].[BankAccountDetail] | ||
( | ||
[Id] INT IDENTITY NOT NULL, | ||
[AccountId] INT NOT NULL, | ||
[Date] DATETIME NOT NULL, | ||
[Amount] MONEY NOT NULL, | ||
[Description] NVARCHAR(512) NOT NULL, | ||
[TransactionType] NVARCHAR(512) NOT NULL, | ||
[Deleted] BIT DEFAULT (0) NOT NULL, | ||
[CreateUserId] INT NOT NULL, | ||
[CreateDate] DATETIME CONSTRAINT [DF_BankAccountDetail_CreateDate] DEFAULT (getutcdate()) NOT NULL, | ||
[AmendUserId] INT NOT NULL, | ||
[AmendDate] DATETIME CONSTRAINT [DF_BankAccountDetail_AmendDate] DEFAULT (getutcdate()) NOT NULL, | ||
CONSTRAINT [PK_BankAccountDetail] PRIMARY KEY CLUSTERED ([Id] ASC), | ||
CONSTRAINT [FK_BankAccountDetail_Account] FOREIGN KEY ([AccountId]) REFERENCES [finance].[Account]([Id]) | ||
) |
11 changes: 11 additions & 0 deletions
11
src/PropertyPortfolioManager.Database/Types/StatementTableType.sql.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- ========================================================== | ||
-- Author: Dave Brown | ||
-- Create date: 12 Dec 2023 | ||
-- Description: Creates a Statement Table Type | ||
-- ========================================================== | ||
CREATE TYPE finance.StatementTableType AS TABLE ( | ||
[Date] DATETIME NULL, | ||
[Amount] MONEY NULL, | ||
[Description] NVARCHAR(512) NULL, | ||
[TransactionType] NVARCHAR(512) NULL | ||
); |
11 changes: 11 additions & 0 deletions
11
src/PropertyPortfolioManager.Models/InternalObjects/UploadResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
| ||
namespace PropertyPortfolioManager.Models.InternalObjects | ||
{ | ||
public class UploadResult | ||
{ | ||
public bool Uploaded { get; set; } | ||
public string? FileName { get; set; } | ||
public string? StoredFileName { get; set; } | ||
public int ErrorCode { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/PropertyPortfolioManager.Models/Model/Finance/BankStatementMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using CsvHelper.Configuration; | ||
|
||
namespace PropertyPortfolioManager.Models.Model.Finance | ||
{ | ||
public class BankStatementMap : ClassMap<BankStatementModel> | ||
{ | ||
public BankStatementMap() | ||
{ | ||
Map(m => m.Date).Name("Date"); | ||
Map(m => m.Amount).Name("Amount"); | ||
Map(m => m.Description).Name("Memo"); | ||
Map(m => m.TransactionType).Name("Subcategory"); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/PropertyPortfolioManager.Models/Model/Finance/BankStatementModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace PropertyPortfolioManager.Models.Model.Finance | ||
{ | ||
public class BankStatementModel | ||
{ | ||
public DateTime Date { get; set; } | ||
public decimal Amount { get; set; } | ||
public string Description { get; set; } = string.Empty; | ||
public string TransactionType { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/PropertyPortfolioManager.Server.Repositories.Interfaces/IBankStatementRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using PropertyPortfolioManager.Models.Model.Finance; | ||
using System.Data; | ||
|
||
namespace PropertyPortfolioManager.Server.Repositories.Interfaces | ||
{ | ||
public interface IBankStatementRepository | ||
{ | ||
Task AddBankStatementRecords(int currentUserId, int accountId, DataTable recordList); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/PropertyPortfolioManager.Server.Repositories/BankStatementRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Dapper; | ||
using Microsoft.Graph.Models; | ||
using PropertyPortfolioManager.Models.Model.Finance; | ||
using PropertyPortfolioManager.Server.Repositories.Interfaces; | ||
using System.ComponentModel; | ||
using System.Data; | ||
|
||
namespace PropertyPortfolioManager.Server.Repositories | ||
{ | ||
public class BankStatementRepository : IBankStatementRepository | ||
{ | ||
private readonly IDbConnection dbConnection; | ||
|
||
public BankStatementRepository(IDbConnection dbConnection) | ||
{ | ||
this.dbConnection = dbConnection; | ||
} | ||
|
||
public async Task AddBankStatementRecords(int currentUserId, int accountId, DataTable recordList) | ||
{ | ||
var parameters = new DynamicParameters(); | ||
parameters.Add("@AccountId", accountId); | ||
parameters.Add("@Statement", recordList.AsTableValuedParameter("[finance].[StatementTableType]")); | ||
parameters.Add("@CurrentUserId", currentUserId); | ||
|
||
await this.dbConnection.ExecuteAsync("finance.BankStatement_Upload", parameters, commandType: CommandType.StoredProcedure); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PropertyPortfolioManager.Server.Services.Interfaces/IBankStatementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using PropertyPortfolioManager.Models.Model.Document; | ||
|
||
namespace PropertyPortfolioManager.Server.Services.Interfaces | ||
{ | ||
public interface IBankStatementService | ||
{ | ||
Task UploadBankStatement(int currentUserId, int portfolioId, Stream stream); | ||
} | ||
} |
Oops, something went wrong.