feat: expose received_date in laporan pembelian

This commit is contained in:
Adnan Zahir
2026-04-25 22:24:28 +07:00
parent af5f3dc7d4
commit 27d076b817
2 changed files with 27 additions and 13 deletions
@@ -78,12 +78,13 @@ func setPurchaseExportColumns(file *excelize.File, sheet string) error {
"A": 16, "A": 16,
"B": 16, "B": 16,
"C": 14, "C": 14,
"D": 22, "D": 14,
"E": 22, "E": 22,
"F": 18, "F": 22,
"G": 18, "G": 18,
"H": 52, "H": 18,
"I": 24, "I": 52,
"J": 24,
} }
for col, width := range columnWidths { for col, width := range columnWidths {
@@ -103,6 +104,7 @@ func setPurchaseExportHeaders(file *excelize.File, sheet string) error {
"PR Number", "PR Number",
"PO Number", "PO Number",
"Tanggal PO", "Tanggal PO",
"Tanggal Terima",
"Supplier", "Supplier",
"Lokasi", "Lokasi",
"Status", "Status",
@@ -136,7 +138,7 @@ func setPurchaseExportHeaders(file *excelize.File, sheet string) error {
return err return err
} }
return file.SetCellStyle(sheet, "A1", "I1", headerStyle) return file.SetCellStyle(sheet, "A1", "J1", 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 {
@@ -155,22 +157,25 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha
if err := file.SetCellValue(sheet, "C"+row, formatPurchaseExportDate(item.PoDate)); err != nil { if err := file.SetCellValue(sheet, "C"+row, formatPurchaseExportDate(item.PoDate)); err != nil {
return err return err
} }
if err := file.SetCellValue(sheet, "D"+row, safePurchaseSupplierName(item)); err != nil { if err := file.SetCellValue(sheet, "D"+row, formatPurchaseExportDate(item.ReceivedDate)); err != nil {
return err return err
} }
if err := file.SetCellValue(sheet, "E"+row, safePurchaseLocationName(item)); err != nil { if err := file.SetCellValue(sheet, "E"+row, safePurchaseSupplierName(item)); err != nil {
return err return err
} }
if err := file.SetCellValue(sheet, "F"+row, formatPurchaseExportStatus(item)); err != nil { if err := file.SetCellValue(sheet, "F"+row, safePurchaseLocationName(item)); err != nil {
return err return err
} }
if err := file.SetCellValue(sheet, "G"+row, formatPurchaseRupiah(grandTotals[item.Id])); err != nil { if err := file.SetCellValue(sheet, "G"+row, formatPurchaseExportStatus(item)); err != nil {
return err return err
} }
if err := file.SetCellValue(sheet, "H"+row, formatPurchaseProducts(item)); err != nil { if err := file.SetCellValue(sheet, "H"+row, formatPurchaseRupiah(grandTotals[item.Id])); err != nil {
return err return err
} }
if err := file.SetCellValue(sheet, "I"+row, safePurchaseExportPointerText(item.Notes)); err != nil { if err := file.SetCellValue(sheet, "I"+row, formatPurchaseProducts(item)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "J"+row, safePurchaseExportPointerText(item.Notes)); err != nil {
return err return err
} }
} }
@@ -192,7 +197,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", "I"+strconv.Itoa(lastRow), dataStyle); err != nil { if err := file.SetCellStyle(sheet, "A2", "J"+strconv.Itoa(lastRow), dataStyle); err != nil {
return err return err
} }
@@ -212,7 +217,7 @@ func setPurchaseExportRows(file *excelize.File, sheet string, items []dto.Purcha
return err return err
} }
return file.SetCellStyle(sheet, "G2", "G"+strconv.Itoa(lastRow), moneyStyle) return file.SetCellStyle(sheet, "H2", "H"+strconv.Itoa(lastRow), moneyStyle)
} }
func buildPurchaseGrandTotalMap(items []entity.Purchase) map[uint]float64 { func buildPurchaseGrandTotalMap(items []entity.Purchase) map[uint]float64 {
@@ -27,6 +27,7 @@ type PurchaseListDTO struct {
PurchaseRelationDTO PurchaseRelationDTO
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"` Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
DueDate *time.Time `json:"due_date"` DueDate *time.Time `json:"due_date"`
ReceivedDate *time.Time `json:"received_date"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"` CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
RequesterName string `json:"requester_name"` RequesterName string `json:"requester_name"`
PoExpedition []PoExpeditionDTO `json:"po_expedition"` PoExpedition []PoExpeditionDTO `json:"po_expedition"`
@@ -174,6 +175,7 @@ func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
poExpedition = make([]PoExpeditionDTO, 0) poExpedition = make([]PoExpeditionDTO, 0)
location *locationDTO.LocationRelationDTO location *locationDTO.LocationRelationDTO
area *areaDTO.AreaRelationDTO area *areaDTO.AreaRelationDTO
receivedDate *time.Time
) )
productMap := make(map[uint]productDTO.ProductRelationDTO) productMap := make(map[uint]productDTO.ProductRelationDTO)
expeditionRefSet := make(map[uint64]struct{}) expeditionRefSet := make(map[uint64]struct{})
@@ -205,6 +207,12 @@ func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
ar := areaDTO.ToAreaRelationDTO(item.Warehouse.Area) ar := areaDTO.ToAreaRelationDTO(item.Warehouse.Area)
area = &ar area = &ar
} }
if item.ReceivedDate != nil && !item.ReceivedDate.IsZero() {
if receivedDate == nil || item.ReceivedDate.Before(*receivedDate) {
t := *item.ReceivedDate
receivedDate = &t
}
}
} }
products := make([]productDTO.ProductRelationDTO, 0, len(productMap)) products := make([]productDTO.ProductRelationDTO, 0, len(productMap))
for _, prod := range productMap { for _, prod := range productMap {
@@ -215,6 +223,7 @@ func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
PurchaseRelationDTO: ToPurchaseRelationDTO(&p), PurchaseRelationDTO: ToPurchaseRelationDTO(&p),
Supplier: supplier, Supplier: supplier,
DueDate: p.DueDate, DueDate: p.DueDate,
ReceivedDate: receivedDate,
CreatedUser: createdUser, CreatedUser: createdUser,
RequesterName: requesterName, RequesterName: requesterName,
PoExpedition: poExpedition, PoExpedition: poExpedition,