tax calculations
All checks were successful
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m15s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m37s

This commit is contained in:
matst80
2025-10-14 09:13:38 +02:00
parent 6c44a03dd1
commit 7a79efbb9f

View File

@@ -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
}
}