fix asof chickin adjustment

This commit is contained in:
ragilap
2026-03-25 12:42:05 +07:00
parent 325825a709
commit d226d5f7f3
@@ -37,6 +37,7 @@ import (
const ( const (
chickinDeletePopulationGuardMessage = "Chickin tidak dapat dihapus karena masih memiliki population aktif" 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." 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 { type ChickinService interface {
@@ -577,7 +578,7 @@ func (s *chickinService) resolveLayingSourceAvailableQty(ctx context.Context, tx
Lane: commonSvc.FifoStockV2Lane("STOCKABLE"), Lane: commonSvc.FifoStockV2Lane("STOCKABLE"),
AllocationPurpose: entity.StockAllocationPurposeConsume, AllocationPurpose: entity.StockAllocationPurposeConsume,
ProductWarehouseID: productWarehouseID, ProductWarehouseID: productWarehouseID,
AsOf: asOf, AsOf: nil,
Limit: 10000, Limit: 10000,
Tx: tx, Tx: tx,
}) })
@@ -586,10 +587,16 @@ func (s *chickinService) resolveLayingSourceAvailableQty(ctx context.Context, tx
} }
available := 0.0 available := 0.0
hasAsOf := asOf != nil && !asOf.IsZero()
for _, row := range gatherRows { for _, row := range gatherRows {
if row.AvailableQuantity <= 0 { if row.AvailableQuantity <= 0 {
continue continue
} }
if hasAsOf &&
!strings.EqualFold(strings.TrimSpace(row.SourceTable), chickinAdjustmentSourceTable) &&
row.SortAt.After(*asOf) {
continue
}
available += row.AvailableQuantity available += row.AvailableQuantity
} }
return available, nil return available, nil