Skip to content

Commit

Permalink
Remove Calculate taxes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 committed Apr 20, 2024
1 parent 6e6ddf7 commit e25be90
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Faktur.Domain.Products;
using Faktur.Domain.Receipts;
using Faktur.Domain.Stores;
using Faktur.Domain.Taxes;
using FluentValidation;
using Logitar.Identity.Domain.Shared;
using MediatR;
Expand All @@ -15,13 +14,11 @@ internal class CreateOrReplaceReceiptItemCommandHandler : IRequestHandler<Create
{
private readonly IReceiptItemQuerier _receiptItemQuerier;
private readonly IReceiptRepository _receiptRepository;
private readonly ITaxRepository _taxRepository;

public CreateOrReplaceReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, IReceiptRepository receiptRepository, ITaxRepository taxRepository)
public CreateOrReplaceReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, IReceiptRepository receiptRepository)
{
_receiptItemQuerier = receiptItemQuerier;
_receiptRepository = receiptRepository;
_taxRepository = taxRepository;
}

public async Task<CreateOrReplaceReceiptItemResult?> Handle(CreateOrReplaceReceiptItemCommand command, CancellationToken cancellationToken)
Expand Down Expand Up @@ -104,9 +101,7 @@ public CreateOrReplaceReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQ

item = new(gtin, sku, label, flags, quantity, unitPrice, price, departmentNumber, department);
receipt.SetItem(command.ItemNumber, item, command.ActorId);

IEnumerable<TaxAggregate> taxes = await _taxRepository.LoadAsync(cancellationToken);
receipt.Calculate(taxes, command.ActorId);
receipt.Calculate(command.ActorId);

await _receiptRepository.SaveAsync(receipt, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public async Task<Receipt> Handle(ImportReceiptCommand command, CancellationToke
NumberUnit? number = NumberUnit.TryCreate(payload.Number);
IEnumerable<TaxAggregate> taxes = await _taxRepository.LoadAsync(cancellationToken);
ReceiptAggregate receipt = ReceiptAggregate.Import(store, payload.IssuedOn, number, items, taxes, command.ActorId);
receipt.Calculate(command.ActorId);

receipt.Calculate(taxes, command.ActorId);
await _receiptRepository.SaveAsync(receipt, cancellationToken);

return await _receiptQuerier.ReadAsync(receipt, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Faktur.Contracts.Receipts;
using Faktur.Domain.Receipts;
using Faktur.Domain.Taxes;
using MediatR;

namespace Faktur.Application.Receipts.Commands;
Expand All @@ -9,13 +8,11 @@ internal class RemoveReceiptItemCommandHandler : IRequestHandler<RemoveReceiptIt
{
private readonly IReceiptItemQuerier _receiptItemQuerier;
private readonly IReceiptRepository _receiptRepository;
private readonly ITaxRepository _taxRepository;

public RemoveReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, IReceiptRepository receiptRepository, ITaxRepository taxRepository)
public RemoveReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, IReceiptRepository receiptRepository)
{
_receiptItemQuerier = receiptItemQuerier;
_receiptRepository = receiptRepository;
_taxRepository = taxRepository;
}

public async Task<ReceiptItem?> Handle(RemoveReceiptItemCommand command, CancellationToken cancellationToken)
Expand All @@ -28,9 +25,7 @@ public RemoveReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, I
ReceiptItem result = await _receiptItemQuerier.ReadAsync(receipt, command.ItemNumber, cancellationToken);

receipt.RemoveItem(command.ItemNumber, command.ActorId);

IEnumerable<TaxAggregate> taxes = await _taxRepository.LoadAsync(cancellationToken);
receipt.Calculate(taxes, command.ActorId);
receipt.Calculate(command.ActorId);

await _receiptRepository.SaveAsync(receipt, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Faktur.Domain.Products;
using Faktur.Domain.Receipts;
using Faktur.Domain.Stores;
using Faktur.Domain.Taxes;
using FluentValidation;
using Logitar.Identity.Domain.Shared;
using MediatR;
Expand All @@ -15,13 +14,11 @@ internal class UpdateReceiptItemCommandHandler : IRequestHandler<UpdateReceiptIt
{
private readonly IReceiptItemQuerier _receiptItemQuerier;
private readonly IReceiptRepository _receiptRepository;
private readonly ITaxRepository _taxRepository;

public UpdateReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, IReceiptRepository receiptRepository, ITaxRepository taxRepository)
public UpdateReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, IReceiptRepository receiptRepository)
{
_receiptItemQuerier = receiptItemQuerier;
_receiptRepository = receiptRepository;
_taxRepository = taxRepository;
}

public async Task<ReceiptItem?> Handle(UpdateReceiptItemCommand command, CancellationToken cancellationToken)
Expand Down Expand Up @@ -77,9 +74,7 @@ public UpdateReceiptItemCommandHandler(IReceiptItemQuerier receiptItemQuerier, I

item = new(gtin, sku, label, flags, quantity, unitPrice, price, departmentNumber, department);
receipt.SetItem(command.ItemNumber, item, command.ActorId);

IEnumerable<TaxAggregate> taxes = await _taxRepository.LoadAsync(cancellationToken);
receipt.Calculate(taxes, command.ActorId);
receipt.Calculate(command.ActorId);

await _receiptRepository.SaveAsync(receipt, cancellationToken);

Expand Down
2 changes: 1 addition & 1 deletion backend/src/Faktur.Domain/Receipts/ReceiptAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static IReadOnlyDictionary<string, ReceiptTaxUnit> InitializeTaxes(IEnum
return receiptTaxes;
}

public void Calculate(IEnumerable<TaxAggregate> _, ActorId actorId = default)
public void Calculate(ActorId actorId = default)
{
Dictionary<string, decimal> taxableAmounts = [];
foreach (KeyValuePair<string, ReceiptTaxUnit> tax in _taxes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Calculate_it_should_calculate_the_correct_taxes()
receipt.SetItem(3, new ReceiptItemUnit(new GtinUnit("4011"), sku: null, new DisplayNameUnit("BANANES"), new FlagsUnit("MRJ"),
quantity: 1.150d, unitPrice: 1.52m, price: 1.75m, departmentNumber: null, department: null));

receipt.Calculate([_gst, _hst, _qst]);
receipt.Calculate();
Assert.Equal(21.03m, receipt.SubTotal);

Assert.Equal(3, receipt.Taxes.Count);
Expand All @@ -73,7 +73,7 @@ public void Calculate_it_should_not_calculate_any_tax_when_no_item_is_taxable()
_receipt.SetItem(1, new ReceiptItemUnit(new GtinUnit("06038385904"), sku: null, new DisplayNameUnit("PC POULET BBQ"), flags: null,
quantity: 1.0d, unitPrice: 9.99m, price: 9.99m, departmentNumber: null, department: null));

_receipt.Calculate([_gst, _qst]);
_receipt.Calculate();
Assert.Equal(9.99m, _receipt.SubTotal);
Assert.Empty(_receipt.Taxes);
Assert.Equal(9.99m, _receipt.Total);
Expand All @@ -85,7 +85,7 @@ public void Calculate_it_should_not_calculate_any_tax_when_none_were_provided()
_receipt.SetItem(1, new ReceiptItemUnit(new GtinUnit("06038385904"), sku: null, new DisplayNameUnit("PC POULET BBQ"), new FlagsUnit("FPMRJ"),
quantity: 1.0d, unitPrice: 9.99m, price: 9.99m, departmentNumber: null, department: null));

_receipt.Calculate([]);
_receipt.Calculate();
Assert.Equal(9.99m, _receipt.SubTotal);
Assert.Empty(_receipt.Taxes);
Assert.Equal(9.99m, _receipt.Total);
Expand All @@ -94,7 +94,7 @@ public void Calculate_it_should_not_calculate_any_tax_when_none_were_provided()
[Fact(DisplayName = "Calculate: it should not calculate any tax when there is no item.")]
public void Calculate_it_should_not_calculate_any_tax_when_there_is_no_item()
{
_receipt.Calculate([_gst, _qst]);
_receipt.Calculate();
Assert.Equal(0m, _receipt.SubTotal);
Assert.Empty(_receipt.Taxes);
Assert.Equal(0m, _receipt.Total);
Expand Down

0 comments on commit e25be90

Please sign in to comment.