diff --git a/internal/modules/repports/controllers/repport.controller.go b/internal/modules/repports/controllers/repport.controller.go index 9becdf87..aff0a718 100644 --- a/internal/modules/repports/controllers/repport.controller.go +++ b/internal/modules/repports/controllers/repport.controller.go @@ -324,6 +324,7 @@ func (c *RepportController) GetCustomerPayment(ctx *fiber.Ctx) error { Page: ctx.QueryInt("page", 1), Limit: ctx.QueryInt("limit", 10), CustomerIDs: customerIDs, + FilterBy: strings.ToUpper(ctx.Query("filter_by", "")), StartDate: ctx.Query("start_date", ""), EndDate: ctx.Query("end_date", ""), } diff --git a/internal/modules/repports/services/repport.service.go b/internal/modules/repports/services/repport.service.go index 713fe6a4..38fdd74b 100644 --- a/internal/modules/repports/services/repport.service.go +++ b/internal/modules/repports/services/repport.service.go @@ -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) diff --git a/internal/modules/repports/validations/repport.validation.go b/internal/modules/repports/validations/repport.validation.go index 37c581d9..97ea60fa 100644 --- a/internal/modules/repports/validations/repport.validation.go +++ b/internal/modules/repports/validations/repport.validation.go @@ -85,6 +85,7 @@ type CustomerPaymentQuery struct { Page int `query:"page" validate:"omitempty,min=1,gt=0"` Limit int `query:"limit" validate:"omitempty,min=1,max=100,gt=0"` CustomerIDs []uint `query:"customer_ids" validate:"omitempty,dive,gt=0"` + FilterBy string `query:"filter_by" validate:"omitempty,oneof=TRANS_DATE REALIZATION_DATE"` StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"` EndDate string `query:"end_date" validate:"omitempty,datetime=2006-01-02"` } diff --git a/internal/utils/constant.go b/internal/utils/constant.go index d395ad3c..2b91f579 100644 --- a/internal/utils/constant.go +++ b/internal/utils/constant.go @@ -161,6 +161,15 @@ const ( ExpenseCategoryNonBOP ExpenseCategory = "NON-BOP" ) +// ------------------------------------------------------------------- +// Filter Customer Payment +// ------------------------------------------------------------------- + +const ( + CustomerPaymentFilterByTransDate = "TRANS_DATE" + CustomerPaymentFilterByRealizationDate = "REALIZATION_DATE" +) + // ------------------------------------------------------------------- // Payment Method // -------------------------------------------------------------------