mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
initial refactori trasnfer to laying, and depretitation to 25 week
This commit is contained in:
@@ -37,10 +37,10 @@ type FarmDepreciationManualInputRow struct {
|
||||
Note *string
|
||||
}
|
||||
|
||||
type houseDepreciationPercentRow struct {
|
||||
HouseType string
|
||||
Day int
|
||||
DepreciationPercent float64
|
||||
type houseMultiplicationPercentageRow struct {
|
||||
HouseType string
|
||||
Day int
|
||||
MultiplicationPercentage float64
|
||||
}
|
||||
|
||||
type ExpenseDepreciationRepository interface {
|
||||
@@ -48,8 +48,9 @@ type ExpenseDepreciationRepository interface {
|
||||
GetSnapshotsByPeriodAndFarmIDs(ctx context.Context, period time.Time, farmIDs []uint) ([]entity.FarmDepreciationSnapshot, error)
|
||||
UpsertSnapshots(ctx context.Context, rows []entity.FarmDepreciationSnapshot) error
|
||||
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)
|
||||
GetDepreciationPercents(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, error)
|
||||
GetLatestManualInputsByFarms(ctx context.Context, areaIDs, locationIDs, projectFlockIDs []int64) ([]FarmDepreciationManualInputRow, error)
|
||||
UpsertManualInput(ctx context.Context, row *entity.FarmDepreciationManualInput) error
|
||||
DB() *gorm.DB
|
||||
@@ -159,6 +160,17 @@ func (r *expenseDepreciationRepository) DeleteSnapshotsFromDate(
|
||||
return query.Delete(nil).Error
|
||||
}
|
||||
|
||||
func (r *expenseDepreciationRepository) DeleteSnapshotsByFarmIDs(ctx context.Context, farmIDs []uint) error {
|
||||
if len(farmIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.db.WithContext(ctx).
|
||||
Table("farm_depreciation_snapshots").
|
||||
Where("project_flock_id IN ?", farmIDs).
|
||||
Delete(nil).Error
|
||||
}
|
||||
|
||||
func (r *expenseDepreciationRepository) GetLatestTransferInputsByFarms(
|
||||
ctx context.Context,
|
||||
period time.Time,
|
||||
@@ -228,7 +240,7 @@ ORDER BY ltt.target_project_flock_kandang_id, at.effective_date DESC, at.id DESC
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (r *expenseDepreciationRepository) GetDepreciationPercents(
|
||||
func (r *expenseDepreciationRepository) GetMultiplicationPercentages(
|
||||
ctx context.Context,
|
||||
houseTypes []string,
|
||||
maxDay int,
|
||||
@@ -238,14 +250,14 @@ func (r *expenseDepreciationRepository) GetDepreciationPercents(
|
||||
return result, nil
|
||||
}
|
||||
|
||||
rows := make([]houseDepreciationPercentRow, 0)
|
||||
if err := r.db.WithContext(ctx).
|
||||
Table("house_depreciation_standards").
|
||||
Select("house_type::text AS house_type, day, depreciation_percent").
|
||||
Where("house_type::text IN ?", houseTypes).
|
||||
Where("day <= ?", maxDay).
|
||||
Order("house_type ASC, day ASC").
|
||||
Scan(&rows).Error; err != nil {
|
||||
rows := make([]houseMultiplicationPercentageRow, 0)
|
||||
if err := r.db.WithContext(ctx).Raw(`
|
||||
SELECT DISTINCT ON (house_type::text, day)
|
||||
house_type::text AS house_type, day, multiplication_percentage
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -253,7 +265,7 @@ func (r *expenseDepreciationRepository) GetDepreciationPercents(
|
||||
if _, exists := result[row.HouseType]; !exists {
|
||||
result[row.HouseType] = make(map[int]float64)
|
||||
}
|
||||
result[row.HouseType][row.Day] = row.DepreciationPercent
|
||||
result[row.HouseType][row.Day] = row.MultiplicationPercentage
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user