From 7a79efbb9f2fa2a7c54f7a6143772d285caa1e44 Mon Sep 17 00:00:00 2001 From: matst80 Date: Tue, 14 Oct 2025 09:13:38 +0200 Subject: [PATCH] tax calculations --- cmd/cart/cart-grain.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/cart/cart-grain.go b/cmd/cart/cart-grain.go index 41fd0ab..48727e0 100644 --- a/cmd/cart/cart-grain.go +++ b/cmd/cart/cart-grain.go @@ -70,6 +70,7 @@ type CartGrain struct { TotalPrice int64 `json:"totalPrice"` TotalTax int64 `json:"totalTax"` TotalDiscount int64 `json:"totalDiscount"` + TotalDiscountTax int64 `json:"totalDiscountTax"` Deliveries []*CartDelivery `json:"deliveries,omitempty"` Processing bool `json:"processing"` PaymentInProgress bool `json:"paymentInProgress"` @@ -248,6 +249,7 @@ func (c *CartGrain) UpdateTotals() { c.TotalPrice = 0 c.TotalTax = 0 c.TotalDiscount = 0 + c.TotalDiscountTax = 0 for _, item := range c.Items { rowTotal := item.Price * int64(item.Quantity) rowTax := int64(item.Tax) * int64(item.Quantity) @@ -257,10 +259,15 @@ func (c *CartGrain) UpdateTotals() { c.TotalTax += rowTax itemDiff := max(0, item.OrgPrice-item.Price) c.TotalDiscount += itemDiff * int64(item.Quantity) + c.TotalDiscountTax += GetTaxAmount(c.TotalDiscount, 2500) } for _, delivery := range c.Deliveries { c.TotalPrice += delivery.Price c.TotalTax += GetTaxAmount(delivery.Price, 2500) } - + for _, voucher := range c.Vouchers { + c.TotalPrice -= voucher.Value + c.TotalTax -= voucher.TaxValue + c.TotalDiscountTax += voucher.TaxValue + } }