mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
add adjustment depresiasi calculation and percentage depresiasi
This commit is contained in:
@@ -112,7 +112,7 @@ type HppV2CostRepository interface {
|
||||
GetFarmDepreciationSnapshotByProjectFlockIDAndPeriod(ctx context.Context, projectFlockID uint, periodDate time.Time) (*HppV2FarmDepreciationSnapshotRow, error)
|
||||
GetEarliestChickInDateByProjectFlockID(ctx context.Context, projectFlockID uint) (*time.Time, error)
|
||||
GetChickinPopulationByPFKForFarm(ctx context.Context, projectFlockID uint) (map[uint]float64, error)
|
||||
GetMultiplicationPercentages(ctx context.Context, houseTypes []string, maxDay int) (map[string]map[int]float64, error)
|
||||
GetMultiplicationPercentages(ctx context.Context, houseTypes []string, maxDay int) (map[string]map[int]float64, map[string]*time.Time, error)
|
||||
ListUsageCostRowsByProductFlags(ctx context.Context, projectFlockKandangIDs []uint, flagNames []string, date *time.Time) ([]HppV2UsageCostRow, error)
|
||||
ListAdjustmentCostRowsByProductFlags(ctx context.Context, projectFlockKandangIDs []uint, flagNames []string, date *time.Time) ([]HppV2AdjustmentCostRow, error)
|
||||
ListExpenseRealizationRowsByProjectFlockKandangIDs(ctx context.Context, projectFlockKandangIDs []uint, date *time.Time, ekspedisi bool) ([]HppV2ExpenseCostRow, error)
|
||||
@@ -466,28 +466,30 @@ func (r *HppV2RepositoryImpl) GetMultiplicationPercentages(
|
||||
ctx context.Context,
|
||||
houseTypes []string,
|
||||
maxDay int,
|
||||
) (map[string]map[int]float64, error) {
|
||||
) (map[string]map[int]float64, map[string]*time.Time, error) {
|
||||
result := make(map[string]map[int]float64)
|
||||
effectiveDates := make(map[string]*time.Time)
|
||||
if len(houseTypes) == 0 || maxDay <= 0 {
|
||||
return result, nil
|
||||
return result, effectiveDates, nil
|
||||
}
|
||||
|
||||
type row struct {
|
||||
HouseType string
|
||||
Day int
|
||||
MultiplicationPercentage float64
|
||||
EffectiveDate *time.Time
|
||||
}
|
||||
|
||||
rows := make([]row, 0)
|
||||
err := r.db.WithContext(ctx).Raw(`
|
||||
SELECT DISTINCT ON (house_type::text, day)
|
||||
house_type::text AS house_type, day, multiplication_percentage
|
||||
house_type::text AS house_type, day, multiplication_percentage, effective_date
|
||||
FROM house_depreciation_standards
|
||||
WHERE house_type::text IN ? AND day <= ?
|
||||
ORDER BY house_type, day, effective_date DESC NULLS LAST
|
||||
`, houseTypes, maxDay).Scan(&rows).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for _, item := range rows {
|
||||
@@ -495,9 +497,12 @@ func (r *HppV2RepositoryImpl) GetMultiplicationPercentages(
|
||||
result[item.HouseType] = make(map[int]float64)
|
||||
}
|
||||
result[item.HouseType][item.Day] = item.MultiplicationPercentage
|
||||
if _, tracked := effectiveDates[item.HouseType]; !tracked {
|
||||
effectiveDates[item.HouseType] = item.EffectiveDate
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return result, effectiveDates, nil
|
||||
}
|
||||
|
||||
func (r *HppV2RepositoryImpl) ListUsageCostRowsByProductFlags(
|
||||
|
||||
Reference in New Issue
Block a user