From aa1fd1c35b6485f6a1bf944d9384236e6cab3e73 Mon Sep 17 00:00:00 2001 From: aguhh18 Date: Thu, 5 Feb 2026 09:57:38 +0700 Subject: [PATCH] FEAT[BE] :update price calculation in sales order service for accurate rounding, add new conversion unit for quantity --- .../modules/marketing/services/salesorder.service.go | 11 ++++++----- internal/utils/constant.go | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/modules/marketing/services/salesorder.service.go b/internal/modules/marketing/services/salesorder.service.go index 58901794..eb2e4f5b 100644 --- a/internal/modules/marketing/services/salesorder.service.go +++ b/internal/modules/marketing/services/salesorder.service.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math" "strings" commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository" @@ -752,13 +753,13 @@ func (s *salesOrdersService) createMarketingProductWithDelivery(ctx context.Cont func (s *salesOrdersService) calculatePriceByMarketingType(marketingType string, qty, avgWeight, unitPrice float64, week *int) (totalWeight, totalPrice float64) { if marketingType == string(utils.MarketingTypeTrading) { totalWeight = 0 - totalPrice = qty * unitPrice + totalPrice = math.Round(qty*unitPrice*100) / 100 } else if marketingType == string(utils.MarketingTypeAyamPullet) && week != nil && *week > 0 { - totalWeight = qty * avgWeight - totalPrice = unitPrice * float64(*week) * qty + totalWeight = math.Round(qty*avgWeight*100) / 100 + totalPrice = math.Round(unitPrice*float64(*week)*qty*100) / 100 } else { - totalWeight = qty * avgWeight - totalPrice = totalWeight * unitPrice + totalWeight = math.Round(qty*avgWeight*100) / 100 + totalPrice = math.Round(totalWeight*unitPrice*100) / 100 } return totalWeight, totalPrice } diff --git a/internal/utils/constant.go b/internal/utils/constant.go index 1de04fa3..27d1ec3e 100644 --- a/internal/utils/constant.go +++ b/internal/utils/constant.go @@ -234,6 +234,7 @@ type ConvertionUnit string const ( ConvertionUnitPeti ConvertionUnit = "PETI" ConvertionUnitKG ConvertionUnit = "KG" + ConvertionUnitQty ConvertionUnit = "QTY" ) // ------------------------------------------------------------------- @@ -643,7 +644,7 @@ func IsValidMarketingType(v string) bool { func IsValidConvertionUnit(v string) bool { switch ConvertionUnit(v) { - case ConvertionUnitPeti, ConvertionUnitKG: + case ConvertionUnitPeti, ConvertionUnitKG, ConvertionUnitQty: return true } return false