mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
finishing common service calculate hpp
This commit is contained in:
@@ -13,6 +13,7 @@ type HppService interface {
|
||||
GetTotalProductionCost(projectFlockKandangId uint, date *time.Time, totalDepresiasiGrowing float64) (float64, error)
|
||||
GetBudgetKandangLaying(projectFlockKandangId uint, date *time.Time) (float64, error)
|
||||
GetDepresiasiTransfer(projectFlockKandangId uint, date *time.Time) (float64, error)
|
||||
GetHppEstimationDanRealisasi(totalProductionCost float64, projectFlockKandangId uint, date *time.Time) (*HppCostResponse, error)
|
||||
}
|
||||
|
||||
type HppCostResponse struct {
|
||||
@@ -52,12 +53,8 @@ func (s *hppService) CalculateHppCost(projectFlockKandangId uint, date *time.Tim
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = totalProductionCost
|
||||
return s.GetHppEstimationDanRealisasi(totalProductionCost, projectFlockKandangId, date)
|
||||
|
||||
return &HppCostResponse{
|
||||
Estimation: HppCostDetail{},
|
||||
Real: HppCostDetail{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetTotalDepresiasiFlockGrowing(sourceProjectFlockID uint, date *time.Time) (float64, error) {
|
||||
@@ -214,3 +211,53 @@ func (s *hppService) GetDepresiasiTransfer(projectFlockKandangId uint, date *tim
|
||||
|
||||
return (totalDepresiasiFlockGrowing * transferTotalQty) / totalPopulationFlockGrowing, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, projectFlockKandangId uint, date *time.Time) (*HppCostResponse, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
}
|
||||
|
||||
if s.hppRepo == nil {
|
||||
return &HppCostResponse{}, nil
|
||||
}
|
||||
|
||||
estimPieces, estimWeightKg, err := s.hppRepo.GetEggProduksiPiecesAndWeightKgByProjectFlockKandangIds(context.Background(), []uint{projectFlockKandangId}, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
realPieces, realWeightKg, err := s.hppRepo.GetEggTerjualPiecesAndWeightKgByProjectFlockKandangIds(context.Background(), []uint{projectFlockKandangId}, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
estimation := HppCostDetail{
|
||||
Total: totalProductionCost,
|
||||
Kg: estimWeightKg,
|
||||
Butir: estimPieces,
|
||||
}
|
||||
if estimWeightKg > 0 {
|
||||
estimation.HargaKg = totalProductionCost / estimWeightKg
|
||||
}
|
||||
if estimPieces > 0 {
|
||||
estimation.HargaButir = totalProductionCost / estimPieces
|
||||
}
|
||||
|
||||
real := HppCostDetail{
|
||||
Total: totalProductionCost,
|
||||
Kg: realWeightKg,
|
||||
Butir: realPieces,
|
||||
}
|
||||
if realWeightKg > 0 {
|
||||
real.HargaKg = totalProductionCost / realWeightKg
|
||||
}
|
||||
if realPieces > 0 {
|
||||
real.HargaButir = totalProductionCost / realPieces
|
||||
}
|
||||
|
||||
return &HppCostResponse{
|
||||
Estimation: estimation,
|
||||
Real: real,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user