mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
add common service and repo for calculate hpp
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
)
|
||||
|
||||
type HppService interface {
|
||||
CalculateHppCost(projectFlockKandangId uint, date *time.Time) (*HppCostResponse, error)
|
||||
GetTotalDepresiasi(projectFlockKandangId uint, date *time.Time) (float64, error)
|
||||
}
|
||||
|
||||
type HppCostResponse struct {
|
||||
Estimation HppCostDetail `json:"estimation"`
|
||||
Real HppCostDetail `json:"real"`
|
||||
}
|
||||
|
||||
type HppCostDetail struct {
|
||||
HargaKg float64 `json:"harga_kg"`
|
||||
HargaButir float64 `json:"harga_butir"`
|
||||
Total float64 `json:"total"`
|
||||
Kg float64 `json:"kg"`
|
||||
Butir float64 `json:"butir"`
|
||||
}
|
||||
|
||||
type hppService struct {
|
||||
hppRepo commonRepo.HppCostRepository
|
||||
}
|
||||
|
||||
func NewHppService(hppRepo commonRepo.HppCostRepository) HppService {
|
||||
return &hppService{hppRepo: hppRepo}
|
||||
}
|
||||
|
||||
func (s *hppService) CalculateHppCost(projectFlockKandangId uint, date *time.Time) (*HppCostResponse, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
}
|
||||
|
||||
// _ = projectFlockKandangId
|
||||
_ = date
|
||||
|
||||
return &HppCostResponse{
|
||||
Estimation: HppCostDetail{},
|
||||
Real: HppCostDetail{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *hppService) GetTotalDepresiasi(projectFlockKandangId uint, date *time.Time) (float64, error) {
|
||||
if date == nil {
|
||||
now := time.Now()
|
||||
date = &now
|
||||
}
|
||||
|
||||
if s.hppRepo == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
docCost, err := s.hppRepo.GetDocCost(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
budgetCost, err := s.hppRepo.GetBudgetCost(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
expedisionCost, err := s.hppRepo.GetExpedisionCost(context.Background(), projectFlockKandangId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
feedCost, err := s.hppRepo.GetFeedCost(context.Background(), projectFlockKandangId, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
ovkCost, err := s.hppRepo.GetOvkCost(context.Background(), projectFlockKandangId, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
_ = date
|
||||
|
||||
return docCost + budgetCost + expedisionCost + feedCost + ovkCost, nil
|
||||
}
|
||||
Reference in New Issue
Block a user