feat[BE]: update customer payment report to support multiple customer IDs and nullable aging days

This commit is contained in:
aguhh18
2026-01-14 14:06:34 +07:00
parent f6e872c0aa
commit 7daa509cd0
5 changed files with 109 additions and 38 deletions
@@ -243,25 +243,30 @@ func (c *RepportController) GetHppPerKandang(ctx *fiber.Ctx) error {
}
func (c *RepportController) GetCustomerPayment(ctx *fiber.Ctx) error {
var customerID *uint
if customerIDStr := ctx.Query("customer_id"); customerIDStr != "" {
if id, err := strconv.ParseUint(customerIDStr, 10, 32); err == nil {
cid := uint(id)
customerID = &cid
var customerIDs []uint
if customerIDsStr := ctx.Query("customer_ids"); customerIDsStr != "" {
ids := strings.Split(customerIDsStr, ",")
for _, idStr := range ids {
idStr = strings.TrimSpace(idStr)
if idStr != "" {
if id, err := strconv.ParseUint(idStr, 10, 32); err == nil {
customerIDs = append(customerIDs, uint(id))
}
}
}
}
query := &validation.CustomerPaymentQuery{
Page: ctx.QueryInt("page", 1),
Limit: ctx.QueryInt("limit", 10),
CustomerID: customerID,
StartDate: ctx.Query("start_date", ""),
EndDate: ctx.Query("end_date", ""),
Page: ctx.QueryInt("page", 1),
Limit: ctx.QueryInt("limit", 10),
CustomerIDs: customerIDs,
StartDate: ctx.Query("start_date", ""),
EndDate: ctx.Query("end_date", ""),
}
// Validate pagination
if customerID == nil && (query.Page < 1 || query.Limit < 1) {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
if len(customerIDs) == 0 && (query.Page < 1 || query.Limit < 1) {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0 when customer_ids is not provided")
}
result, totalResults, err := c.RepportService.GetCustomerPayment(ctx, query)
@@ -269,8 +274,8 @@ func (c *RepportController) GetCustomerPayment(ctx *fiber.Ctx) error {
return err
}
// If single customer mode, return without pagination
if customerID != nil {
// If single customer mode (only 1 customer ID), return without pagination
if len(customerIDs) == 1 {
return ctx.Status(fiber.StatusOK).
JSON(response.Success{
Code: fiber.StatusOK,