diff --git a/internal/modules/purchases/controllers/purchase.export.go b/internal/modules/purchases/controllers/purchase.export.go index 7a9a0696..44b2c8eb 100644 --- a/internal/modules/purchases/controllers/purchase.export.go +++ b/internal/modules/purchases/controllers/purchase.export.go @@ -435,6 +435,21 @@ func formatPurchaseExportEntityStatus(purchase *entity.Purchase) string { return safePurchaseExportText(purchase.LatestApproval.StepName) } +var purchaseIndonesianMonths = map[time.Month]string{ + time.January: "Jan", + time.February: "Feb", + time.March: "Mar", + time.April: "Apr", + time.May: "Mei", + time.June: "Jun", + time.July: "Jul", + time.August: "Ags", + time.September: "Sep", + time.October: "Okt", + time.November: "Nov", + time.December: "Des", +} + func formatPurchaseExportDate(value *time.Time) string { if value == nil || value.IsZero() { return "-" @@ -446,7 +461,8 @@ func formatPurchaseExportDate(value *time.Time) string { t = t.In(location) } - return t.Format("02-01-2006") + month := purchaseIndonesianMonths[t.Month()] + return fmt.Sprintf("%d-%s-%02d", t.Day(), month, t.Year()%100) } func safePurchaseExportPointerText(value *string) string { diff --git a/internal/modules/repports/repositories/balance_monitoring.repository.go b/internal/modules/repports/repositories/balance_monitoring.repository.go index 7dc69e02..4efb67aa 100644 --- a/internal/modules/repports/repositories/balance_monitoring.repository.go +++ b/internal/modules/repports/repositories/balance_monitoring.repository.go @@ -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 {