add query sort by grand total

This commit is contained in:
giovanni
2026-05-07 14:11:39 +07:00
parent 0357531e73
commit 094e8f904b
2 changed files with 3 additions and 1 deletions
@@ -308,6 +308,8 @@ func (s deliveryOrdersService) GetAll(c *fiber.Ctx, params *validation.DeliveryO
return db.Order(statusSQL)
case "customer":
return db.Joins("LEFT JOIN customers ON customers.id = marketings.customer_id").Order("COALESCE(customers.name, '') " + orderDir)
case "grand_total":
return db.Order("(SELECT COALESCE(SUM(mp.total_price), 0) FROM marketing_products mp WHERE mp.marketing_id = marketings.id) " + orderDir)
default:
return db.Order("created_at DESC").Order("updated_at DESC")
}
@@ -31,7 +31,7 @@ type DeliveryOrderQuery struct {
MarketingId uint `query:"marketing_id" validate:"omitempty,gt=0"`
ProjectFlockID uint `query:"project_flock_id" validate:"omitempty,gt=0"`
ProjectFlockKandangID uint `query:"project_flock_kandang_id" validate:"omitempty,gt=0"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=so_number so_date status customer"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=so_number so_date status customer grand_total"`
SortOrder string `query:"sort_order" validate:"omitempty,oneof=asc desc"`
}