Skip to content

Commit

Permalink
Show Pending Transactions on Account Details Page
Browse files Browse the repository at this point in the history
Part of work for #1
  • Loading branch information
groberts314 committed Dec 31, 2018
1 parent 8119896 commit 05ebcdd
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 73 deletions.
15 changes: 11 additions & 4 deletions src/DashAccountingSystem/Controllers/LedgerAccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public async Task<IActionResult> AddAccount(int tenantId)
[HttpGet]
[Route("Ledger/{tenantId:int}/Accounts/{accountId:int}", Name = "accountDetails")]
[TenantViewDataFilter]
public async Task<IActionResult> AccountDetails(int tenantId, int accountId)
[PaginationValidationFilter]
public async Task<IActionResult> AccountDetails(
[FromRoute] int tenantId,
[FromRoute] int accountId,
[FromQuery] PaginationViewModel pagination)
{
// TODO: Either in here or in an attribute, verify authorization for the tenant
var account = await _accountRepository.GetAccountByIdAsync(accountId);
Expand All @@ -55,12 +59,15 @@ public async Task<IActionResult> AccountDetails(int tenantId, int accountId)

// TODO: If doesn't belong to selected tenant either 404 not found or 403 forbidden

// TODO: Get pending and recently posted transactions and use an enhanced view model
// instead of raw Account model
// Get pending transactions
var pendingTransactions = await _accountRepository.GetPendingTransactionsAsync(accountId);

// TODO: Get posted transactions

var resultViewModel = new AccountDetailsViewModel()
{
Account = account
Account = account,
PendingTransactions = pendingTransactions.Select(AccountTransactionViewModel.FromModel)
};

return View(resultViewModel);
Expand Down
22 changes: 1 addition & 21 deletions src/DashAccountingSystem/Data/Repositories/AccountRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,7 @@ public async Task<IEnumerable<JournalEntryAccount>> GetPendingTransactionsAsync(

}

public Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsAsync(int accountId, int pageNumber, int pageSize)
{
throw new NotImplementedException();
}

public Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByDateRangeAsync(int accountId, DateTime dateRangeStart, DateTime dateRangeEnd)
{
throw new NotImplementedException();
}

public Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByMonthAsync(int accountId, int year, byte month)
{
throw new NotImplementedException();
}

public Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByPeriodAsync(int accountId, int accountingPeriodId)
{
throw new NotImplementedException();
}

public Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByQuarterAsync(int accountId, int year, byte quarter)
public Task<PagedResult<JournalEntryAccount>> GetPostedTransactionsAsync(int accountId, Pagination pagination)
{
throw new NotImplementedException();
}
Expand Down
10 changes: 2 additions & 8 deletions src/DashAccountingSystem/Data/Repositories/IAccountRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using DashAccountingSystem.Data.Models;

Expand All @@ -12,10 +10,6 @@ public interface IAccountRepository
Task<IEnumerable<Account>> GetAccountsByTenantAsync(int tenantId);
Task<Account> GetAccountByIdAsync(int accountId);
Task<IEnumerable<JournalEntryAccount>> GetPendingTransactionsAsync(int accountId);
Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByDateRangeAsync(int accountId, DateTime dateRangeStart, DateTime dateRangeEnd);
Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByMonthAsync(int accountId, int year, byte month);
Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByPeriodAsync(int accountId, int accountingPeriodId);
Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsByQuarterAsync(int accountId, int year, byte quarter);
Task<IEnumerable<JournalEntryAccount>> GetPostedTransactionsAsync(int accountId, int pageNumber, int pageSize);
Task<PagedResult<JournalEntryAccount>> GetPostedTransactionsAsync(int accountId, Pagination pagination);
}
}
7 changes: 3 additions & 4 deletions src/DashAccountingSystem/Models/AccountDetailsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using DashAccountingSystem.Data.Models;

namespace DashAccountingSystem.Models
{
public class AccountDetailsViewModel
{
public Account Account { get; set; }
public IEnumerable<AccountTransactionViewModel> PendingTransactions { get; set; }
public PagedResult<AccountTransactionViewModel> Transactions { get; set; }
}
}
104 changes: 104 additions & 0 deletions src/DashAccountingSystem/Models/AccountTransactionViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using DashAccountingSystem.Data.Models;

namespace DashAccountingSystem.Models
{
public class AccountTransactionViewModel : INumberedJournalEntry
{
// Journal Entry top-level
public int Id { get; set; }
public int EntryId { get; set; }
public TransactionStatus Status { get; set; }
public string Description { get; set; }
public string Note { get; set; }
public uint? CheckNumber { get; set; }
public DateTime Created { get; set; }
public DateTime? Updated { get; set; }
public DateTime EntryDate { get; set; }
public DateTime? PostDate { get; set; }
public DateTime? CancelDate { get; set; }

public DateTime Date
{
get
{
switch (Status)
{
case TransactionStatus.Posted:
return PostDate.Value;
case TransactionStatus.Pending:
default:
return EntryDate;
}
}
}

public AccountingPeriodLiteViewModel Period { get; set; }

// Account Level
public string AssetType { get; set; }
public decimal Amount { get; set; }

public AmountType AmountType
{
get
{
if (Amount < 0.0m)
return AmountType.Credit;
else
return AmountType.Debit;
}
}

public decimal? Debit
{
get
{
if (AmountType == AmountType.Debit)
return Amount;

return null;
}
}

public decimal? Credit
{
get
{
if (AmountType == AmountType.Credit)
return -Amount;

return null;
}
}

public decimal? PreviousBalance { get; set; }
public decimal? NewBalance { get; set; }

public static AccountTransactionViewModel FromModel(JournalEntryAccount model)
{
if (model == null)
return null;

return new AccountTransactionViewModel()
{
Id = model.JournalEntry.Id,
EntryId = model.JournalEntry.EntryId,
EntryDate = model.JournalEntry.EntryDate,
Description = model.JournalEntry.Description,
Note = model.JournalEntry.Note,
CheckNumber = model.JournalEntry.CheckNumber,
Created = model.JournalEntry.Created,
Updated = model.JournalEntry.Updated,
PostDate = model.JournalEntry.PostDate,
CancelDate = model.JournalEntry.CancelDate,
Status = model.JournalEntry.Status,
Period = AccountingPeriodLiteViewModel.FromModel(model.JournalEntry.AccountingPeriod),
AssetType = model.AssetType.Name,
Amount = model.Amount,
PreviousBalance = model.PreviousBalance,
NewBalance = model.NewBalance
};
}
}
}
38 changes: 38 additions & 0 deletions src/DashAccountingSystem/Models/AccountingPeriodLiteViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using DashAccountingSystem.Data.Models;

namespace DashAccountingSystem.Models
{
public class AccountingPeriodLiteViewModel
{
public int Id { get; set; }
public AccountingPeriodType PeriodType { get; set; }
public int Year { get; set; }
public byte Month { get; set; }
public byte Quarter { get; set; }
public string Name { get; set; }
public bool Closed { get; set; }

public static AccountingPeriodLiteViewModel FromModel(AccountingPeriod model)
{
if (model == null)
return null;

return Fill(new AccountingPeriodViewModel(), model);
}

public static AccountingPeriodLiteViewModel Fill(
AccountingPeriodLiteViewModel viewModel,
AccountingPeriod model)
{
viewModel.Id = model.Id;
viewModel.PeriodType = model.PeriodType;
viewModel.Year = model.Year;
viewModel.Month = model.Month;
viewModel.Quarter = model.Quarter;
viewModel.Name = model.Name;
viewModel.Closed = model.Closed;

return viewModel;
}
}
}
24 changes: 4 additions & 20 deletions src/DashAccountingSystem/Models/AccountingPeriodViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,17 @@

namespace DashAccountingSystem.Models
{
public class AccountingPeriodViewModel
public class AccountingPeriodViewModel : AccountingPeriodLiteViewModel
{
public int Id { get; set; }
public AccountingPeriodType PeriodType { get; set; }
public int Year { get; set; }
public byte Month { get; set; }
public byte Quarter { get; set; }
public string Name { get; set; }
public bool Closed { get; set; }
public bool Current { get; set; }
public bool Selected { get; set; }

public static AccountingPeriodViewModel FromModel(AccountingPeriod accountingPeriod)
public static new AccountingPeriodViewModel FromModel(AccountingPeriod model)
{
if (accountingPeriod == null)
if (model == null)
return null;

return new AccountingPeriodViewModel()
{
Id = accountingPeriod.Id,
PeriodType = accountingPeriod.PeriodType,
Year = accountingPeriod.Year,
Month = accountingPeriod.Month,
Quarter = accountingPeriod.Quarter,
Name = accountingPeriod.Name,
Closed = accountingPeriod.Closed
};
return Fill(new AccountingPeriodViewModel(), model) as AccountingPeriodViewModel;
}
}
}
7 changes: 7 additions & 0 deletions src/DashAccountingSystem/Models/INumberedJournalEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DashAccountingSystem.Models
{
public interface INumberedJournalEntry
{
int EntryId { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DashAccountingSystem.Data.Models;

namespace DashAccountingSystem.Models
{
public class JournalEntryDetailedViewModel : JournalEntryBaseViewModel
public class JournalEntryDetailedViewModel : JournalEntryBaseViewModel, INumberedJournalEntry
{
public int EntryId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@using DashAccountingSystem.Data.Models
@using DashAccountingSystem.Extensions
@using DashAccountingSystem.Models
@model AccountDetailsViewModel

@{
var account = Model.Account;
ViewData["Title"] = account.AccountNumber + " - " + account.Name;
Layout = "~/Views/Shared/_Layout.cshtml";

const string amountFormat = "#,##0.00;(#,##0.00)";

var pendingDebits = account.PendingDebits ?? 0.0m;
Expand All @@ -19,7 +20,7 @@

<partial name="~/Views/Shared/_TenantMastheadAndNavPartial.cshtml" />

<div style="margin: 22px auto 22px 22px">
<div style="margin: 22px auto">
<a asp-route="editAccount"
asp-route-tenantid="@account.TenantId"
asp-route-accountid="@account.Id">
Expand All @@ -28,6 +29,8 @@
<a asp-route="accountsIndex" asp-route-tenantid="@account.TenantId">Back to List</a>
</div>

<h4>Summary</h4>

<div>
<dl class="dl-horizontal account-meta-data">
<dt>Account #</dt>
Expand All @@ -43,7 +46,7 @@
</dl>
</div>

<table class="table table-condensed table-striped meta-data-table">
<table class="table table-condensed table-striped meta-data-table" style="margin-bottom:22px">
<tbody>
<tr>
<td>Current Balance</td>
Expand Down Expand Up @@ -71,3 +74,14 @@
</tr>
</tbody>
</table>

<h4>Pending Transactions</h4>
@if (!Model.PendingTransactions.HasAny())
{
<p>There are no pending journal entries</p>
}
else
{
<partial name="_AccountPendingTransactionsTablePartial" for="PendingTransactions" />
}

Loading

0 comments on commit 05ebcdd

Please sign in to comment.