fix(BE): filter by transaction or realization in report customer payment

This commit is contained in:
Hafizh A. Y
2026-02-05 14:16:02 +07:00
parent f407ef6a0c
commit fc157dfd79
4 changed files with 28 additions and 3 deletions
@@ -582,6 +582,11 @@ func (s *repportService) processCustomerPayment(ctx context.Context, customerID
return dto.CustomerPaymentReportItem{}, err
}
filterBy := strings.ToUpper(strings.TrimSpace(params.FilterBy))
if filterBy == "" {
filterBy = utils.CustomerPaymentFilterByTransDate
}
var startDate, endDate *time.Time
if params.StartDate != "" {
parsed, err := time.ParseInLocation("2006-01-02", params.StartDate, location)
@@ -600,11 +605,20 @@ func (s *repportService) processCustomerPayment(ctx context.Context, customerID
}
for _, row := range rows {
transDate := row.TransDate.In(location)
if startDate != nil && transDate.Before(*startDate) {
var compareDate time.Time
if filterBy == utils.CustomerPaymentFilterByRealizationDate {
if row.DeliveryDate == nil {
continue
}
compareDate = row.DeliveryDate.In(location)
} else {
compareDate = row.TransDate.In(location)
}
if startDate != nil && compareDate.Before(*startDate) {
continue
}
if endDate != nil && transDate.After(*endDate) {
if endDate != nil && compareDate.After(*endDate) {
continue
}
filteredRows = append(filteredRows, row)