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
@@ -324,6 +324,7 @@ func (c *RepportController) GetCustomerPayment(ctx *fiber.Ctx) error {
Page: ctx.QueryInt("page", 1), Page: ctx.QueryInt("page", 1),
Limit: ctx.QueryInt("limit", 10), Limit: ctx.QueryInt("limit", 10),
CustomerIDs: customerIDs, CustomerIDs: customerIDs,
FilterBy: strings.ToUpper(ctx.Query("filter_by", "")),
StartDate: ctx.Query("start_date", ""), StartDate: ctx.Query("start_date", ""),
EndDate: ctx.Query("end_date", ""), EndDate: ctx.Query("end_date", ""),
} }
@@ -582,6 +582,11 @@ func (s *repportService) processCustomerPayment(ctx context.Context, customerID
return dto.CustomerPaymentReportItem{}, err return dto.CustomerPaymentReportItem{}, err
} }
filterBy := strings.ToUpper(strings.TrimSpace(params.FilterBy))
if filterBy == "" {
filterBy = utils.CustomerPaymentFilterByTransDate
}
var startDate, endDate *time.Time var startDate, endDate *time.Time
if params.StartDate != "" { if params.StartDate != "" {
parsed, err := time.ParseInLocation("2006-01-02", params.StartDate, location) 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 { for _, row := range rows {
transDate := row.TransDate.In(location) var compareDate time.Time
if startDate != nil && transDate.Before(*startDate) { if filterBy == utils.CustomerPaymentFilterByRealizationDate {
if row.DeliveryDate == nil {
continue continue
} }
if endDate != nil && transDate.After(*endDate) { compareDate = row.DeliveryDate.In(location)
} else {
compareDate = row.TransDate.In(location)
}
if startDate != nil && compareDate.Before(*startDate) {
continue
}
if endDate != nil && compareDate.After(*endDate) {
continue continue
} }
filteredRows = append(filteredRows, row) filteredRows = append(filteredRows, row)
@@ -85,6 +85,7 @@ type CustomerPaymentQuery struct {
Page int `query:"page" validate:"omitempty,min=1,gt=0"` Page int `query:"page" validate:"omitempty,min=1,gt=0"`
Limit int `query:"limit" validate:"omitempty,min=1,max=100,gt=0"` Limit int `query:"limit" validate:"omitempty,min=1,max=100,gt=0"`
CustomerIDs []uint `query:"customer_ids" validate:"omitempty,dive,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"` StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"`
EndDate string `query:"end_date" validate:"omitempty,datetime=2006-01-02"` EndDate string `query:"end_date" validate:"omitempty,datetime=2006-01-02"`
} }
+9
View File
@@ -161,6 +161,15 @@ const (
ExpenseCategoryNonBOP ExpenseCategory = "NON-BOP" ExpenseCategoryNonBOP ExpenseCategory = "NON-BOP"
) )
// -------------------------------------------------------------------
// Filter Customer Payment
// -------------------------------------------------------------------
const (
CustomerPaymentFilterByTransDate = "TRANS_DATE"
CustomerPaymentFilterByRealizationDate = "REALIZATION_DATE"
)
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Payment Method // Payment Method
// ------------------------------------------------------------------- // -------------------------------------------------------------------