-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basically functional version of add journal entry. Hit a milestone!
- Loading branch information
1 parent
7f925c1
commit 4bb6d7f
Showing
15 changed files
with
402 additions
and
168 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
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
10 changes: 10 additions & 0 deletions
10
src/DashAccountingSystem/Data/Scripts/delete-journal-and-zero-out-accounts.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,10 @@ | ||
/* DANGER - Don't do it unless you mean it! */ | ||
/* Affects all tenants! */ | ||
|
||
UPDATE "Account" | ||
SET "PendingDebits" = NULL | ||
,"PendingCredits" = NULL | ||
,"CurrentBalance" = 0 | ||
,"BalanceUpdated" = now() AT TIME ZONE 'UTC'; | ||
|
||
TRUNCATE TABLE "JournalEntry" RESTART IDENTITY CASCADE; |
39 changes: 39 additions & 0 deletions
39
src/DashAccountingSystem/Extensions/ClaimsPrincipalExtensions.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,39 @@ | ||
using System; | ||
using System.Security.Claims; | ||
|
||
namespace DashAccountingSystem.Extensions | ||
{ | ||
public static class ClaimsPrincipalExtensions | ||
{ | ||
public static string GetUserFirstName(this ClaimsPrincipal user) | ||
{ | ||
return user.FindFirstValue(ClaimTypes.GivenName); | ||
} | ||
|
||
public static string GetUserFullName(this ClaimsPrincipal user) | ||
{ | ||
return $"{user.GetUserFirstName()} {user.GetUserFullName()}".Trim(); | ||
} | ||
|
||
public static Guid GetUserId(this ClaimsPrincipal user) | ||
{ | ||
var nameIdentifierClaim = user.FindFirstValue(ClaimTypes.NameIdentifier); | ||
|
||
if (string.IsNullOrWhiteSpace(nameIdentifierClaim)) | ||
throw new ArgumentException("Could not find the 'name identifier' claim"); | ||
|
||
Guid userId; | ||
|
||
if (!Guid.TryParse(nameIdentifierClaim, out userId)) | ||
throw new ArgumentException( | ||
$"'name identifier' claim does not seem to be a GUID type value as expected; value is: '{nameIdentifierClaim}'"); | ||
|
||
return userId; | ||
} | ||
|
||
public static string GetUserLastName(this ClaimsPrincipal user) | ||
{ | ||
return user.FindFirstValue(ClaimTypes.Surname); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/DashAccountingSystem/Filters/JournalEntryViewModelValidationFilterAttribute.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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.Extensions.Logging; | ||
using DashAccountingSystem.Models; | ||
|
||
namespace DashAccountingSystem.Filters | ||
{ | ||
public class JournalEntryViewModelValidationFilterAttribute : ActionFilterAttribute | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public JournalEntryViewModelValidationFilterAttribute( | ||
ILogger<JournalEntryViewModelValidationFilterAttribute> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) | ||
{ | ||
if (context.ModelState.IsValid) | ||
{ | ||
// TODO: Extract the view model and perform additional validation: | ||
// * Must contain at least two accounts of each asset type with non-zero values | ||
// * Must balance (debits must equal credits) | ||
} | ||
|
||
return base.OnActionExecutionAsync(context, next); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/DashAccountingSystem/Models/JournalEntryAccountDetailedViewModel.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,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DashAccountingSystem.Data.Models; | ||
|
||
namespace DashAccountingSystem.Models | ||
{ | ||
public class JournalEntryAccountDetailedViewModel : JournalEntryAccountBaseViewModel | ||
{ | ||
[Display(Name = "Account Name")] | ||
public string AccountName { get; set; } | ||
|
||
[Display(Name = "Asset Type")] | ||
public string AssetType { get; set; } | ||
|
||
public static JournalEntryAccountDetailedViewModel FromModel(JournalEntryAccount model) | ||
{ | ||
if (model == null) | ||
return null; | ||
|
||
return new JournalEntryAccountDetailedViewModel() | ||
{ | ||
AccountId = model.AccountId, | ||
AccountName = model.Account.DisplayName, | ||
AssetType = model.AssetType.Name, | ||
AssetTypeId = model.AssetTypeId, | ||
Credit = model.AmountType == BalanceType.Credit ? Math.Abs(model.Amount) : 0.0m, | ||
Debit = model.AmountType == BalanceType.Debit ? model.Amount : 0.0m | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.