mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +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"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
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) {
|
func (s *salesOrdersService) calculatePriceByMarketingType(marketingType string, qty, avgWeight, unitPrice float64, week *int) (totalWeight, totalPrice float64) {
|
||||||
if marketingType == string(utils.MarketingTypeTrading) {
|
if marketingType == string(utils.MarketingTypeTrading) {
|
||||||
totalWeight = 0
|
totalWeight = 0
|
||||||
totalPrice = qty * unitPrice
|
totalPrice = math.Round(qty*unitPrice*100) / 100
|
||||||
} else if marketingType == string(utils.MarketingTypeAyamPullet) && week != nil && *week > 0 {
|
} else if marketingType == string(utils.MarketingTypeAyamPullet) && week != nil && *week > 0 {
|
||||||
totalWeight = qty * avgWeight
|
totalWeight = math.Round(qty*avgWeight*100) / 100
|
||||||
totalPrice = unitPrice * float64(*week) * qty
|
totalPrice = math.Round(unitPrice*float64(*week)*qty*100) / 100
|
||||||
} else {
|
} else {
|
||||||
totalWeight = qty * avgWeight
|
totalWeight = math.Round(qty*avgWeight*100) / 100
|
||||||
totalPrice = totalWeight * unitPrice
|
totalPrice = math.Round(totalWeight*unitPrice*100) / 100
|
||||||
}
|
}
|
||||||
return totalWeight, totalPrice
|
return totalWeight, totalPrice
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ type ConvertionUnit string
|
|||||||
const (
|
const (
|
||||||
ConvertionUnitPeti ConvertionUnit = "PETI"
|
ConvertionUnitPeti ConvertionUnit = "PETI"
|
||||||
ConvertionUnitKG ConvertionUnit = "KG"
|
ConvertionUnitKG ConvertionUnit = "KG"
|
||||||
|
ConvertionUnitQty ConvertionUnit = "QTY"
|
||||||
)
|
)
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
@@ -643,7 +644,7 @@ func IsValidMarketingType(v string) bool {
|
|||||||
|
|
||||||
func IsValidConvertionUnit(v string) bool {
|
func IsValidConvertionUnit(v string) bool {
|
||||||
switch ConvertionUnit(v) {
|
switch ConvertionUnit(v) {
|
||||||
case ConvertionUnitPeti, ConvertionUnitKG:
|
case ConvertionUnitPeti, ConvertionUnitKG, ConvertionUnitQty:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user