mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 22:35:43 +00:00
next commit
This commit is contained in:
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
type HppService interface {
|
||||
CalculateHppCost(projectFlockKandangId uint, date *time.Time) (*HppCostResponse, error)
|
||||
GetTotalDepresiasi(projectFlockKandangId uint, date *time.Time) (float64, error)
|
||||
GetTotalDepresiasiFlockGrowing(sourceProjectFlockID uint, date *time.Time) (float64, error)
|
||||
GetTotalProductionCost(projectFlockKandangId uint, date *time.Time, totalDepresiasiGrowing float64) (float64, error)
|
||||
}
|
||||
|
||||
type HppCostResponse struct {
|
||||
@@ -39,8 +40,36 @@ func (s *hppService) CalculateHppCost(projectFlockKandangId uint, date *time.Tim
|
||||
date = &now
|
||||
}
|
||||
|
||||
// _ = projectFlockKandangId
|
||||
_ = date
|
||||
var sourceProjectFlockID uint
|
||||
var transferTotalQty float64
|
||||
var err error
|
||||
sourceProjectFlockID, transferTotalQty, err = s.hppRepo.GetTransferSourceSummary(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kandangIDsGrowing, err := s.hppRepo.GetProjectFlockKandangIDs(context.Background(), sourceProjectFlockID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalPopulationFlockGrowing, err := s.hppRepo.GetTotalPopulation(context.Background(), kandangIDsGrowing)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalDepresiasiFlockGrowing, err := s.GetTotalDepresiasiFlockGrowing(sourceProjectFlockID, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
depresiasiTransfer := (totalDepresiasiFlockGrowing * transferTotalQty) / totalPopulationFlockGrowing
|
||||
|
||||
_, err = s.GetTotalProductionCost(projectFlockKandangId, date, depresiasiTransfer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &HppCostResponse{
|
||||
Estimation: HppCostDetail{},
|
||||
@@ -48,7 +77,7 @@ func (s *hppService) CalculateHppCost(projectFlockKandangId uint, date *time.Tim
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetTotalDepresiasi(projectFlockKandangId uint, date *time.Time) (float64, error) {
|
||||
func (s *hppService) GetTotalDepresiasiFlockGrowing(sourceProjectFlockID uint, date *time.Time) (float64, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
@@ -58,32 +87,52 @@ func (s *hppService) GetTotalDepresiasi(projectFlockKandangId uint, date *time.T
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
docCost, err := s.hppRepo.GetDocCost(context.Background(), projectFlockKandangId)
|
||||
kandangIDs, err := s.hppRepo.GetProjectFlockKandangIDs(context.Background(), sourceProjectFlockID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
budgetCost, err := s.hppRepo.GetBudgetCost(context.Background(), projectFlockKandangId)
|
||||
docCost, err := s.hppRepo.GetDocCost(context.Background(), kandangIDs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
expedisionCost, err := s.hppRepo.GetExpedisionCost(context.Background(), projectFlockKandangId)
|
||||
budgetCost, err := s.hppRepo.GetBudgetCostByProjectFlockId(context.Background(), sourceProjectFlockID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
feedCost, err := s.hppRepo.GetFeedCost(context.Background(), projectFlockKandangId, date)
|
||||
expedisionCost, err := s.hppRepo.GetExpedisionCost(context.Background(), kandangIDs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
ovkCost, err := s.hppRepo.GetOvkCost(context.Background(), projectFlockKandangId, date)
|
||||
feedCost, err := s.hppRepo.GetFeedCost(context.Background(), kandangIDs, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
ovkCost, err := s.hppRepo.GetOvkCost(context.Background(), kandangIDs, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return docCost + budgetCost + expedisionCost + feedCost + ovkCost, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetTotalProductionCost(projectFlockKandangId uint, date *time.Time, depresiasiTransfer float64) (float64, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
}
|
||||
|
||||
costPullet, err := s.hppRepo.GetPulletCost(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
}
|
||||
|
||||
_ = date
|
||||
|
||||
return docCost + budgetCost + expedisionCost + feedCost + ovkCost, nil
|
||||
return depresiasiTransfer + costPullet, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user