feat[BE]: enhance customer payment report with vehicle numbers and pickup info, add date filtering

This commit is contained in:
aguhh18
2026-01-14 15:15:29 +07:00
parent 7daa509cd0
commit 804ff45dbd
4 changed files with 141 additions and 78 deletions
@@ -54,7 +54,8 @@ func (r *customerPaymentRepositoryImpl) GetCustomerPaymentTransactions(ctx conte
m.so_date::DATE AS trans_date,
MAX(mdp.delivery_date)::DATE AS delivery_date,
m.so_number AS reference,
COALESCE(STRING_AGG(DISTINCT mdp.vehicle_number, ', ') FILTER (WHERE mdp.vehicle_number IS NOT NULL AND mdp.vehicle_number != ''), '') AS vehicle_numbers,
COALESCE(STRING_AGG(DISTINCT mdp.vehicle_number, ', ') FILTER (WHERE mdp.vehicle_number IS NOT NULL), '') AS vehicle_numbers,
COALESCE(SUM(COALESCE(mp.qty, 0)), 0)::NUMERIC(15,3) AS qty,
COALESCE(SUM(COALESCE(mdp.total_weight, mp.total_weight, 0)), 0)::NUMERIC(15,3) AS weight,
CASE WHEN COALESCE(SUM(COALESCE(mp.qty, 0)), 0) > 0
@@ -77,7 +78,8 @@ func (r *customerPaymentRepositoryImpl) GetCustomerPaymentTransactions(ctx conte
Joins("LEFT JOIN warehouses w ON w.id = pw.warehouse_id").
Joins("LEFT JOIN users u ON u.id = m.sales_person_id").
Where("m.deleted_at IS NULL").
Where("c.deleted_at IS NULL")
Where("c.deleted_at IS NULL").
Where("mdp.delivery_date IS NOT NULL")
if customerID != nil {
salesQuery = salesQuery.Where("c.id = ?", *customerID)