add adjustment depresiasi calculation and percentage depresiasi

This commit is contained in:
giovanni
2026-05-29 21:48:20 +07:00
parent b4fbef702a
commit a46edc4498
14 changed files with 128 additions and 178 deletions
@@ -1390,7 +1390,7 @@ func (s *hppV2Service) buildNormalTransferDepreciationPart(
}
houseType := NormalizeDepreciationHouseType(contextRow.HouseType)
multiplicationByHouseType, err := s.hppRepo.GetMultiplicationPercentages(context.Background(), []string{houseType}, scheduleDay)
multiplicationByHouseType, effectiveDates, err := s.hppRepo.GetMultiplicationPercentages(context.Background(), []string{houseType}, scheduleDay)
if err != nil {
return nil, err
}
@@ -1407,6 +1407,11 @@ func (s *hppV2Service) buildNormalTransferDepreciationPart(
totalValueAfter := pulletCostDayN * multiplicationPercentage
depreciationPercent := (1.0 - multiplicationPercentage) * 100.0
var standardEffectiveDate string
if ed, ok := effectiveDates[houseType]; ok && ed != nil {
standardEffectiveDate = formatDateOnly(*ed)
}
return &HppV2ComponentPart{
Code: hppV2PartDepreciationNormal,
Title: "Normal Transfer",
@@ -1422,6 +1427,8 @@ func (s *hppV2Service) buildNormalTransferDepreciationPart(
"origin_date": formatDateOnly(*originDate),
"transfer_date": formatDateOnly(transferInput.TransferDate),
"source_project_flock_id": transferInput.SourceProjectFlockID,
"standard_effective_date": standardEffectiveDate,
"kandang_population": transferInput.TransferQty,
},
References: []HppV2Reference{
{
@@ -1492,7 +1499,7 @@ func (s *hppV2Service) buildManualCutoverDepreciationPart(
}
houseType := NormalizeDepreciationHouseType(contextRow.HouseType)
multiplicationByHouseType, err := s.hppRepo.GetMultiplicationPercentages(context.Background(), []string{houseType}, reportScheduleDay)
multiplicationByHouseType, effectiveDates, err := s.hppRepo.GetMultiplicationPercentages(context.Background(), []string{houseType}, reportScheduleDay)
if err != nil {
return nil, err
}
@@ -1511,6 +1518,11 @@ func (s *hppV2Service) buildManualCutoverDepreciationPart(
depreciationPercent := (1.0 - multiplicationPercentage) * 100.0
_ = totalPulletCost
var standardEffectiveDate string
if ed, ok := effectiveDates[houseType]; ok && ed != nil {
standardEffectiveDate = formatDateOnly(*ed)
}
return &HppV2ComponentPart{
Code: hppV2PartDepreciationCutover,
Title: "Manual Cut-over",
@@ -1530,6 +1542,8 @@ func (s *hppV2Service) buildManualCutoverDepreciationPart(
"cutover_date": formatDateOnly(manualInput.CutoverDate),
"manual_input_id": manualInput.ID,
"project_flock_kandang": projectFlockKandangId,
"standard_effective_date": standardEffectiveDate,
"kandang_population": kandangPopulation,
},
References: []HppV2Reference{
{
@@ -103,8 +103,9 @@ func (s *hppV2RepoStub) GetDepreciationPercents(_ context.Context, houseTypes []
// GetMultiplicationPercentages — alias yang sama dengan GetDepreciationPercents untuk match
// interface HppV2CostRepository (interface dipakai method name baru ini).
func (s *hppV2RepoStub) GetMultiplicationPercentages(ctx context.Context, houseTypes []string, maxDay int) (map[string]map[int]float64, error) {
return s.GetDepreciationPercents(ctx, houseTypes, maxDay)
func (s *hppV2RepoStub) GetMultiplicationPercentages(ctx context.Context, houseTypes []string, maxDay int) (map[string]map[int]float64, map[string]*time.Time, error) {
vals, err := s.GetDepreciationPercents(ctx, houseTypes, maxDay)
return vals, make(map[string]*time.Time), err
}
// GetChickinPopulationByPFKForFarm — return populasi per PFK dari satu project flock.