adjust value hpp

This commit is contained in:
giovanni
2026-01-23 10:29:48 +07:00
parent 1edd071a8a
commit d54911f8b4
@@ -2,6 +2,7 @@ package service
import (
"context"
"math"
"time"
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
@@ -238,10 +239,10 @@ func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, p
Butir: estimPieces,
}
if estimWeightKg > 0 {
estimation.HargaKg = totalProductionCost / estimWeightKg
estimation.HargaKg = roundToTwoDecimals(totalProductionCost / estimWeightKg)
}
if estimPieces > 0 {
estimation.HargaButir = totalProductionCost / estimPieces
estimation.HargaButir = roundToTwoDecimals(totalProductionCost / estimPieces)
}
real := HppCostDetail{
@@ -250,10 +251,10 @@ func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, p
Butir: realPieces,
}
if realWeightKg > 0 {
real.HargaKg = totalProductionCost / realWeightKg
real.HargaKg = roundToTwoDecimals(totalProductionCost / realWeightKg)
}
if realPieces > 0 {
real.HargaButir = totalProductionCost / realPieces
real.HargaButir = roundToTwoDecimals(totalProductionCost / realPieces)
}
return &HppCostResponse{
@@ -261,3 +262,7 @@ func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, p
Real: real,
}, nil
}
func roundToTwoDecimals(value float64) float64 {
return math.Round(value*100) / 100
}