mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02b86be4c5 | |||
| 99e185a16a | |||
| 995d585f54 |
@@ -1030,6 +1030,7 @@ func (s *dailyChecklistService) UpdateByPut(c *fiber.Ctx, req *validation.Create
|
||||
}
|
||||
}
|
||||
|
||||
var wasBranchC bool // non-empty_kandang → empty_kandang transition
|
||||
err = s.Repository.DB().WithContext(c.Context()).Transaction(func(tx *gorm.DB) error {
|
||||
if err := s.lockKandangForChecklistCreation(tx, req.KandangId); err != nil {
|
||||
return err
|
||||
@@ -1088,6 +1089,23 @@ func (s *dailyChecklistService) UpdateByPut(c *fiber.Ctx, req *validation.Create
|
||||
if err := s.upsertEmptyKandangRange(tx, id, req.KandangId, date, emptyEndDate, actorID); err != nil {
|
||||
return err
|
||||
}
|
||||
// Branch C: non-empty → empty_kandang, hard-delete task/progress data
|
||||
if !existingIsEmpty {
|
||||
wasBranchC = true
|
||||
if err := tx.Exec(`
|
||||
DELETE FROM daily_checklist_activity_task_assignments
|
||||
WHERE task_id IN (
|
||||
SELECT id FROM daily_checklist_activity_tasks WHERE checklist_id = ?
|
||||
)`, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Where("checklist_id = ?", id).Delete(&entity.DailyChecklistActivityTask{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Where("daily_checklist_id = ?", id).Delete(&entity.DailyChecklistTask{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if existingIsEmpty {
|
||||
updates := map[string]any{
|
||||
"deleted_at": time.Now(),
|
||||
@@ -1108,6 +1126,20 @@ func (s *dailyChecklistService) UpdateByPut(c *fiber.Ctx, req *validation.Create
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Branch C: delete DC documents outside transaction (storage is external)
|
||||
if wasBranchC && s.DocumentSvc != nil {
|
||||
docs, docErr := s.DocumentSvc.ListByTarget(c.Context(), string(utils.DocumentTypeDailyChecklist), uint64(id))
|
||||
if docErr == nil && len(docs) > 0 {
|
||||
docIDs := make([]uint, 0, len(docs))
|
||||
for _, doc := range docs {
|
||||
docIDs = append(docIDs, doc.Id)
|
||||
}
|
||||
if delErr := s.DocumentSvc.DeleteDocuments(c.Context(), docIDs, true); delErr != nil {
|
||||
s.Log.Errorf("Failed to delete documents for DC %d during empty_kandang conversion: %+v", id, delErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s.GetOne(c, id)
|
||||
}
|
||||
|
||||
|
||||
@@ -177,10 +177,48 @@ func (r *ExpenseRealizationRepositoryImpl) GetAllWithFilters(ctx context.Context
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
sortExpr := "expense_realizations.created_at"
|
||||
order := "DESC"
|
||||
if filters.SortOrder == "asc" {
|
||||
order = "ASC"
|
||||
}
|
||||
switch filters.SortBy {
|
||||
case "po_number":
|
||||
sortExpr = "expenses.po_number"
|
||||
case "reference_number":
|
||||
sortExpr = "expenses.reference_number"
|
||||
case "realization_date":
|
||||
sortExpr = "expenses.realization_date"
|
||||
case "transaction_date":
|
||||
sortExpr = "expenses.transaction_date"
|
||||
case "category":
|
||||
sortExpr = "expenses.category"
|
||||
case "product":
|
||||
sortExpr = "(SELECT name FROM nonstocks WHERE id = expense_nonstocks.nonstock_id)"
|
||||
case "supplier":
|
||||
sortExpr = "suppliers.name"
|
||||
case "location":
|
||||
sortExpr = "(SELECT l.name FROM kandangs k JOIN locations l ON l.id = k.location_id WHERE k.id = expense_nonstocks.kandang_id)"
|
||||
case "kandang":
|
||||
sortExpr = "(SELECT name FROM kandangs WHERE id = expense_nonstocks.kandang_id)"
|
||||
case "qty_pengajuan":
|
||||
sortExpr = "expense_nonstocks.qty"
|
||||
case "price_pengajuan":
|
||||
sortExpr = "expense_nonstocks.price"
|
||||
case "total_pengajuan":
|
||||
sortExpr = "expense_nonstocks.qty * expense_nonstocks.price"
|
||||
case "qty_realisasi":
|
||||
sortExpr = "expense_realizations.qty"
|
||||
case "price_realisasi":
|
||||
sortExpr = "expense_realizations.price"
|
||||
case "total_realisasi":
|
||||
sortExpr = "expense_realizations.qty * expense_realizations.price"
|
||||
}
|
||||
|
||||
if err := db.
|
||||
Offset(offset).
|
||||
Limit(limit).
|
||||
Order("expense_realizations.created_at DESC").
|
||||
Order(sortExpr + " " + order).
|
||||
Find(&realizations).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ func (c *RepportController) GetExpense(ctx *fiber.Ctx) error {
|
||||
AreaId: int64(ctx.QueryInt("area_id", 0)),
|
||||
LocationId: int64(ctx.QueryInt("location_id", 0)),
|
||||
RealizationDate: ctx.Query("realization_date", ""),
|
||||
SortBy: ctx.Query("sort_by", ""),
|
||||
SortOrder: ctx.Query("sort_order", ""),
|
||||
}
|
||||
|
||||
locationScope, err := m.ResolveLocationScope(ctx, c.RepportService.DB())
|
||||
|
||||
@@ -13,6 +13,8 @@ type ExpenseQuery struct {
|
||||
AreaId int64 `query:"area_id" validate:"omitempty"`
|
||||
LocationId int64 `query:"location_id" validate:"omitempty"`
|
||||
RealizationDate string `query:"realization_date" validate:"omitempty"`
|
||||
SortBy string `query:"sort_by" validate:"omitempty,oneof=po_number reference_number realization_date transaction_date category product supplier location kandang qty_pengajuan price_pengajuan total_pengajuan qty_realisasi price_realisasi total_realisasi"`
|
||||
SortOrder string `query:"sort_order" validate:"omitempty,oneof=asc desc"`
|
||||
AllowedAreaIDs []int64 `query:"-"`
|
||||
AllowedLocationIDs []int64 `query:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user