init add function command for create seed depretitaion standard

This commit is contained in:
giovanni
2026-06-01 21:07:30 +07:00
parent 09b1f19d19
commit 44b82a8e38
8 changed files with 747 additions and 9 deletions
@@ -51,7 +51,7 @@ type ExpenseDepreciationRepository interface {
DeleteSnapshotsFromDate(ctx context.Context, fromDate time.Time, farmIDs []uint) error
DeleteSnapshotsByFarmIDs(ctx context.Context, farmIDs []uint) error
GetLatestTransferInputsByFarms(ctx context.Context, period time.Time, farmIDs []uint) ([]FarmDepreciationLatestTransferRow, error)
GetMultiplicationPercentages(ctx context.Context, houseTypes []string, maxDay int) (map[string]map[int]float64, map[string]*time.Time, error)
GetMultiplicationPercentages(ctx context.Context, houseTypes []string, maxDay int, projectFlockID uint) (map[string]map[int]float64, map[string]*time.Time, error)
GetLatestManualInputsByFarms(ctx context.Context, areaIDs, locationIDs, projectFlockIDs []int64) ([]FarmDepreciationManualInputRow, error)
UpsertManualInput(ctx context.Context, row *entity.FarmDepreciationManualInput) error
DB() *gorm.DB
@@ -245,6 +245,7 @@ func (r *expenseDepreciationRepository) GetMultiplicationPercentages(
ctx context.Context,
houseTypes []string,
maxDay int,
projectFlockID uint,
) (map[string]map[int]float64, map[string]*time.Time, error) {
result := make(map[string]map[int]float64)
effectiveDates := make(map[string]*time.Time)
@@ -258,8 +259,9 @@ func (r *expenseDepreciationRepository) GetMultiplicationPercentages(
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; err != nil {
AND (project_flock_id = ? OR project_flock_id IS NULL)
ORDER BY house_type, day, (project_flock_id IS NOT NULL) DESC, effective_date DESC NULLS LAST
`, houseTypes, maxDay, projectFlockID).Scan(&rows).Error; err != nil {
return nil, nil, err
}