Feat(BE-339): make a report for purchasing supplier

This commit is contained in:
ragilap
2025-12-16 14:42:31 +07:00
parent 062a7937e2
commit cd739f41b9
8 changed files with 474 additions and 6 deletions
@@ -97,3 +97,53 @@ func (c *RepportController) GetMarketing(ctx *fiber.Ctx) error {
Data: result,
})
}
func (c *RepportController) GetPurchaseSupplier(ctx *fiber.Ctx) error {
query := &validation.PurchaseSupplierQuery{
Page: ctx.QueryInt("page", 1),
Limit: ctx.QueryInt("limit", 10),
AreaId: int64(ctx.QueryInt("area_id", 0)),
SupplierId: int64(ctx.QueryInt("supplier_id", 0)),
ProductId: int64(ctx.QueryInt("product_id", 0)),
ProductCategoryId: int64(ctx.QueryInt("product_category_id", 0)),
DateFrom: ctx.Query("date_from", ""),
DateTo: ctx.Query("date_to", ""),
SortBy: ctx.Query("sort_by", ""),
FilterBy: ctx.Query("filter_by", ""),
}
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.GetPurchaseSupplier(ctx, query)
if err != nil {
return err
}
filters := map[string]interface{}{
"area_id": query.AreaId,
"supplier_id": query.SupplierId,
"product_id": query.ProductId,
"product_category_id": query.ProductCategoryId,
"date_from": query.DateFrom,
"date_to": query.DateTo,
"sort_by": query.SortBy,
"filter_by": query.FilterBy,
}
return ctx.Status(fiber.StatusOK).
JSON(response.SuccessWithPaginate[dto.PurchaseSupplierDTO]{
Code: fiber.StatusOK,
Status: "success",
Message: "Get supplier purchase 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,
})
}