mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
FEAT[BE] :update price calculation in sales order service for accurate rounding, add new conversion unit for quantity
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user