Skip to content

Commit

Permalink
#343 - Show income total in month summary.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed May 15, 2021
1 parent f7cf4e0 commit 29b8d5c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
19 changes: 15 additions & 4 deletions src/Money.Blazor.Host/Pages/Summary.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ExpenseBagPublishButton Text="You have expenses created when offline. Upload them now..." class="mb-4" />

@if (SelectedPeriod != null)
{
{
<div class="mb-3">
<SortButton TType="SummarySortType" @bind-Current="@SortDescriptor" Changed="@OnSorted" />

Expand All @@ -52,14 +52,14 @@
</div>
}

@if (TotalAmout != null && TotalAmout.Value == 0)
@if (ExpenseTotal != null && ExpenseTotal.Value == 0)
{
<Alert Title="No data." Message="Let's add some expenses." Mode="@AlertMode.Warning" />
}
else if (Categories != null)
{
<div class="graph">
@if (TotalAmout != null)
@if (ExpenseTotal != null)
{
<div class="card bar-graph bar-graph-summary" @onclick="@(() => OpenOverview(SelectedPeriod))">
<div class="card-body">
Expand All @@ -69,7 +69,18 @@
</h3>

<div class="value">
<div class="amount">@FormatPrice(TotalAmout)</div>
<div class="amount">
@if (IncomeTotal != null)
{
<span class="text-success mr-2">
@FormatPrice(IncomeTotal)
</span>
}

<span class="text-danger">
@FormatPrice(ExpenseTotal)
</span>
</div>
</div>
</div>
</div>
Expand Down
19 changes: 15 additions & 4 deletions src/Money.Blazor.Host/Pages/Summary.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public partial class Summary<T> :
protected IReadOnlyCollection<T> PeriodGuesses { get; set; }

protected LoadingContext CategoriesLoading { get; } = new LoadingContext();
protected Price TotalAmout { get; private set; }
protected Price IncomeTotal { get; private set; }
protected Price ExpenseTotal { get; private set; }
protected List<CategoryWithAmountModel> Categories { get; private set; }

protected SortDescriptor<SummarySortType> SortDescriptor { get; set; }
Expand Down Expand Up @@ -116,7 +117,14 @@ protected async Task LoadSelectedPeriodAsync()
try
{
Categories = await Queries.QueryAsync(CreateCategoriesQuery(SelectedPeriod));
TotalAmout = await Queries.QueryAsync(CreateTotalQuery(SelectedPeriod));

var incomeQuery = CreateIncomeTotalQuery(SelectedPeriod);
if (incomeQuery != null)
IncomeTotal = await Queries.QueryAsync(CreateIncomeTotalQuery(SelectedPeriod));
else
IncomeTotal = null;

ExpenseTotal = await Queries.QueryAsync(CreateExpenseTotalQuery(SelectedPeriod));
}
catch (MissingDefaultCurrentException)
{
Expand All @@ -128,8 +136,11 @@ protected async Task LoadSelectedPeriodAsync()
}
}

protected virtual IQuery<Price> CreateTotalQuery(T item)
=> throw Ensure.Exception.NotImplemented($"Missing override for method '{nameof(CreateTotalQuery)}'.");
protected virtual IQuery<Price> CreateIncomeTotalQuery(T item)
=> null;

protected virtual IQuery<Price> CreateExpenseTotalQuery(T item)
=> throw Ensure.Exception.NotImplemented($"Missing override for method '{nameof(CreateExpenseTotalQuery)}'.");

protected virtual IQuery<List<CategoryWithAmountModel>> CreateCategoriesQuery(T item)
=> throw Ensure.Exception.NotImplemented($"Missing override for method '{nameof(CreateCategoriesQuery)}'.");
Expand Down
5 changes: 4 additions & 1 deletion src/Money.Blazor.Host/Pages/SummaryMonth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ protected override (MonthModel, IReadOnlyCollection<MonthModel>) CreateSelectedP
protected override IQuery<List<MonthModel>> CreatePeriodsQuery()
=> new ListMonthWithOutcome();

protected override IQuery<Price> CreateTotalQuery(MonthModel item)
protected override IQuery<Price> CreateIncomeTotalQuery(MonthModel item)
=> new GetTotalMonthIncome(item);

protected override IQuery<Price> CreateExpenseTotalQuery(MonthModel item)
=> new GetTotalMonthOutcome(item);

protected override IQuery<List<CategoryWithAmountModel>> CreateCategoriesQuery(MonthModel item)
Expand Down
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Pages/SummaryYear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override (YearModel, IReadOnlyCollection<YearModel>) CreateSelectedPer
protected override IQuery<List<YearModel>> CreatePeriodsQuery()
=> new ListYearWithOutcome();

protected override IQuery<Price> CreateTotalQuery(YearModel item)
protected override IQuery<Price> CreateExpenseTotalQuery(YearModel item)
=> new GetTotalYearOutcome(item);

protected override IQuery<List<CategoryWithAmountModel>> CreateCategoriesQuery(YearModel item)
Expand Down

0 comments on commit 29b8d5c

Please sign in to comment.