feat(BE):Rekapitulasi hutang supplier

This commit is contained in:
ragilap
2026-01-11 19:41:21 +07:00
parent d3c7d65bf5
commit 09f1b29359
12 changed files with 588 additions and 47 deletions
@@ -3,6 +3,7 @@ package controller
import (
"math"
"strconv"
"strings"
"gitlab.com/mbugroup/lti-api.git/internal/modules/repports/dto"
service "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/services"
@@ -164,6 +165,59 @@ func (c *RepportController) GetPurchaseSupplier(ctx *fiber.Ctx) error {
})
}
func (c *RepportController) GetDebtSupplier(ctx *fiber.Ctx) error {
supplierIDs, err := parseCommaSeparatedInt64s(ctx.Query("supplier_ids", ""))
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
query := &validation.DebtSupplierQuery{
Page: ctx.QueryInt("page", 1),
Limit: ctx.QueryInt("limit", 10),
SupplierIDs: supplierIDs,
StartDate: ctx.Query("start_date", ""),
EndDate: ctx.Query("end_date", ""),
FilterBy: ctx.Query("filter_by", ""),
SortOrder: ctx.Query("sort_order", ""),
}
if query.Page < 1 || query.Limit < 1 {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
}
result, totalResults, err := c.RepportService.GetDebtSupplier(ctx, query)
if err != nil {
return err
}
supplierIDs = query.SupplierIDs
if supplierIDs == nil {
supplierIDs = []int64{}
}
filters := map[string]interface{}{
"start_date": query.StartDate,
"end_date": query.EndDate,
"supplier_ids": supplierIDs,
"filter_by": query.FilterBy,
}
return ctx.Status(fiber.StatusOK).
JSON(response.SuccessWithPaginate[dto.DebtSupplierDTO]{
Code: fiber.StatusOK,
Status: "success",
Message: "Get supplier debt recap successfully",
Meta: response.Meta{
Page: query.Page,
Limit: query.Limit,
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
TotalResults: totalResults,
Filters: filters,
},
Data: result,
})
}
func (c *RepportController) GetHppPerKandang(ctx *fiber.Ctx) error {
data, meta, err := c.RepportService.GetHppPerKandang(ctx)
if err != nil {
@@ -227,3 +281,27 @@ func (c *RepportController) GetProductionResult(ctx *fiber.Ctx) error {
Data: data,
})
}
func parseCommaSeparatedInt64s(raw string) ([]int64, error) {
raw = strings.TrimSpace(raw)
if raw == "" {
return []int64{}, nil
}
parts := strings.Split(raw, ",")
result := make([]int64, 0, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
if part == "" {
continue
}
id, err := strconv.ParseInt(part, 10, 64)
if err != nil {
return nil, fiber.NewError(fiber.StatusBadRequest, "supplier_ids must be comma separated integers")
}
result = append(result, id)
}
return result, nil
}