diff --git a/backend/src/Faktur.Application/Receipts/Commands/CreateOrReplaceReceiptItemCommandHandler.cs b/backend/src/Faktur.Application/Receipts/Commands/CreateOrReplaceReceiptItemCommandHandler.cs index d5b9d0d..6ebe38b 100644 --- a/backend/src/Faktur.Application/Receipts/Commands/CreateOrReplaceReceiptItemCommandHandler.cs +++ b/backend/src/Faktur.Application/Receipts/Commands/CreateOrReplaceReceiptItemCommandHandler.cs @@ -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; @@ -15,13 +14,11 @@ internal class CreateOrReplaceReceiptItemCommandHandler : IRequestHandler Handle(CreateOrReplaceReceiptItemCommand command, CancellationToken cancellationToken) @@ -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 taxes = await _taxRepository.LoadAsync(cancellationToken); - receipt.Calculate(taxes, command.ActorId); + receipt.Calculate(command.ActorId); await _receiptRepository.SaveAsync(receipt, cancellationToken); diff --git a/backend/src/Faktur.Application/Receipts/Commands/ImportReceiptCommandHandler.cs b/backend/src/Faktur.Application/Receipts/Commands/ImportReceiptCommandHandler.cs index 5dccd3b..fc394a6 100644 --- a/backend/src/Faktur.Application/Receipts/Commands/ImportReceiptCommandHandler.cs +++ b/backend/src/Faktur.Application/Receipts/Commands/ImportReceiptCommandHandler.cs @@ -130,8 +130,8 @@ public async Task Handle(ImportReceiptCommand command, CancellationToke NumberUnit? number = NumberUnit.TryCreate(payload.Number); IEnumerable 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); diff --git a/backend/src/Faktur.Application/Receipts/Commands/RemoveReceiptItemCommandHandler.cs b/backend/src/Faktur.Application/Receipts/Commands/RemoveReceiptItemCommandHandler.cs index 3c0dcec..42cbb0a 100644 --- a/backend/src/Faktur.Application/Receipts/Commands/RemoveReceiptItemCommandHandler.cs +++ b/backend/src/Faktur.Application/Receipts/Commands/RemoveReceiptItemCommandHandler.cs @@ -1,6 +1,5 @@ using Faktur.Contracts.Receipts; using Faktur.Domain.Receipts; -using Faktur.Domain.Taxes; using MediatR; namespace Faktur.Application.Receipts.Commands; @@ -9,13 +8,11 @@ internal class RemoveReceiptItemCommandHandler : IRequestHandler Handle(RemoveReceiptItemCommand command, CancellationToken cancellationToken) @@ -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 taxes = await _taxRepository.LoadAsync(cancellationToken); - receipt.Calculate(taxes, command.ActorId); + receipt.Calculate(command.ActorId); await _receiptRepository.SaveAsync(receipt, cancellationToken); diff --git a/backend/src/Faktur.Application/Receipts/Commands/UpdateReceiptItemCommandHandler.cs b/backend/src/Faktur.Application/Receipts/Commands/UpdateReceiptItemCommandHandler.cs index bd80786..1efd954 100644 --- a/backend/src/Faktur.Application/Receipts/Commands/UpdateReceiptItemCommandHandler.cs +++ b/backend/src/Faktur.Application/Receipts/Commands/UpdateReceiptItemCommandHandler.cs @@ -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; @@ -15,13 +14,11 @@ internal class UpdateReceiptItemCommandHandler : IRequestHandler Handle(UpdateReceiptItemCommand command, CancellationToken cancellationToken) @@ -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 taxes = await _taxRepository.LoadAsync(cancellationToken); - receipt.Calculate(taxes, command.ActorId); + receipt.Calculate(command.ActorId); await _receiptRepository.SaveAsync(receipt, cancellationToken); diff --git a/backend/src/Faktur.Domain/Receipts/ReceiptAggregate.cs b/backend/src/Faktur.Domain/Receipts/ReceiptAggregate.cs index 3b2fc48..4bbb7a7 100644 --- a/backend/src/Faktur.Domain/Receipts/ReceiptAggregate.cs +++ b/backend/src/Faktur.Domain/Receipts/ReceiptAggregate.cs @@ -146,7 +146,7 @@ private static IReadOnlyDictionary InitializeTaxes(IEnum return receiptTaxes; } - public void Calculate(IEnumerable _, ActorId actorId = default) + public void Calculate(ActorId actorId = default) { Dictionary taxableAmounts = []; foreach (KeyValuePair tax in _taxes) diff --git a/backend/tests/Faktur.Domain.UnitTests/Receipts/ReceiptAggregateTests.cs b/backend/tests/Faktur.Domain.UnitTests/Receipts/ReceiptAggregateTests.cs index 4746306..e3bdcb2 100644 --- a/backend/tests/Faktur.Domain.UnitTests/Receipts/ReceiptAggregateTests.cs +++ b/backend/tests/Faktur.Domain.UnitTests/Receipts/ReceiptAggregateTests.cs @@ -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); @@ -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); @@ -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); @@ -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);