Files
lti-api/internal/common/service/common.hpp.service.go
T
2026-01-20 18:21:49 +07:00

90 lines
2.0 KiB
Go

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
}