mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
feat[BE]: implement customer payment report retrieval with pagination and filtering
This commit is contained in:
@@ -242,6 +242,60 @@ func (c *RepportController) GetHppPerKandang(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusOK).JSON(resp)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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", ""),
|
||||
}
|
||||
|
||||
// Validate pagination
|
||||
if customerID == nil && (query.Page < 1 || query.Limit < 1) {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
result, totalResults, err := c.RepportService.GetCustomerPayment(ctx, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If single customer mode, return without pagination
|
||||
if customerID != nil {
|
||||
return ctx.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get customer payment report successfully",
|
||||
Data: result,
|
||||
})
|
||||
}
|
||||
|
||||
// Multiple customers mode with pagination
|
||||
return ctx.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.CustomerPaymentReportItem]{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get customer payment report successfully",
|
||||
Meta: response.Meta{
|
||||
Page: query.Page,
|
||||
Limit: query.Limit,
|
||||
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
||||
TotalResults: totalResults,
|
||||
},
|
||||
Data: result,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *RepportController) GetProductionResult(ctx *fiber.Ctx) error {
|
||||
idParam := ctx.Params("idProjectFlockKandang")
|
||||
if idParam == "" {
|
||||
@@ -283,36 +337,6 @@ func (c *RepportController) GetProductionResult(ctx *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *RepportController) GetCustomerPayment(ctx *fiber.Ctx) error {
|
||||
page := ctx.QueryInt("page", 1)
|
||||
limit := ctx.QueryInt("limit", 10)
|
||||
|
||||
if page < 1 || limit < 1 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data := []dto.CustomerPaymentReportItem{}
|
||||
totalResults := int64(0)
|
||||
|
||||
return ctx.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.CustomerPaymentReportItem]{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get customer payment report successfully",
|
||||
Meta: response.Meta{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
TotalPages: int64(math.Ceil(float64(totalResults) / float64(limit))),
|
||||
TotalResults: totalResults,
|
||||
},
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
func parseCommaSeparatedInt64s(raw string) ([]int64, error) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
|
||||
Reference in New Issue
Block a user