From 0434285bc150665387c63d4fbad269c3e2de83f3 Mon Sep 17 00:00:00 2001 From: "Ridzwan (Rizz) Nur Saidy" Date: Thu, 21 Nov 2024 11:45:22 -0800 Subject: [PATCH 1/3] initialized branch for debug/8-income-report --- .../Views/Financials/IncomeStatement.cshtml | 13 ++++++++++-- src/Api/Controllers/FinancialsController.cs | 21 +++++++++++++------ src/Api/appsettings.json | 10 ++++++++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml b/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml index 2029defbf..1f6ddf77a 100644 --- a/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml +++ b/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml @@ -2,8 +2,17 @@ @{ ViewBag.Title = "IncomeStatement"; Layout = "~/Views/Shared/_Layout_bootstrap.cshtml"; - @* var netIncome = Model.Where(a => a.IsExpense == false).Sum(a => a.Amount) - Model.Where(a => a.IsExpense == true).Sum(a => a.Amount); *@ - var netIncome = 100; + + // Handle null or empty model + if (Model == null || !Model.Any()) + { +

No data available to display.

+ return; // Stop further processing + } + + // Calculate net income + var netIncome = Model.Where(a => a.IsExpense == false).Sum(a => a.Amount) - + Model.Where(a => a.IsExpense == true).Sum(a => a.Amount); }

Income Statement

diff --git a/src/Api/Controllers/FinancialsController.cs b/src/Api/Controllers/FinancialsController.cs index e88240623..0aae8b039 100644 --- a/src/Api/Controllers/FinancialsController.cs +++ b/src/Api/Controllers/FinancialsController.cs @@ -335,15 +335,24 @@ public ActionResult BalanceSheet() return new ObjectResult(Dto); } - [HttpGet] - [Route("IncomeStatement")] - // TODO: this generates an error a.ContraAccounts' is invalid inside an 'Include' operation - public ActionResult IncomeStatement() + [HttpGet] + [Route("IncomeStatement")] + public ActionResult IncomeStatement() + { + var dto = _financialService.IncomeStatement(); + + // Ensure the DTO is not null + if (dto == null) { - var Dto = _financialService.IncomeStatement(); - return new ObjectResult(Dto); + // Return an empty list or handle appropriately + dto = new List(); } + return new ObjectResult(dto); + } + + + #region Private Methods private IList BuildAccountGrouping(IList allAccounts, int? parentAccountId) diff --git a/src/Api/appsettings.json b/src/Api/appsettings.json index 5064e3b6e..81f524553 100644 --- a/src/Api/appsettings.json +++ b/src/Api/appsettings.json @@ -9,5 +9,13 @@ }, "ConnectionStrings": { "DefaultConnection": "Data Source={0};User ID={1};Password={2};Initial Catalog={3};TrustServerCertificate=yes;MultipleActiveResultSets=true;" - } + }, + "JwtSettings": { + "validIssuer": "Good Deed Books API", + "validAudience": "http://localhost:8001", + "expires": 60 +}, +"SECRET": { + "key": "GoodDeedBooks1234GoodDeedBooks1234" +} } \ No newline at end of file From 6f1280f0ac1f45479161b821aa99a07d89b4ed6d Mon Sep 17 00:00:00 2001 From: "Ridzwan (Rizz) Nur Saidy" Date: Thu, 21 Nov 2024 13:41:49 -0800 Subject: [PATCH 2/3] updated income method --- .../Controllers/FinancialsController.cs | 45 ++++--- .../Views/Financials/IncomeStatement.cshtml | 113 +++++++++--------- src/Api/Controllers/FinancialsController.cs | 25 ++-- src/Api/Data/ApplicationIdentityDbContext.cs | 4 + 4 files changed, 106 insertions(+), 81 deletions(-) diff --git a/src/AccountGoWeb/Controllers/FinancialsController.cs b/src/AccountGoWeb/Controllers/FinancialsController.cs index 1c0a3c5d8..5877e3a0e 100644 --- a/src/AccountGoWeb/Controllers/FinancialsController.cs +++ b/src/AccountGoWeb/Controllers/FinancialsController.cs @@ -166,27 +166,38 @@ public async System.Threading.Tasks.Task BalanceSheet() } public async Task IncomeStatement() - { - ViewBag.PageContentHeader = "Income Statement"; +{ + ViewBag.PageContentHeader = "Income Statement"; - using (var client = new System.Net.Http.HttpClient()) + using (var client = new System.Net.Http.HttpClient()) + { + var baseUri = _baseConfig!["ApiUrl"]; + client.BaseAddress = new System.Uri(baseUri!); + client.DefaultRequestHeaders.Accept.Clear(); + + try + { + var response = await client.GetAsync(baseUri + "financials/incomestatement"); + if (response.IsSuccessStatusCode) { - var baseUri = _baseConfig!["ApiUrl"]; - client.BaseAddress = new System.Uri(baseUri!); - client.DefaultRequestHeaders.Accept.Clear(); - var response = await client.GetAsync(baseUri + "financials/incomestatement"); - if (response.IsSuccessStatusCode) - { - var responseJson = await response.Content.ReadAsStringAsync(); - var incomeStatementModel = Newtonsoft.Json.JsonConvert.DeserializeObject>(responseJson); - return View(incomeStatementModel); - } + var responseJson = await response.Content.ReadAsStringAsync(); + var incomeStatementModel = Newtonsoft.Json.JsonConvert.DeserializeObject>(responseJson); + return View(incomeStatementModel); + } + else + { + ViewBag.Error = "Failed to fetch income statement data."; } - - return View(); - //var Dto = _financialService.IncomeStatement(); - //return View(Dto); } + catch (Exception ex) + { + ViewBag.Error = $"Error: {ex.Message}"; + } + } + + return View(new List()); +} + public IActionResult Banks() { diff --git a/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml b/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml index 1f6ddf77a..54cf2ac2e 100644 --- a/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml +++ b/src/AccountGoWeb/Views/Financials/IncomeStatement.cshtml @@ -1,67 +1,70 @@ @model ICollection + @{ - ViewBag.Title = "IncomeStatement"; + ViewBag.Title = "Income Statement"; Layout = "~/Views/Shared/_Layout_bootstrap.cshtml"; - // Handle null or empty model - if (Model == null || !Model.Any()) - { -

No data available to display.

- return; // Stop further processing - } - - // Calculate net income - var netIncome = Model.Where(a => a.IsExpense == false).Sum(a => a.Amount) - - Model.Where(a => a.IsExpense == true).Sum(a => a.Amount); + var netIncome = Model?.Where(a => !a.IsExpense).Sum(a => a.Amount) ?? 0 - + Model?.Where(a => a.IsExpense).Sum(a => a.Amount) ?? 0; }

Income Statement

-
-

Income Statement

-
-
- - - - - - - @foreach (var asset in Model.Where(a => a.IsExpense == false)) - { +@if (ViewBag.Error != null) +{ +
@ViewBag.Error
+} +else if (Model == null || !Model.Any()) +{ +

No data available to display.

+} +else +{ +
+

Revenues

+
Account CodeAccount NameAmount
- - - + + + - } - - - - -
@Html.ActionLink((string)string.Format("{0}", asset.AccountCode), "account", new { id = asset.AccountId })@asset.AccountName@asset.AmountAccount CodeAccount NameAmount
Total Revenues@Model.Where(a => a.IsExpense == false).Sum(a => a.Amount)
-
-
- - - - - - - @foreach (var asset in Model.Where(a => a.IsExpense == true)) - { + @foreach (var item in Model.Where(a => !a.IsExpense)) + { + + + + + + } - - - + + - } - - - - -
Account CodeAccount NameAmount
@Html.ActionLink(item.AccountCode, "Account", new { id = item.AccountId })@item.AccountName@item.Amount
@Html.ActionLink((string)string.Format("{0}", asset.AccountCode), "account", new { id = asset.AccountId })@asset.AccountName@asset.AmountTotal Revenues@Model.Where(a => !a.IsExpense).Sum(a => a.Amount)
Total Expenses@Model.Where(a => a.IsExpense == true).Sum(a => a.Amount)
-
-
- Net Income: @netIncome -
\ No newline at end of file + + +
+

Expenses

+ + + + + + + @foreach (var item in Model.Where(a => a.IsExpense)) + { + + + + + + } + + + + +
Account CodeAccount NameAmount
@Html.ActionLink(item.AccountCode, "Account", new { id = item.AccountId })@item.AccountName@item.Amount
Total Expenses@Model.Where(a => a.IsExpense).Sum(a => a.Amount)
+
+
+ Net Income: @netIncome +
+} diff --git a/src/Api/Controllers/FinancialsController.cs b/src/Api/Controllers/FinancialsController.cs index 0aae8b039..a0e7dae9f 100644 --- a/src/Api/Controllers/FinancialsController.cs +++ b/src/Api/Controllers/FinancialsController.cs @@ -335,24 +335,31 @@ public ActionResult BalanceSheet() return new ObjectResult(Dto); } - [HttpGet] + [HttpGet] [Route("IncomeStatement")] - public ActionResult IncomeStatement() + public IActionResult IncomeStatement() { - var dto = _financialService.IncomeStatement(); + try + { + var incomeStatementData = _financialService.IncomeStatement(); + + // Ensure the data is not null + if (incomeStatementData == null) + { + incomeStatementData = new List(); + } - // Ensure the DTO is not null - if (dto == null) + return Ok(incomeStatementData); + } + catch (Exception ex) { - // Return an empty list or handle appropriately - dto = new List(); + return BadRequest(new { message = "Error fetching income statement", details = ex.Message }); } - - return new ObjectResult(dto); } + #region Private Methods private IList BuildAccountGrouping(IList allAccounts, int? parentAccountId) diff --git a/src/Api/Data/ApplicationIdentityDbContext.cs b/src/Api/Data/ApplicationIdentityDbContext.cs index b528e99d9..ef07f1c94 100644 --- a/src/Api/Data/ApplicationIdentityDbContext.cs +++ b/src/Api/Data/ApplicationIdentityDbContext.cs @@ -14,5 +14,9 @@ protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } + + + + } } From 60aa12fda3e69e7daeef8ee1c0a72876d318dac2 Mon Sep 17 00:00:00 2001 From: "Ridzwan (Rizz) Nur Saidy" Date: Thu, 21 Nov 2024 15:14:00 -0800 Subject: [PATCH 3/3] Debugged Income Statement report --- src/Core/Domain/Financials/Account.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Domain/Financials/Account.cs b/src/Core/Domain/Financials/Account.cs index 7385ec215..5b9a2a6a1 100644 --- a/src/Core/Domain/Financials/Account.cs +++ b/src/Core/Domain/Financials/Account.cs @@ -46,7 +46,7 @@ public Account() public virtual Company Company { get; set; } public virtual ICollection ChildAccounts { get; set; } - [NotMapped] + // [NotMapped] public virtual ICollection ContraAccounts { get; set; } public virtual ICollection GeneralLedgerLines { get; set; }