Feat[BE]: implement FIFO stock management for marketing delivery products, including migration scripts and updates to related services and DTOs

This commit is contained in:
aguhh18
2025-12-26 19:02:50 +07:00
parent 54487b0fcf
commit cd14de4dd2
16 changed files with 290 additions and 72 deletions
@@ -64,7 +64,7 @@ func ToSalesDTO(e entity.MarketingDeliveryProduct) SalesDTO {
DoNumber: doNumber,
Product: product,
Customer: customer,
Qty: e.Qty,
Qty: e.UsageQty, // Show allocated quantity from FIFO
Weight: e.TotalWeight,
AvgWeight: e.AvgWeight,
Price: e.UnitPrice,
@@ -712,13 +712,13 @@ func (s closingService) calculateAverageSalesAge(ctx context.Context, projectFlo
)
for _, product := range deliveryProducts {
if product.Qty == 0 {
if product.UsageQty == 0 {
continue
}
projectFlockKandang := product.MarketingProduct.ProductWarehouse.ProjectFlockKandang
ageWeeks := dto.CalculateAgeFromChickinDataProduksi(projectFlockKandang, product.DeliveryDate)
totalAgeWeeks += float64(ageWeeks) * product.Qty
totalQty += product.Qty
totalAgeWeeks += float64(ageWeeks) * product.UsageQty
totalQty += product.UsageQty
}
if totalQty == 0 {