diff --git a/internal/modules/production/chickins/services/chickin.service.go b/internal/modules/production/chickins/services/chickin.service.go index 3a342646..33651482 100644 --- a/internal/modules/production/chickins/services/chickin.service.go +++ b/internal/modules/production/chickins/services/chickin.service.go @@ -37,6 +37,7 @@ import ( const ( chickinDeletePopulationGuardMessage = "Chickin tidak dapat dihapus karena masih memiliki population aktif" chickinDeleteDownstreamGuardMessage = "Chickin tidak bisa dihapus karena masih dipakai oleh transaksi turunan. Hapus/unexecute Marketing, Recording, Transfer, Adjustment, dan Transfer to Laying terlebih dahulu." + chickinAdjustmentSourceTable = "adjustment_stocks" ) type ChickinService interface { @@ -577,7 +578,7 @@ func (s *chickinService) resolveLayingSourceAvailableQty(ctx context.Context, tx Lane: commonSvc.FifoStockV2Lane("STOCKABLE"), AllocationPurpose: entity.StockAllocationPurposeConsume, ProductWarehouseID: productWarehouseID, - AsOf: asOf, + AsOf: nil, Limit: 10000, Tx: tx, }) @@ -586,10 +587,16 @@ func (s *chickinService) resolveLayingSourceAvailableQty(ctx context.Context, tx } available := 0.0 + hasAsOf := asOf != nil && !asOf.IsZero() for _, row := range gatherRows { if row.AvailableQuantity <= 0 { continue } + if hasAsOf && + !strings.EqualFold(strings.TrimSpace(row.SourceTable), chickinAdjustmentSourceTable) && + row.SortAt.After(*asOf) { + continue + } available += row.AvailableQuantity } return available, nil