mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
continue common service hpp
This commit is contained in:
@@ -11,6 +11,8 @@ type HppService interface {
|
||||
CalculateHppCost(projectFlockKandangId uint, date *time.Time) (*HppCostResponse, error)
|
||||
GetTotalDepresiasiFlockGrowing(sourceProjectFlockID uint, date *time.Time) (float64, error)
|
||||
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)
|
||||
}
|
||||
|
||||
type HppCostResponse struct {
|
||||
@@ -40,36 +42,17 @@ func (s *hppService) CalculateHppCost(projectFlockKandangId uint, date *time.Tim
|
||||
date = &now
|
||||
}
|
||||
|
||||
var sourceProjectFlockID uint
|
||||
var transferTotalQty float64
|
||||
var err error
|
||||
sourceProjectFlockID, transferTotalQty, err = s.hppRepo.GetTransferSourceSummary(context.Background(), projectFlockKandangId)
|
||||
depresiasiTransfer, err := s.GetDepresiasiTransfer(projectFlockKandangId, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kandangIDsGrowing, err := s.hppRepo.GetProjectFlockKandangIDs(context.Background(), sourceProjectFlockID)
|
||||
|
||||
totalProductionCost, err := s.GetTotalProductionCost(projectFlockKandangId, date, depresiasiTransfer)
|
||||
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
|
||||
}
|
||||
_ = totalProductionCost
|
||||
|
||||
return &HppCostResponse{
|
||||
Estimation: HppCostDetail{},
|
||||
@@ -107,12 +90,12 @@ func (s *hppService) GetTotalDepresiasiFlockGrowing(sourceProjectFlockID uint, d
|
||||
return 0, err
|
||||
}
|
||||
|
||||
feedCost, err := s.hppRepo.GetFeedCost(context.Background(), kandangIDs, date)
|
||||
feedCost, err := s.hppRepo.GetFeedUsageCost(context.Background(), kandangIDs, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
ovkCost, err := s.hppRepo.GetOvkCost(context.Background(), kandangIDs, date)
|
||||
ovkCost, err := s.hppRepo.GetOvkUsageCost(context.Background(), kandangIDs, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -129,10 +112,105 @@ func (s *hppService) GetTotalProductionCost(projectFlockKandangId uint, date *ti
|
||||
costPullet, err := s.hppRepo.GetPulletCost(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
}
|
||||
|
||||
_ = date
|
||||
costFeed, err := s.hppRepo.GetFeedUsageCost(context.Background(), []uint{projectFlockKandangId}, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return depresiasiTransfer + costPullet, nil
|
||||
costOvk, err := s.hppRepo.GetOvkUsageCost(context.Background(), []uint{projectFlockKandangId}, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
costExpedision, err := s.hppRepo.GetExpedisionCost(context.Background(), []uint{projectFlockKandangId})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
costBudget, err := s.GetBudgetKandangLaying(projectFlockKandangId, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return depresiasiTransfer + costPullet + costFeed + costOvk + costExpedision + costBudget, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetBudgetKandangLaying(projectFlockKandangId uint, date *time.Time) (float64, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
}
|
||||
|
||||
if s.hppRepo == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
projectFlockId, err := s.hppRepo.GetProjectFlockIDByProjectFlockKandangID(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
projectFlockKandangIds, err := s.hppRepo.GetProjectFlockKandangIDs(context.Background(), projectFlockId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
eggProduksiPiecesFlock, _, err := s.hppRepo.GetEggProduksiPiecesAndWeightKgByProjectFlockKandangIds(context.Background(), projectFlockKandangIds, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
eggProduksiPiecesKandang, _, err := s.hppRepo.GetEggProduksiPiecesAndWeightKgByProjectFlockKandangIds(context.Background(), []uint{projectFlockKandangId}, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
totalBudgetCost, err := s.hppRepo.GetBudgetCostByProjectFlockId(context.Background(), projectFlockId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if eggProduksiPiecesFlock == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return (totalBudgetCost * eggProduksiPiecesKandang) / eggProduksiPiecesFlock, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetDepresiasiTransfer(projectFlockKandangId uint, date *time.Time) (float64, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
}
|
||||
|
||||
if s.hppRepo == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
sourceProjectFlockID, transferTotalQty, err := s.hppRepo.GetTransferSourceSummary(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
kandangIDsGrowing, err := s.hppRepo.GetProjectFlockKandangIDs(context.Background(), sourceProjectFlockID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
totalPopulationFlockGrowing, err := s.hppRepo.GetTotalPopulation(context.Background(), kandangIDsGrowing)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if totalPopulationFlockGrowing == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
totalDepresiasiFlockGrowing, err := s.GetTotalDepresiasiFlockGrowing(sourceProjectFlockID, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return (totalDepresiasiFlockGrowing * transferTotalQty) / totalPopulationFlockGrowing, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user