mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
adjust calculate total price marketing ayam pullet
This commit is contained in:
@@ -770,15 +770,21 @@ func (s salesOrdersService) Approval(c *fiber.Ctx, req *validation.Approve) ([]e
|
||||
|
||||
func (s *salesOrdersService) createMarketingProductWithDelivery(ctx context.Context, marketingId uint, marketingType string, rp validation.CreateMarketingProduct, marketingProductRepo repository.MarketingProductRepository, invDeliveryRepo repository.MarketingDeliveryProductRepository) error {
|
||||
|
||||
totalWeight, totalPrice := s.calculatePriceByMarketingType(
|
||||
marketingType,
|
||||
rp.Qty,
|
||||
rp.AvgWeight,
|
||||
rp.UnitPrice,
|
||||
rp.Week,
|
||||
rp.ConvertionUnit,
|
||||
rp.WeightPerConvertion,
|
||||
)
|
||||
var totalWeight, totalPrice float64
|
||||
if rp.TotalPrice != nil {
|
||||
totalWeight = math.Round(rp.Qty*rp.AvgWeight*100) / 100
|
||||
totalPrice = *rp.TotalPrice
|
||||
} else {
|
||||
totalWeight, totalPrice = s.calculatePriceByMarketingType(
|
||||
marketingType,
|
||||
rp.Qty,
|
||||
rp.AvgWeight,
|
||||
rp.UnitPrice,
|
||||
rp.Week,
|
||||
rp.ConvertionUnit,
|
||||
rp.WeightPerConvertion,
|
||||
)
|
||||
}
|
||||
|
||||
marketingProduct := &entity.MarketingProduct{
|
||||
MarketingId: marketingId,
|
||||
@@ -821,7 +827,7 @@ func (s *salesOrdersService) calculatePriceByMarketingType(marketingType string,
|
||||
totalPrice = math.Round(qty*unitPrice*100) / 100
|
||||
} else if marketingType == string(utils.MarketingTypeAyamPullet) && week != nil && *week > 0 {
|
||||
totalWeight = math.Round(qty*avgWeight*100) / 100
|
||||
totalPrice = math.Round(unitPrice*float64(*week)*qty*100) / 100
|
||||
totalPrice = math.Round(totalWeight*unitPrice*100) / 100
|
||||
} else {
|
||||
totalWeight = math.Round(qty*avgWeight*100) / 100
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ type CreateMarketingProduct struct {
|
||||
UnitPrice float64 `json:"unit_price" validate:"required,gt=0"`
|
||||
Qty float64 `json:"qty" validate:"required,gt=0"`
|
||||
AvgWeight float64 `json:"avg_weight" validate:"omitempty,gt=0"`
|
||||
TotalPrice *float64 `json:"total_price" validate:"omitempty,gt=0"`
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
|
||||
Reference in New Issue
Block a user