From 151edf578e8de49d58ff4abe6352495ec6bd7bb4 Mon Sep 17 00:00:00 2001 From: giovanni Date: Thu, 23 Apr 2026 13:49:51 +0700 Subject: [PATCH] add kolom lokasi to export --- .../purchases/controllers/purchase.export.go | 32 +++++++---- .../controllers/purchase.export_test.go | 53 ++++++++++++------- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/internal/modules/purchases/controllers/purchase.export.go b/internal/modules/purchases/controllers/purchase.export.go index 299df22b..acbed929 100644 --- a/internal/modules/purchases/controllers/purchase.export.go +++ b/internal/modules/purchases/controllers/purchase.export.go @@ -79,10 +79,11 @@ func setPurchaseExportColumns(file *excelize.File, sheet string) error { "B": 16, "C": 14, "D": 22, - "E": 18, + "E": 22, "F": 18, - "G": 52, - "H": 24, + "G": 18, + "H": 52, + "I": 24, } for col, width := range columnWidths { @@ -103,6 +104,7 @@ func setPurchaseExportHeaders(file *excelize.File, sheet string) error { "PO Number", "Tanggal PO", "Supplier", + "Lokasi", "Status", "Grand Total", "Products", @@ -134,7 +136,7 @@ func setPurchaseExportHeaders(file *excelize.File, sheet string) error { return err } - return file.SetCellStyle(sheet, "A1", "H1", headerStyle) + return file.SetCellStyle(sheet, "A1", "I1", headerStyle) } func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.PurchaseListDTO, grandTotals map[uint]float64) error { @@ -156,16 +158,19 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha if err := file.SetCellValue(sheet, "D"+row, safePurchaseSupplierName(item)); err != nil { return err } - if err := file.SetCellValue(sheet, "E"+row, formatPurchaseExportStatus(item)); err != nil { + if err := file.SetCellValue(sheet, "E"+row, safePurchaseLocationName(item)); err != nil { return err } - if err := file.SetCellValue(sheet, "F"+row, formatPurchaseRupiah(grandTotals[item.Id])); err != nil { + if err := file.SetCellValue(sheet, "F"+row, formatPurchaseExportStatus(item)); err != nil { return err } - if err := file.SetCellValue(sheet, "G"+row, formatPurchaseProducts(item)); err != nil { + if err := file.SetCellValue(sheet, "G"+row, formatPurchaseRupiah(grandTotals[item.Id])); err != nil { return err } - if err := file.SetCellValue(sheet, "H"+row, safePurchaseExportPointerText(item.Notes)); err != nil { + if err := file.SetCellValue(sheet, "H"+row, formatPurchaseProducts(item)); err != nil { + return err + } + if err := file.SetCellValue(sheet, "I"+row, safePurchaseExportPointerText(item.Notes)); err != nil { return err } } @@ -187,7 +192,7 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha if err != nil { return err } - if err := file.SetCellStyle(sheet, "A2", "H"+strconv.Itoa(lastRow), dataStyle); err != nil { + if err := file.SetCellStyle(sheet, "A2", "I"+strconv.Itoa(lastRow), dataStyle); err != nil { return err } @@ -207,7 +212,7 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha return err } - return file.SetCellStyle(sheet, "F2", "F"+strconv.Itoa(lastRow), moneyStyle) + return file.SetCellStyle(sheet, "G2", "G"+strconv.Itoa(lastRow), moneyStyle) } func buildPurchaseGrandTotalMap(items []entity.Purchase) map[uint]float64 { @@ -229,6 +234,13 @@ func safePurchaseSupplierName(item dto.PurchaseListDTO) string { return safePurchaseExportText(item.Supplier.Name) } +func safePurchaseLocationName(item dto.PurchaseListDTO) string { + if item.Location == nil { + return "-" + } + return safePurchaseExportText(item.Location.Name) +} + func formatPurchaseExportStatus(item dto.PurchaseListDTO) string { if item.LatestApproval == nil { return "-" diff --git a/internal/modules/purchases/controllers/purchase.export_test.go b/internal/modules/purchases/controllers/purchase.export_test.go index c440c3e4..d93bf108 100644 --- a/internal/modules/purchases/controllers/purchase.export_test.go +++ b/internal/modules/purchases/controllers/purchase.export_test.go @@ -22,9 +22,9 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) { nil, "catatan", []entity.PurchaseItem{ - buildPurchaseItemForExportTest(11, "Pakan Starter", 1000000), - buildPurchaseItemForExportTest(12, "Vitamin A", 350000), - buildPurchaseItemForExportTest(11, "Pakan Starter", 0), + buildPurchaseItemForExportTest(11, "Pakan Starter", 1000000, "Location A"), + buildPurchaseItemForExportTest(12, "Vitamin A", 350000, "Location B"), + buildPurchaseItemForExportTest(11, "Pakan Starter", 0, ""), }, ), buildPurchaseForExportTest( @@ -37,7 +37,7 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) { ptrApprovalAction(entity.ApprovalActionRejected), "", []entity.PurchaseItem{ - buildPurchaseItemForExportTest(21, "Obat X", 75000), + buildPurchaseItemForExportTest(21, "Obat X", 75000, ""), }, ), }) @@ -56,10 +56,11 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) { "B1": "PO Number", "C1": "Tanggal PO", "D1": "Supplier", - "E1": "Status", - "F1": "Grand Total", - "G1": "Products", - "H1": "Notes", + "E1": "Lokasi", + "F1": "Status", + "G1": "Grand Total", + "H1": "Products", + "I1": "Notes", } for cell, expected := range expectedHeaders { got, err := file.GetCellValue(purchaseExportSheetName, cell) @@ -75,18 +76,20 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) { assertPurchaseCellEquals(t, file, "B2", "PO-00011") assertPurchaseCellEquals(t, file, "C2", "22-04-2026") assertPurchaseCellEquals(t, file, "D2", "Supplier A") - assertPurchaseCellEquals(t, file, "E2", "Manager Purchase") - assertPurchaseCellEquals(t, file, "F2", "Rp 1.350.000") - assertPurchaseCellEquals(t, file, "G2", "Pakan Starter, Vitamin A") - assertPurchaseCellEquals(t, file, "H2", "catatan") + assertPurchaseCellEquals(t, file, "E2", "Location A") + assertPurchaseCellEquals(t, file, "F2", "Manager Purchase") + assertPurchaseCellEquals(t, file, "G2", "Rp 1.350.000") + assertPurchaseCellEquals(t, file, "H2", "Pakan Starter, Vitamin A") + assertPurchaseCellEquals(t, file, "I2", "catatan") assertPurchaseCellEquals(t, file, "A3", "PR-00012") assertPurchaseCellEquals(t, file, "B3", "-") assertPurchaseCellEquals(t, file, "C3", "-") - assertPurchaseCellEquals(t, file, "E3", "Ditolak") - assertPurchaseCellEquals(t, file, "F3", "Rp 75.000") - assertPurchaseCellEquals(t, file, "G3", "Obat X") - assertPurchaseCellEquals(t, file, "H3", "-") + assertPurchaseCellEquals(t, file, "E3", "-") + assertPurchaseCellEquals(t, file, "F3", "Ditolak") + assertPurchaseCellEquals(t, file, "G3", "Rp 75.000") + assertPurchaseCellEquals(t, file, "H3", "Obat X") + assertPurchaseCellEquals(t, file, "I3", "-") } func assertPurchaseCellEquals(t *testing.T, file *excelize.File, cell, expected string) { @@ -141,8 +144,8 @@ func buildPurchaseForExportTest( } } -func buildPurchaseItemForExportTest(productID uint, productName string, totalPrice float64) entity.PurchaseItem { - return entity.PurchaseItem{ +func buildPurchaseItemForExportTest(productID uint, productName string, totalPrice float64, locationName string) entity.PurchaseItem { + item := entity.PurchaseItem{ ProductId: productID, TotalPrice: totalPrice, Product: &entity.Product{ @@ -150,6 +153,20 @@ func buildPurchaseItemForExportTest(productID uint, productName string, totalPri Name: productName, }, } + + if locationName != "" { + locationID := productID + 1000 + warehouseID := productID + 500 + item.Warehouse = &entity.Warehouse{ + Id: warehouseID, + Location: &entity.Location{ + Id: locationID, + Name: locationName, + }, + } + } + + return item } func ptrApprovalAction(value entity.ApprovalAction) *entity.ApprovalAction {