Compare commits

...

10 Commits

Author SHA1 Message Date
giovanni ef985b5da5 fix list penjualan and export penjualan dengan qty 2026-05-25 14:50:01 +07:00
Giovanni Gabriel Septriadi 1ca632d838 Merge branch 'development' into 'production'
Development

See merge request mbugroup/lti-api!559
2026-05-25 04:03:38 +00:00
Giovanni Gabriel Septriadi f0403e2699 Merge branch 'hot-fix/cikaum' into 'production'
add migration for normalize wrong location pullet cikaum

See merge request mbugroup/lti-api!558
2026-05-23 04:25:29 +00:00
giovanni 3e34da7385 add migration for normalize wrong location pullet cikaum 2026-05-23 11:12:36 +07:00
Giovanni Gabriel Septriadi 8750e2ffec Merge branch 'fix/location-flock' into 'development'
add migration for normalize wrong location pullet cikaum

See merge request mbugroup/lti-api!557
2026-05-23 04:07:29 +00:00
giovanni 3429529162 add migration for normalize wrong location pullet cikaum 2026-05-23 11:06:33 +07:00
Giovanni Gabriel Septriadi 32b8acb9dc Merge branch 'fix/po-a' into 'development'
fix monitoring saldo

See merge request mbugroup/lti-api!556
2026-05-23 02:36:42 +00:00
Giovanni Gabriel Septriadi 0d7a0e30cd Merge branch 'fix/po-a' into 'development'
fix debt supplier ekspedisi only realisasi

See merge request mbugroup/lti-api!555
2026-05-22 12:55:39 +00:00
Giovanni Gabriel Septriadi d0e7b7aad1 Merge branch 'fix/po-a' into 'development'
fix monitorin saldo without sales order;format date excel po

See merge request mbugroup/lti-api!554
2026-05-22 12:41:05 +00:00
Giovanni Gabriel Septriadi e781115390 Merge branch 'hot-fix/price-adj' into 'production'
hot fit update price adjustment stock

See merge request mbugroup/lti-api!553
2026-05-22 11:50:45 +00:00
4 changed files with 244 additions and 88 deletions
@@ -0,0 +1,31 @@
BEGIN;
-- Rollback konsolidasi: kembalikan data ke loc 18 / 25 sesuai snapshot pre-migration.
-- Order: un-soft-delete locations dulu agar FK tidak gagal saat UPDATE child.
-- 1. Un-soft-delete locations
UPDATE locations SET deleted_at = NULL WHERE id IN (18, 25);
-- 2. project_flocks: PF 30 -> 18, PF 25 & 31 -> 25
UPDATE project_flocks SET location_id = 18, updated_at = NOW() WHERE id = 30;
UPDATE project_flocks SET location_id = 25, updated_at = NOW() WHERE id IN (25, 31);
-- 3. kandangs: K9, K72, K117 -> 18; K10, K73, K116 -> 25
UPDATE kandangs SET location_id = 18, updated_at = NOW() WHERE id IN (9, 72, 117);
UPDATE kandangs SET location_id = 25, updated_at = NOW() WHERE id IN (10, 73, 116);
-- 4. kandang_groups: KG 26, 68 -> 18; KG 27, 67 -> 25
UPDATE kandang_groups SET location_id = 18, updated_at = NOW() WHERE id IN (26, 68);
UPDATE kandang_groups SET location_id = 25, updated_at = NOW() WHERE id IN (27, 67);
-- 5. warehouses: W27, W145, W152 -> 18; W3, W146, W153 -> 25
UPDATE warehouses SET location_id = 18, updated_at = NOW() WHERE id IN (27, 145, 152);
UPDATE warehouses SET location_id = 25, updated_at = NOW() WHERE id IN (3, 146, 153);
-- 6. expenses: list eksplisit per location
UPDATE expenses SET location_id = 18, updated_at = NOW()
WHERE id IN (36, 345, 500, 501, 502, 503, 504, 505, 506, 507, 508);
UPDATE expenses SET location_id = 25, updated_at = NOW()
WHERE id IN (9, 37, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518);
COMMIT;
@@ -0,0 +1,34 @@
BEGIN;
-- Konsolidasi 3 lokasi "Pullet Cikaum" jadi 1.
-- Pindahkan semua data di loc 18 (Pullet Cikaum 1) & 25 (Pullet Cikaum 2) ke loc 2 (Pullet Cikaum).
-- Urutan wajib: semua UPDATE child harus selesai SEBELUM soft-delete locations,
-- karena trigger trg_soft_delete_fk_locations akan RAISE EXCEPTION untuk FK
-- RESTRICT (project_flocks, kandangs, kandang_groups, expenses) atau SET NULL
-- untuk warehouses kalau masih ada child yang reference.
-- 1. project_flocks (PF 25, 30, 31)
UPDATE project_flocks SET location_id = 2, updated_at = NOW()
WHERE location_id IN (18, 25);
-- 2. kandangs (K9, K72, K117, K10, K73, K116)
UPDATE kandangs SET location_id = 2, updated_at = NOW()
WHERE location_id IN (18, 25);
-- 3. kandang_groups (KG 26, 68, 27, 67)
UPDATE kandang_groups SET location_id = 2, updated_at = NOW()
WHERE location_id IN (18, 25);
-- 4. warehouses (W3, W27, W145, W146, W152, W153)
UPDATE warehouses SET location_id = 2, updated_at = NOW()
WHERE location_id IN (18, 25);
-- 5. expenses (23 row BOP)
UPDATE expenses SET location_id = 2, updated_at = NOW()
WHERE location_id IN (18, 25);
-- 6. Soft-delete locations 18 & 25 (kosong, aman karena semua child sudah pindah)
UPDATE locations SET deleted_at = NOW()
WHERE id IN (18, 25) AND deleted_at IS NULL;
COMMIT;
@@ -75,9 +75,18 @@ func setMarketingExportColumns(file *excelize.File, sheet string) error {
"B": 14,
"C": 18,
"D": 20,
"E": 18,
"F": 60,
"G": 24,
"E": 14,
"F": 40,
"G": 10,
"H": 12,
"I": 12,
"J": 12,
"K": 16,
"L": 16,
"M": 18,
"N": 18,
"O": 18,
"P": 24,
}
for col, width := range columnWidths {
@@ -95,13 +104,22 @@ func setMarketingExportColumns(file *excelize.File, sheet string) error {
func setMarketingExportHeaders(file *excelize.File, sheet string) error {
headers := []string{
"No. Order",
"Tanggal",
"Status",
"Customer",
"Grand Total",
"Products",
"Notes",
"No. Order", // A
"Tanggal", // B
"Status", // C
"Customer", // D
"Tipe", // E
"Nama Produk", // F
"Week", // G
"Jumlah", // H
"Satuan", // I
"Qty Peti", // J
"Berat Rata-rata (kg)", // K
"Total Berat (kg)", // L
"Harga Satuan", // M
"Total Harga", // N
"Grand Total", // O
"Catatan", // P
}
for i, header := range headers {
@@ -130,7 +148,7 @@ func setMarketingExportHeaders(file *excelize.File, sheet string) error {
return err
}
return file.SetCellStyle(sheet, "A1", "G1", headerStyle)
return file.SetCellStyle(sheet, "A1", "P1", headerStyle)
}
func setMarketingExportRows(file *excelize.File, sheet string, items []dto.MarketingListDTO) error {
@@ -138,70 +156,154 @@ func setMarketingExportRows(file *excelize.File, sheet string, items []dto.Marke
return nil
}
for i, item := range items {
rowNumber := i + 2
if err := file.SetCellValue(sheet, "A"+strconv.Itoa(rowNumber), safeMarketingExportText(item.SoNumber)); err != nil {
return err
row := 1
for _, item := range items {
soNumber := safeMarketingExportText(item.SoNumber)
soDate := formatMarketingExportDate(item.SoDate)
status := formatMarketingExportStatus(item)
customer := safeMarketingExportText(item.Customer.Name)
grandTotal := sumMarketingGrandTotal(item.SalesOrder)
notes := safeMarketingExportText(item.Notes)
if len(item.SalesOrder) == 0 {
row++
r := strconv.Itoa(row)
vals := map[string]interface{}{
"A": soNumber, "B": soDate, "C": status, "D": customer,
"E": "-", "F": "-", "G": "-", "H": "-", "I": "-", "J": "-",
"K": "-", "L": "-", "M": "-", "N": "-",
"O": grandTotal, "P": notes,
}
for col, val := range vals {
if err := file.SetCellValue(sheet, col+r, val); err != nil {
return err
}
}
continue
}
if err := file.SetCellValue(sheet, "B"+strconv.Itoa(rowNumber), formatMarketingExportDate(item.SoDate)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "C"+strconv.Itoa(rowNumber), formatMarketingExportStatus(item)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "D"+strconv.Itoa(rowNumber), safeMarketingExportText(item.Customer.Name)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "E"+strconv.Itoa(rowNumber), sumMarketingGrandTotal(item.SalesOrder)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "F"+strconv.Itoa(rowNumber), formatMarketingProducts(item.SalesOrder)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "G"+strconv.Itoa(rowNumber), safeMarketingExportText(item.Notes)); err != nil {
return err
for _, prod := range item.SalesOrder {
row++
r := strconv.Itoa(row)
productName := "-"
if prod.ProductWarehouse != nil && prod.ProductWarehouse.Product != nil {
if n := strings.TrimSpace(prod.ProductWarehouse.Product.Name); n != "" {
productName = n
}
}
week := "-"
if prod.Week != nil {
week = strconv.Itoa(*prod.Week)
}
satuan := "-"
if prod.ConvertionUnit != nil && strings.TrimSpace(*prod.ConvertionUnit) != "" {
satuan = *prod.ConvertionUnit
}
if err := file.SetCellValue(sheet, "A"+r, soNumber); err != nil {
return err
}
if err := file.SetCellValue(sheet, "B"+r, soDate); err != nil {
return err
}
if err := file.SetCellValue(sheet, "C"+r, status); err != nil {
return err
}
if err := file.SetCellValue(sheet, "D"+r, customer); err != nil {
return err
}
if err := file.SetCellValue(sheet, "E"+r, safeMarketingExportText(prod.MarketingType)); err != nil {
return err
}
if err := file.SetCellValue(sheet, "F"+r, productName); err != nil {
return err
}
if err := file.SetCellValue(sheet, "G"+r, week); err != nil {
return err
}
if err := file.SetCellValue(sheet, "H"+r, prod.Qty); err != nil {
return err
}
if err := file.SetCellValue(sheet, "I"+r, satuan); err != nil {
return err
}
if prod.TotalPeti != nil {
if err := file.SetCellValue(sheet, "J"+r, *prod.TotalPeti); err != nil {
return err
}
} else {
if err := file.SetCellValue(sheet, "J"+r, "-"); err != nil {
return err
}
}
if err := file.SetCellValue(sheet, "K"+r, prod.AvgWeight); err != nil {
return err
}
if err := file.SetCellValue(sheet, "L"+r, prod.TotalWeight); err != nil {
return err
}
if err := file.SetCellValue(sheet, "M"+r, prod.UnitPrice); err != nil {
return err
}
if err := file.SetCellValue(sheet, "N"+r, prod.TotalPrice); err != nil {
return err
}
if err := file.SetCellValue(sheet, "O"+r, grandTotal); err != nil {
return err
}
if err := file.SetCellValue(sheet, "P"+r, notes); err != nil {
return err
}
}
}
lastRow := len(items) + 1
lastRow := row
lastRowStr := strconv.Itoa(lastRow)
border := []excelize.Border{
{Type: "left", Color: "D1D5DB", Style: 1},
{Type: "top", Color: "D1D5DB", Style: 1},
{Type: "bottom", Color: "D1D5DB", Style: 1},
{Type: "right", Color: "D1D5DB", Style: 1},
}
dataStyle, err := file.NewStyle(&excelize.Style{
Alignment: &excelize.Alignment{
Horizontal: "left",
Vertical: "center",
WrapText: true,
},
Border: []excelize.Border{
{Type: "left", Color: "D1D5DB", Style: 1},
{Type: "top", Color: "D1D5DB", Style: 1},
{Type: "bottom", Color: "D1D5DB", Style: 1},
{Type: "right", Color: "D1D5DB", Style: 1},
},
Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true},
Border: border,
})
if err != nil {
return err
}
if err := file.SetCellStyle(sheet, "A2", "G"+strconv.Itoa(lastRow), dataStyle); err != nil {
if err := file.SetCellStyle(sheet, "A2", "P"+lastRowStr, dataStyle); err != nil {
return err
}
moneyStyle, err := file.NewStyle(&excelize.Style{
Alignment: &excelize.Alignment{
Horizontal: "right",
Vertical: "center",
},
Border: []excelize.Border{
{Type: "left", Color: "D1D5DB", Style: 1},
{Type: "top", Color: "D1D5DB", Style: 1},
{Type: "bottom", Color: "D1D5DB", Style: 1},
{Type: "right", Color: "D1D5DB", Style: 1},
},
numberStyle, err := file.NewStyle(&excelize.Style{
Alignment: &excelize.Alignment{Horizontal: "right", Vertical: "center"},
Border: border,
})
if err != nil {
return err
}
if err := file.SetCellStyle(sheet, "K2", "O"+lastRowStr, numberStyle); err != nil {
return err
}
return file.SetCellStyle(sheet, "E2", "E"+strconv.Itoa(lastRow), moneyStyle)
centerStyle, err := file.NewStyle(&excelize.Style{
Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
Border: border,
})
if err != nil {
return err
}
for _, col := range []string{"G", "H", "J"} {
if err := file.SetCellStyle(sheet, col+"2", col+lastRowStr, centerStyle); err != nil {
return err
}
}
return nil
}
func formatMarketingExportDate(value time.Time) string {
@@ -225,36 +327,6 @@ func formatMarketingExportStatus(item dto.MarketingListDTO) string {
return safeMarketingExportText(item.LatestApproval.StepName)
}
func formatMarketingProducts(items []dto.DeliveryMarketingProductDTO) string {
if len(items) == 0 {
return "-"
}
seen := make(map[string]struct{})
names := make([]string, 0, len(items))
for _, item := range items {
if item.ProductWarehouse == nil || item.ProductWarehouse.Product == nil {
continue
}
name := strings.TrimSpace(item.ProductWarehouse.Product.Name)
if name == "" {
continue
}
if _, exists := seen[name]; exists {
continue
}
seen[name] = struct{}{}
names = append(names, name)
}
if len(names) == 0 {
return "-"
}
return strings.Join(names, ", ")
}
func sumMarketingGrandTotal(items []dto.DeliveryMarketingProductDTO) float64 {
total := 0.0
@@ -29,6 +29,7 @@ type MarketingListDTO struct {
SalesPerson userDTO.UserRelationDTO `json:"sales_person"`
SoDocs string `json:"so_docs"`
SalesOrder []DeliveryMarketingProductDTO `json:"sales_order"`
DeliveryOrder []DeliveryGroupDTO `json:"delivery_order"`
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
@@ -203,6 +204,7 @@ func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.M
SalesPerson: salesPerson,
SoDocs: marketing.SoDocs,
SalesOrder: salesOrderProducts,
DeliveryOrder: extractDeliveryGroupsFromProducts(marketing),
CreatedUser: createdUser,
CreatedAt: marketing.CreatedAt,
UpdatedAt: marketing.UpdatedAt,
@@ -376,6 +378,23 @@ func GenerateDeliveryOrderNumber(soNumber string, deliveryDate *time.Time, wareh
return numberPrefix
}
func extractDeliveryGroupsFromProducts(marketing *entity.Marketing) []DeliveryGroupDTO {
var dps []MarketingDeliveryProductDTO
for _, product := range marketing.Products {
if product.DeliveryProduct == nil || product.DeliveryProduct.DeliveryDate == nil {
continue
}
dp := ToMarketingDeliveryProductDTO(*product.DeliveryProduct)
if product.ProductWarehouse.Id != 0 {
mapped := productwarehouseDTO.ToProductWarehouseNestedDTO(product.ProductWarehouse)
dp.ProductWarehouse = &mapped
}
dp.ConvertionUnit = product.ConvertionUnit
dps = append(dps, dp)
}
return groupDeliveryProducts(dps, marketing.SoNumber)
}
func collectDoNumbers(marketing *entity.Marketing) []string {
if marketing == nil || len(marketing.Products) == 0 {
return nil