FEAT[BE] :update price calculation in sales order service for accurate rounding, add new conversion unit for quantity

This commit is contained in:
aguhh18
2026-02-05 09:57:38 +07:00
parent 1d95976360
commit aa1fd1c35b
2 changed files with 8 additions and 6 deletions
@@ -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
}
+2 -1
View File
@@ -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