add export po and marketing

This commit is contained in:
giovanni
2026-04-22 19:22:29 +07:00
parent 7d223c81ba
commit ff630a1ed0
8 changed files with 1426 additions and 34 deletions
@@ -10,6 +10,7 @@ import (
"time"
"gitlab.com/mbugroup/lti-api.git/internal/common/exportprogress"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/dto"
service "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/services"
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/validations"
@@ -24,6 +25,8 @@ type PurchaseController struct {
service service.PurchaseService
}
const purchaseExcelExportFetchLimit = 100
func NewPurchaseController(s service.PurchaseService) *PurchaseController {
return &PurchaseController{service: s}
}
@@ -48,20 +51,14 @@ func (ctrl *PurchaseController) GetAll(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).Send(content)
}
query := &validation.Query{
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: strings.TrimSpace(c.Query("search")),
ApprovalStatus: strings.TrimSpace(c.Query("approval_status")),
PoDate: strings.TrimSpace(c.Query("po_date")),
PoDateFrom: strings.TrimSpace(c.Query("po_date_from")),
PoDateTo: strings.TrimSpace(c.Query("po_date_to")),
CreatedFrom: strings.TrimSpace(c.Query("created_from")),
CreatedTo: strings.TrimSpace(c.Query("created_to")),
SupplierID: uint(c.QueryInt("supplier_id", 0)),
AreaID: uint(c.QueryInt("area_id", 0)),
LocationID: uint(c.QueryInt("location_id", 0)),
ProductCategoryID: strings.TrimSpace(c.Query("product_category_id")),
query := buildPurchaseQuery(c)
if isAllPurchaseExcelExportRequest(c) {
results, err := ctrl.getAllPurchasesForExcel(c, query)
if err != nil {
return err
}
return exportPurchaseListExcel(c, results)
}
if query.Page < 1 || query.Limit < 1 {
@@ -88,6 +85,51 @@ func (ctrl *PurchaseController) GetAll(c *fiber.Ctx) error {
})
}
func buildPurchaseQuery(c *fiber.Ctx) *validation.Query {
return &validation.Query{
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: strings.TrimSpace(c.Query("search")),
ApprovalStatus: strings.TrimSpace(c.Query("approval_status")),
PoDate: strings.TrimSpace(c.Query("po_date")),
PoDateFrom: strings.TrimSpace(c.Query("po_date_from")),
PoDateTo: strings.TrimSpace(c.Query("po_date_to")),
CreatedFrom: strings.TrimSpace(c.Query("created_from")),
CreatedTo: strings.TrimSpace(c.Query("created_to")),
SupplierID: uint(c.QueryInt("supplier_id", 0)),
AreaID: uint(c.QueryInt("area_id", 0)),
LocationID: uint(c.QueryInt("location_id", 0)),
ProductCategoryID: strings.TrimSpace(c.Query("product_category_id")),
}
}
func (ctrl *PurchaseController) getAllPurchasesForExcel(c *fiber.Ctx, baseQuery *validation.Query) ([]entity.Purchase, error) {
query := *baseQuery
query.Page = 1
query.Limit = purchaseExcelExportFetchLimit
results := make([]entity.Purchase, 0)
for {
pageResults, total, err := ctrl.service.GetAll(c, &query)
if err != nil {
return nil, err
}
if len(pageResults) == 0 || total == 0 {
break
}
results = append(results, pageResults...)
if int64(len(results)) >= total {
break
}
query.Page++
}
return results, nil
}
func (ctrl *PurchaseController) GetOne(c *fiber.Ctx) error {
param := c.Params("id")