mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat: manual pullet cost
This commit is contained in:
@@ -30,6 +30,7 @@ type ExpenseDepreciationManualInputRowDTO struct {
|
||||
ProjectFlockID int64 `json:"project_flock_id"`
|
||||
FarmName string `json:"farm_name"`
|
||||
TotalCost float64 `json:"total_cost"`
|
||||
CutoverDate string `json:"cutover_date"`
|
||||
Note *string `json:"note"`
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ type FarmDepreciationManualInputRow struct {
|
||||
ProjectFlockID uint
|
||||
FarmName string
|
||||
TotalCost float64
|
||||
CutoverDate time.Time
|
||||
Note *string
|
||||
}
|
||||
|
||||
@@ -271,6 +272,7 @@ func (r *expenseDepreciationRepository) GetLatestManualInputsByFarms(
|
||||
fdmi.project_flock_id AS project_flock_id,
|
||||
pf.flock_name AS farm_name,
|
||||
fdmi.total_cost AS total_cost,
|
||||
fdmi.cutover_date AS cutover_date,
|
||||
fdmi.note AS note
|
||||
`).
|
||||
Joins("JOIN project_flocks AS pf ON pf.id = fdmi.project_flock_id").
|
||||
@@ -308,9 +310,10 @@ func (r *expenseDepreciationRepository) UpsertManualInput(ctx context.Context, r
|
||||
{Name: "project_flock_id"},
|
||||
},
|
||||
DoUpdates: clause.Assignments(map[string]any{
|
||||
"total_cost": row.TotalCost,
|
||||
"note": row.Note,
|
||||
"updated_at": now,
|
||||
"total_cost": row.TotalCost,
|
||||
"cutover_date": row.CutoverDate,
|
||||
"note": row.Note,
|
||||
"updated_at": now,
|
||||
}),
|
||||
}).
|
||||
Create(row).Error
|
||||
@@ -320,7 +323,7 @@ func (r *expenseDepreciationRepository) UpsertManualInput(ctx context.Context, r
|
||||
|
||||
return r.db.WithContext(ctx).
|
||||
Table("farm_depreciation_manual_inputs").
|
||||
Select("id, project_flock_id, total_cost, note").
|
||||
Select("id, project_flock_id, total_cost, cutover_date, note").
|
||||
Where("project_flock_id = ?", row.ProjectFlockId).
|
||||
Take(row).Error
|
||||
}
|
||||
|
||||
@@ -347,6 +347,7 @@ func (s *repportService) GetExpenseDepreciationManualInputs(ctx *fiber.Ctx) ([]d
|
||||
ProjectFlockID: int64(row.ProjectFlockID),
|
||||
FarmName: row.FarmName,
|
||||
TotalCost: row.TotalCost,
|
||||
CutoverDate: row.CutoverDate.Format("2006-01-02"),
|
||||
Note: row.Note,
|
||||
})
|
||||
}
|
||||
@@ -397,10 +398,19 @@ func (s *repportService) UpsertExpenseDepreciationManualInput(ctx *fiber.Ctx, re
|
||||
if s.ExpenseDepreciationRepo == nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "expense depreciation repository is not configured")
|
||||
}
|
||||
location, err := time.LoadLocation("Asia/Jakarta")
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "failed to load timezone configuration")
|
||||
}
|
||||
cutoverDate, err := time.ParseInLocation("2006-01-02", req.CutoverDate, location)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "cutover_date must follow format YYYY-MM-DD")
|
||||
}
|
||||
|
||||
row := entity.FarmDepreciationManualInput{
|
||||
ProjectFlockId: req.ProjectFlockID,
|
||||
TotalCost: req.TotalCost,
|
||||
CutoverDate: cutoverDate,
|
||||
Note: req.Note,
|
||||
}
|
||||
if err := s.ExpenseDepreciationRepo.UpsertManualInput(ctx.Context(), &row); err != nil {
|
||||
@@ -411,6 +421,7 @@ func (s *repportService) UpsertExpenseDepreciationManualInput(ctx *fiber.Ctx, re
|
||||
ID: int64(row.Id),
|
||||
ProjectFlockID: int64(row.ProjectFlockId),
|
||||
TotalCost: row.TotalCost,
|
||||
CutoverDate: row.CutoverDate.Format("2006-01-02"),
|
||||
Note: row.Note,
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ type ExpenseDepreciationQuery struct {
|
||||
type ExpenseDepreciationManualInputUpsert struct {
|
||||
ProjectFlockID uint `json:"project_flock_id" validate:"required,gt=0"`
|
||||
TotalCost float64 `json:"total_cost" validate:"required,gte=0"`
|
||||
CutoverDate string `json:"cutover_date" validate:"required,datetime=2006-01-02"`
|
||||
Note *string `json:"note" validate:"omitempty,max=1000"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user