fix monitorin saldo without sales order;format date excel po

This commit is contained in:
giovanni
2026-05-22 19:40:05 +07:00
parent 7bbb6a836c
commit c676aed371
2 changed files with 25 additions and 7 deletions
@@ -255,16 +255,17 @@ func (r *balanceMonitoringRepositoryImpl) GetSalesTotalsBeforeDate(ctx context.C
Joins("INNER JOIN marketings m ON m.id = mp.marketing_id").
Where("m.customer_id IN ?", customerIDs).
Where("m.deleted_at IS NULL").
Where("EXISTS (SELECT 1 FROM marketing_delivery_products mdp WHERE mdp.marketing_product_id = mp.id AND mdp.deleted_at IS NULL AND mdp.delivery_date IS NOT NULL AND DATE(mdp.delivery_date) < ?)", startDate)
Where("EXISTS (SELECT 1 FROM marketing_delivery_products mdp WHERE mdp.marketing_product_id = mp.id AND mdp.delivery_date IS NOT NULL AND DATE(mdp.delivery_date) < ?)", startDate)
} else {
// sold_at: count all SO products ordered before startDate
// sold_at: SO-date sebelum startDate DAN sudah di-approve sebagai Delivery Order (step >= 3)
db = r.db.WithContext(ctx).
Table("marketing_products mp").
Select("m.customer_id AS customer_id, COALESCE(SUM(mp.total_price), 0) AS total").
Joins("INNER JOIN marketings m ON m.id = mp.marketing_id").
Where("m.customer_id IN ?", customerIDs).
Where("m.deleted_at IS NULL").
Where("DATE(m.so_date) < ?", startDate)
Where("DATE(m.so_date) < ?", startDate).
Where("EXISTS (SELECT 1 FROM approvals a WHERE a.approvable_type = 'MARKETINGS' AND a.approvable_id = mp.marketing_id AND a.step_number >= 3)")
}
if len(filters.SalesIDs) > 0 {
@@ -350,9 +351,9 @@ func (r *balanceMonitoringRepositoryImpl) GetSalesByCategoryInPeriod(ctx context
Joins("INNER JOIN marketings m ON m.id = mp.marketing_id").
Where("m.customer_id IN ?", customerIDs).
Where("m.deleted_at IS NULL").
Where("EXISTS (SELECT 1 FROM marketing_delivery_products mdp WHERE mdp.marketing_product_id = mp.id AND mdp.deleted_at IS NULL AND mdp.delivery_date IS NOT NULL AND DATE(mdp.delivery_date) >= ? AND DATE(mdp.delivery_date) <= ?)", startDate, endDate)
Where("EXISTS (SELECT 1 FROM marketing_delivery_products mdp WHERE mdp.marketing_product_id = mp.id AND mdp.delivery_date IS NOT NULL AND DATE(mdp.delivery_date) >= ? AND DATE(mdp.delivery_date) <= ?)", startDate, endDate)
} else {
// sold_at: count all SO products placed in the period regardless of delivery status
// sold_at: SO-date dalam period DAN sudah di-approve sebagai Delivery Order (step >= 3)
db = r.db.WithContext(ctx).
Table("marketing_products mp").
Select(selectCols).
@@ -360,7 +361,8 @@ func (r *balanceMonitoringRepositoryImpl) GetSalesByCategoryInPeriod(ctx context
Where("m.customer_id IN ?", customerIDs).
Where("m.deleted_at IS NULL").
Where("DATE(m.so_date) >= ?", startDate).
Where("DATE(m.so_date) <= ?", endDate)
Where("DATE(m.so_date) <= ?", endDate).
Where("EXISTS (SELECT 1 FROM approvals a WHERE a.approvable_type = 'MARKETINGS' AND a.approvable_id = mp.marketing_id AND a.step_number >= 3)")
}
if len(filters.SalesIDs) > 0 {