mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): filter by transaction or realization in report customer payment
This commit is contained in:
@@ -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", ""),
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
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
|
||||
}
|
||||
filteredRows = append(filteredRows, row)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -161,6 +161,15 @@ const (
|
||||
ExpenseCategoryNonBOP ExpenseCategory = "NON-BOP"
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Filter Customer Payment
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
CustomerPaymentFilterByTransDate = "TRANS_DATE"
|
||||
CustomerPaymentFilterByRealizationDate = "REALIZATION_DATE"
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Payment Method
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user