mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
Merge branch 'feat/marketing-filter-range-date' into 'rc/01'
feat: add date range filter to marketing list API See merge request mbugroup/lti-api!592
This commit is contained in:
@@ -75,6 +75,9 @@ func (u *DeliveryOrdersController) GetAll(c *fiber.Ctx) error {
|
||||
WarehouseID: uint(c.QueryInt("warehouse_id", 0)),
|
||||
SortBy: sortBy,
|
||||
SortOrder: sortOrder,
|
||||
StartDate: strings.TrimSpace(c.Query("start_date", "")),
|
||||
EndDate: strings.TrimSpace(c.Query("end_date", "")),
|
||||
FilterBy: strings.TrimSpace(c.Query("filter_by", "")),
|
||||
}
|
||||
|
||||
if isAllExcelExportRequest(c) {
|
||||
|
||||
@@ -201,11 +201,6 @@ func setMarketingExportRows(file *excelize.File, sheet string, items []dto.Marke
|
||||
for _, group := range item.DeliveryOrder {
|
||||
doNumber := safeMarketingExportText(group.DoNumber)
|
||||
|
||||
doDate := "-"
|
||||
if group.DeliveryDate != nil {
|
||||
doDate = formatMarketingExportDate(*group.DeliveryDate)
|
||||
}
|
||||
|
||||
gudang := "-"
|
||||
if group.Warehouse != nil {
|
||||
gudang = safeMarketingExportText(group.Warehouse.Name)
|
||||
@@ -215,7 +210,7 @@ func setMarketingExportRows(file *excelize.File, sheet string, items []dto.Marke
|
||||
row++
|
||||
r := strconv.Itoa(row)
|
||||
vals := map[string]interface{}{
|
||||
"A": doNumber, "B": doDate, "C": status, "D": customer, "E": salesPerson,
|
||||
"A": doNumber, "B": soDate, "C": status, "D": customer, "E": salesPerson,
|
||||
"F": "-", "G": "-", "H": gudang, "I": "-", "J": "-", "K": "-",
|
||||
"L": "-", "M": "-", "N": "-", "O": "-",
|
||||
"P": grandTotal, "Q": notes,
|
||||
@@ -251,7 +246,7 @@ func setMarketingExportRows(file *excelize.File, sheet string, items []dto.Marke
|
||||
if err := file.SetCellValue(sheet, "A"+r, doNumber); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := file.SetCellValue(sheet, "B"+r, doDate); err != nil {
|
||||
if err := file.SetCellValue(sheet, "B"+r, soDate); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := file.SetCellValue(sheet, "C"+r, status); err != nil {
|
||||
@@ -347,7 +342,7 @@ func setMarketingExportRows(file *excelize.File, sheet string, items []dto.Marke
|
||||
}
|
||||
|
||||
gudang := "-"
|
||||
if prod.ProductWarehouse != nil {
|
||||
if prod.ProductWarehouse != nil && prod.ProductWarehouse.Warehouse != nil {
|
||||
gudang = safeMarketingExportText(prod.ProductWarehouse.Warehouse.Name)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ import (
|
||||
)
|
||||
|
||||
func TestBuildMarketingExportWorkbookHeadersAndRows(t *testing.T) {
|
||||
// DO item has soDate=2026-05-31 and deliveryDate=2026-06-01 to verify
|
||||
// the export uses soDate (not deliveryDate) in column B.
|
||||
deliveryDate := time.Date(2026, time.June, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
items := []dto.MarketingListDTO{
|
||||
{
|
||||
MarketingRelationDTO: dto.MarketingRelationDTO{
|
||||
@@ -51,6 +55,22 @@ func TestBuildMarketingExportWorkbookHeadersAndRows(t *testing.T) {
|
||||
Action: strPtr("REJECTED"),
|
||||
},
|
||||
},
|
||||
{
|
||||
MarketingRelationDTO: dto.MarketingRelationDTO{
|
||||
SoNumber: "SO-00760",
|
||||
SoDate: time.Date(2026, time.May, 31, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
Customer: customerDTO.CustomerRelationDTO{Name: "CORDELA"},
|
||||
DeliveryOrder: []dto.DeliveryGroupDTO{
|
||||
{
|
||||
DoNumber: "DO-01954",
|
||||
DeliveryDate: &deliveryDate,
|
||||
},
|
||||
},
|
||||
LatestApproval: approvalDTO.ApprovalRelationDTO{
|
||||
StepName: "Delivery Order",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
content, err := buildMarketingExportWorkbook(items)
|
||||
@@ -69,9 +89,10 @@ func TestBuildMarketingExportWorkbookHeadersAndRows(t *testing.T) {
|
||||
"B1": "Tanggal",
|
||||
"C1": "Status",
|
||||
"D1": "Customer",
|
||||
"E1": "Grand Total",
|
||||
"F1": "Products",
|
||||
"G1": "Notes",
|
||||
"E1": "Sales",
|
||||
"G1": "Nama Produk",
|
||||
"P1": "Grand Total",
|
||||
"Q1": "Catatan",
|
||||
}
|
||||
for cell, expected := range expectedHeaders {
|
||||
got, err := file.GetCellValue(marketingExportSheetName, cell)
|
||||
@@ -83,19 +104,25 @@ func TestBuildMarketingExportWorkbookHeadersAndRows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// SO-00762: 3 products → rows 2, 3, 4
|
||||
assertCellEquals(t, file, "A2", "SO-00762")
|
||||
assertCellEquals(t, file, "B2", "22-04-2026")
|
||||
assertCellEquals(t, file, "C2", "Pengajuan")
|
||||
assertCellEquals(t, file, "D2", "AJAT")
|
||||
assertCellEquals(t, file, "E2", "Rp 5.206.200.000")
|
||||
assertCellEquals(t, file, "F2", "PAKAN GROWING CRUMBLE 8603 MALINDO, 295 GOLD PELLET")
|
||||
assertCellEquals(t, file, "G2", "tes")
|
||||
assertCellEquals(t, file, "G2", "PAKAN GROWING CRUMBLE 8603 MALINDO")
|
||||
assertCellEquals(t, file, "Q2", "tes")
|
||||
|
||||
assertCellEquals(t, file, "A3", "SO-00761")
|
||||
assertCellEquals(t, file, "C3", "Ditolak")
|
||||
assertCellEquals(t, file, "E3", "Rp 75.000")
|
||||
assertCellEquals(t, file, "F3", "HS30 FOAM @20 LITER")
|
||||
assertCellEquals(t, file, "G3", "-")
|
||||
// SO-00761 (rejected): 1 product → row 5
|
||||
assertCellEquals(t, file, "A5", "SO-00761")
|
||||
assertCellEquals(t, file, "C5", "Ditolak")
|
||||
assertCellEquals(t, file, "G5", "HS30 FOAM @20 LITER")
|
||||
assertCellEquals(t, file, "Q5", "-")
|
||||
|
||||
// DO-01954: column B must use soDate (31-05-2026), not deliveryDate (01-06-2026)
|
||||
assertCellEquals(t, file, "A6", "DO-01954")
|
||||
assertCellEquals(t, file, "B6", "31-05-2026")
|
||||
assertCellEquals(t, file, "C6", "Delivery Order")
|
||||
assertCellEquals(t, file, "D6", "CORDELA")
|
||||
}
|
||||
|
||||
func assertCellEquals(t *testing.T, file *excelize.File, cell, expected string) {
|
||||
|
||||
@@ -321,6 +321,21 @@ func (s deliveryOrdersService) GetAll(c *fiber.Ctx, params *validation.DeliveryO
|
||||
return db.Where("id = ?", params.MarketingId)
|
||||
}
|
||||
|
||||
dateStart, dateEnd, dateErr := utils.ParseDateRangeForQuery(params.StartDate, params.EndDate)
|
||||
if dateErr != nil {
|
||||
return db.Where("1 = 0")
|
||||
}
|
||||
dateCol := "marketings.so_date"
|
||||
if strings.TrimSpace(params.FilterBy) == "created_at" {
|
||||
dateCol = "marketings.created_at"
|
||||
}
|
||||
if dateStart != nil {
|
||||
db = db.Where(dateCol+" >= ?", *dateStart)
|
||||
}
|
||||
if dateEnd != nil {
|
||||
db = db.Where(dateCol+" < ?", *dateEnd)
|
||||
}
|
||||
|
||||
orderDir := "DESC"
|
||||
if params.SortOrder != "" {
|
||||
orderDir = strings.ToUpper(params.SortOrder)
|
||||
|
||||
@@ -34,6 +34,9 @@ type DeliveryOrderQuery struct {
|
||||
WarehouseID uint `query:"warehouse_id" validate:"omitempty,gt=0"`
|
||||
SortBy string `query:"sort_by" validate:"omitempty,oneof=so_number so_date status customer grand_total created_at"`
|
||||
SortOrder string `query:"sort_order" validate:"omitempty,oneof=asc desc"`
|
||||
StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"`
|
||||
EndDate string `query:"end_date" validate:"omitempty,datetime=2006-01-02"`
|
||||
FilterBy string `query:"filter_by" validate:"omitempty,oneof=so_date created_at"`
|
||||
}
|
||||
|
||||
type DeliveryOrderApprove struct {
|
||||
|
||||
Reference in New Issue
Block a user