From 6b4eb758e4cf6726471e46095fefbc1efe65db84 Mon Sep 17 00:00:00 2001 From: aguhh18 Date: Fri, 23 Jan 2026 10:32:40 +0700 Subject: [PATCH] FIX[BE]: fixing umur on closing penjualan for penjualan OVK and PAKAN --- .../modules/closings/dto/closingMarketing.dto.go | 15 +++++++++++++-- .../marketing/services/salesorder.service.go | 3 --- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/modules/closings/dto/closingMarketing.dto.go b/internal/modules/closings/dto/closingMarketing.dto.go index d725b430..72523b69 100644 --- a/internal/modules/closings/dto/closingMarketing.dto.go +++ b/internal/modules/closings/dto/closingMarketing.dto.go @@ -44,7 +44,12 @@ type PenjualanRealisasiResponseDTO struct { func ToSalesDTO(e entity.MarketingDeliveryProduct) SalesDTO { - ageInDay, ageInWeeks := calculateAgeFromChickin(e.MarketingProduct.ProductWarehouse.ProjectFlockKandang, e.DeliveryDate) + productFlags := make([]string, len(e.MarketingProduct.ProductWarehouse.Product.Flags)) + for i, f := range e.MarketingProduct.ProductWarehouse.Product.Flags { + productFlags[i] = f.Name + } + + ageInDay, ageInWeeks := calculateAgeFromChickin(e.MarketingProduct.ProductWarehouse.ProjectFlockKandang, e.DeliveryDate, productFlags) var product *productDTO.ProductRelationDTO if e.MarketingProduct.ProductWarehouse.Product.Id != 0 { @@ -126,11 +131,17 @@ func ToPenjualanRealisasiResponseDTO(e []entity.MarketingDeliveryProduct) Penjua } } -func calculateAgeFromChickin(projectFlockKandang *entity.ProjectFlockKandang, deliveryDate *time.Time) (int, int) { +func calculateAgeFromChickin(projectFlockKandang *entity.ProjectFlockKandang, deliveryDate *time.Time, productFlags []string) (int, int) { if projectFlockKandang == nil || deliveryDate == nil || len(projectFlockKandang.Chickins) == 0 { return 0, 0 } + for _, flag := range productFlags { + if flag == "OVK" || flag == "PAKAN" { + return 0, 0 // + } + } + earliestChickinDate := projectFlockKandang.Chickins[0].ChickInDate for _, chickin := range projectFlockKandang.Chickins { if chickin.ChickInDate.Before(earliestChickinDate) { diff --git a/internal/modules/marketing/services/salesorder.service.go b/internal/modules/marketing/services/salesorder.service.go index e2cfcabb..dbf99219 100644 --- a/internal/modules/marketing/services/salesorder.service.go +++ b/internal/modules/marketing/services/salesorder.service.go @@ -311,14 +311,11 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u } } - // Hitung total_weight dan total_price berdasarkan flag totalWeight := rp.Qty * rp.AvgWeight var totalPrice float64 if isPakanOrOVK { - // PAKAN atau OVK: qty × unit_price totalPrice = rp.Qty * rp.UnitPrice } else { - // Produk lain: total_weight × unit_price totalPrice = totalWeight * rp.UnitPrice }