feat: add preview totals endpoint and DTOs for invoice calculations

This commit is contained in:
2026-10-22 16:24:09 +05:30
parent 2c39b34c5f
commit 5b2b39b7bf
3 changed files with 81 additions and 15 deletions
+16 -4
View File
@@ -1,4 +1,5 @@
using Distribution.Models;
using Distribution.Features.ShopPO;
using Distribution.Models;
namespace Distribution.Features.Invoice;
@@ -9,7 +10,14 @@ public record PrintInvoiceRequest(Guid? PrintedByUserId = null);
// InvoiceItemId set = edit/remove/restore an existing line; ItemId set (InvoiceItemId null) = add a new line.
public record InvoiceItemEdit(Guid? InvoiceItemId, Guid? ItemId, int Quantity, decimal? UnitPrice = null, bool IsRemoved = false);
public record UpdateInvoiceItemsRequest(List<InvoiceItemEdit> Items, Guid? EditedByUserId = null);
// DiscountSchemeIds: the percentage-discount scheme chosen in the editor (at most one); null = leave as is.
public record UpdateInvoiceItemsRequest(List<InvoiceItemEdit> Items, Guid? EditedByUserId = null, List<Guid>? DiscountSchemeIds = null);
public record PreviewLine(Guid ItemId, int Quantity, decimal UnitPrice, bool IsFree = false, bool IsRemoved = false, Guid? SchemeId = null);
public record PreviewInvoiceTotalsRequest(List<PreviewLine> Items, List<Guid>? DiscountSchemeIds = null);
// Quantity = how many free units the scheme still entitles for the lines as typed.
public record FreeEntitlement(Guid SchemeId, int Quantity);
public record InvoiceTotalsPreview(decimal DiscountAmount, decimal TotalAmount, List<FreeEntitlement> FreeEntitlements);
public record InvoiceVersionItemResponse(Guid? ShopPOItemId, Guid ItemId, string ItemName, int Quantity, decimal UnitPrice, bool IsRemoved);
@@ -30,7 +38,10 @@ public record InvoiceItemResponse(
int? OrderedQuantity,
int Quantity,
decimal UnitPrice,
bool IsRemoved);
bool IsRemoved,
bool IsFree = false,
Guid? SchemeId = null,
string? SchemeName = null);
public record InvoiceResponse(
Guid Id,
@@ -49,6 +60,7 @@ public record InvoiceResponse(
decimal PaidAmount,
bool IsActive,
DateTime CreatedAt,
List<InvoiceItemResponse> Items);
List<InvoiceItemResponse> Items,
List<ShopPODiscountResponse>? Discounts = null);
public record OutstandingPaymentsResponse(int InvoiceCount, decimal OutstandingAmount);