add kolom lokasi to export

This commit is contained in:
giovanni
2026-04-23 13:49:51 +07:00
parent c744043321
commit 151edf578e
2 changed files with 57 additions and 28 deletions
@@ -79,10 +79,11 @@ func setPurchaseExportColumns(file *excelize.File, sheet string) error {
"B": 16, "B": 16,
"C": 14, "C": 14,
"D": 22, "D": 22,
"E": 18, "E": 22,
"F": 18, "F": 18,
"G": 52, "G": 18,
"H": 24, "H": 52,
"I": 24,
} }
for col, width := range columnWidths { for col, width := range columnWidths {
@@ -103,6 +104,7 @@ func setPurchaseExportHeaders(file *excelize.File, sheet string) error {
"PO Number", "PO Number",
"Tanggal PO", "Tanggal PO",
"Supplier", "Supplier",
"Lokasi",
"Status", "Status",
"Grand Total", "Grand Total",
"Products", "Products",
@@ -134,7 +136,7 @@ func setPurchaseExportHeaders(file *excelize.File, sheet string) error {
return err 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 { 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 { if err := file.SetCellValue(sheet, "D"+row, safePurchaseSupplierName(item)); err != nil {
return err 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 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 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 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 return err
} }
} }
@@ -187,7 +192,7 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha
if err != nil { if err != nil {
return err 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 return err
} }
@@ -207,7 +212,7 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha
return err 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 { func buildPurchaseGrandTotalMap(items []entity.Purchase) map[uint]float64 {
@@ -229,6 +234,13 @@ func safePurchaseSupplierName(item dto.PurchaseListDTO) string {
return safePurchaseExportText(item.Supplier.Name) 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 { func formatPurchaseExportStatus(item dto.PurchaseListDTO) string {
if item.LatestApproval == nil { if item.LatestApproval == nil {
return "-" return "-"
@@ -22,9 +22,9 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) {
nil, nil,
"catatan", "catatan",
[]entity.PurchaseItem{ []entity.PurchaseItem{
buildPurchaseItemForExportTest(11, "Pakan Starter", 1000000), buildPurchaseItemForExportTest(11, "Pakan Starter", 1000000, "Location A"),
buildPurchaseItemForExportTest(12, "Vitamin A", 350000), buildPurchaseItemForExportTest(12, "Vitamin A", 350000, "Location B"),
buildPurchaseItemForExportTest(11, "Pakan Starter", 0), buildPurchaseItemForExportTest(11, "Pakan Starter", 0, ""),
}, },
), ),
buildPurchaseForExportTest( buildPurchaseForExportTest(
@@ -37,7 +37,7 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) {
ptrApprovalAction(entity.ApprovalActionRejected), ptrApprovalAction(entity.ApprovalActionRejected),
"", "",
[]entity.PurchaseItem{ []entity.PurchaseItem{
buildPurchaseItemForExportTest(21, "Obat X", 75000), buildPurchaseItemForExportTest(21, "Obat X", 75000, ""),
}, },
), ),
}) })
@@ -56,10 +56,11 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) {
"B1": "PO Number", "B1": "PO Number",
"C1": "Tanggal PO", "C1": "Tanggal PO",
"D1": "Supplier", "D1": "Supplier",
"E1": "Status", "E1": "Lokasi",
"F1": "Grand Total", "F1": "Status",
"G1": "Products", "G1": "Grand Total",
"H1": "Notes", "H1": "Products",
"I1": "Notes",
} }
for cell, expected := range expectedHeaders { for cell, expected := range expectedHeaders {
got, err := file.GetCellValue(purchaseExportSheetName, cell) got, err := file.GetCellValue(purchaseExportSheetName, cell)
@@ -75,18 +76,20 @@ func TestBuildPurchaseExportWorkbookHeadersAndRows(t *testing.T) {
assertPurchaseCellEquals(t, file, "B2", "PO-00011") assertPurchaseCellEquals(t, file, "B2", "PO-00011")
assertPurchaseCellEquals(t, file, "C2", "22-04-2026") assertPurchaseCellEquals(t, file, "C2", "22-04-2026")
assertPurchaseCellEquals(t, file, "D2", "Supplier A") assertPurchaseCellEquals(t, file, "D2", "Supplier A")
assertPurchaseCellEquals(t, file, "E2", "Manager Purchase") assertPurchaseCellEquals(t, file, "E2", "Location A")
assertPurchaseCellEquals(t, file, "F2", "Rp 1.350.000") assertPurchaseCellEquals(t, file, "F2", "Manager Purchase")
assertPurchaseCellEquals(t, file, "G2", "Pakan Starter, Vitamin A") assertPurchaseCellEquals(t, file, "G2", "Rp 1.350.000")
assertPurchaseCellEquals(t, file, "H2", "catatan") assertPurchaseCellEquals(t, file, "H2", "Pakan Starter, Vitamin A")
assertPurchaseCellEquals(t, file, "I2", "catatan")
assertPurchaseCellEquals(t, file, "A3", "PR-00012") assertPurchaseCellEquals(t, file, "A3", "PR-00012")
assertPurchaseCellEquals(t, file, "B3", "-") assertPurchaseCellEquals(t, file, "B3", "-")
assertPurchaseCellEquals(t, file, "C3", "-") assertPurchaseCellEquals(t, file, "C3", "-")
assertPurchaseCellEquals(t, file, "E3", "Ditolak") assertPurchaseCellEquals(t, file, "E3", "-")
assertPurchaseCellEquals(t, file, "F3", "Rp 75.000") assertPurchaseCellEquals(t, file, "F3", "Ditolak")
assertPurchaseCellEquals(t, file, "G3", "Obat X") assertPurchaseCellEquals(t, file, "G3", "Rp 75.000")
assertPurchaseCellEquals(t, file, "H3", "-") assertPurchaseCellEquals(t, file, "H3", "Obat X")
assertPurchaseCellEquals(t, file, "I3", "-")
} }
func assertPurchaseCellEquals(t *testing.T, file *excelize.File, cell, expected string) { 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 { func buildPurchaseItemForExportTest(productID uint, productName string, totalPrice float64, locationName string) entity.PurchaseItem {
return entity.PurchaseItem{ item := entity.PurchaseItem{
ProductId: productID, ProductId: productID,
TotalPrice: totalPrice, TotalPrice: totalPrice,
Product: &entity.Product{ Product: &entity.Product{
@@ -150,6 +153,20 @@ func buildPurchaseItemForExportTest(productID uint, productName string, totalPri
Name: productName, 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 { func ptrApprovalAction(value entity.ApprovalAction) *entity.ApprovalAction {