mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
117 lines
3.7 KiB
Go
117 lines
3.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"math"
|
|
|
|
"gitlab.com/mbugroup/lti-api.git/internal/modules/repports/dto"
|
|
service "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/services"
|
|
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/validations"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/response"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// === Marketing Report Response ===
|
|
|
|
type MarketingReportResponse struct {
|
|
Code int `json:"code"`
|
|
Status string `json:"status"`
|
|
Message string `json:"message"`
|
|
Meta response.Meta `json:"meta"`
|
|
Data []dto.RepportMarketingItemDTO `json:"data"`
|
|
Total *dto.Summary `json:"total,omitempty"`
|
|
}
|
|
|
|
type RepportController struct {
|
|
RepportService service.RepportService
|
|
}
|
|
|
|
func NewRepportController(repportService service.RepportService) *RepportController {
|
|
return &RepportController{
|
|
RepportService: repportService,
|
|
}
|
|
}
|
|
|
|
func (c *RepportController) GetExpense(ctx *fiber.Ctx) error {
|
|
query := &validation.ExpenseQuery{
|
|
Page: ctx.QueryInt("page", 1),
|
|
Limit: ctx.QueryInt("limit", 10),
|
|
Search: ctx.Query("search", ""),
|
|
Category: ctx.Query("category", ""),
|
|
SupplierId: int64(ctx.QueryInt("supplier_id", 0)),
|
|
KandangId: int64(ctx.QueryInt("kandang_id", 0)),
|
|
ProjectFlockKandangId: int64(ctx.QueryInt("project_flock_kandang_id", 0)),
|
|
NonstockId: int64(ctx.QueryInt("nonstock_id", 0)),
|
|
AreaId: int64(ctx.QueryInt("area_id", 0)),
|
|
LocationId: int64(ctx.QueryInt("location_id", 0)),
|
|
RealizationDate: ctx.Query("realization_date", ""),
|
|
}
|
|
|
|
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.GetExpense(ctx, query)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return ctx.Status(fiber.StatusOK).
|
|
JSON(response.SuccessWithPaginate[dto.RepportExpenseListDTO]{
|
|
Code: fiber.StatusOK,
|
|
Status: "success",
|
|
Message: "Get expense 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) GetMarketing(ctx *fiber.Ctx) error {
|
|
query := &validation.MarketingQuery{
|
|
Page: ctx.QueryInt("page", 1),
|
|
Limit: ctx.QueryInt("limit", 10),
|
|
Search: ctx.Query("search", ""),
|
|
CustomerId: int64(ctx.QueryInt("customer_id", 0)),
|
|
ProductId: int64(ctx.QueryInt("product_id", 0)),
|
|
WarehouseId: int64(ctx.QueryInt("warehouse_id", 0)),
|
|
SalesPersonId: int64(ctx.QueryInt("sales_person_id", 0)),
|
|
FilterBy: ctx.Query("filter_by", ""),
|
|
StartDate: ctx.Query("start_date", ""),
|
|
EndDate: ctx.Query("end_date", ""),
|
|
SortBy: ctx.Query("sort_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.GetMarketing(ctx, query)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
|
|
total := dto.ToSummaryFromDTOItems(result)
|
|
|
|
return ctx.Status(fiber.StatusOK).
|
|
JSON(MarketingReportResponse{
|
|
Code: fiber.StatusOK,
|
|
Status: "success",
|
|
Message: "Get marketing report successfully",
|
|
Meta: response.Meta{
|
|
Page: query.Page,
|
|
Limit: query.Limit,
|
|
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
|
TotalResults: totalResults,
|
|
},
|
|
Data: result,
|
|
Total: total,
|
|
})
|
|
}
|