Merge branch 'fix/hppv2-egg-production-double-count' into 'development'

Fix/hppv2 egg production double count

See merge request mbugroup/lti-api!463
This commit is contained in:
Adnan Zahir
2026-04-24 03:22:56 +07:00
@@ -878,6 +878,25 @@ func (r *HppV2RepositoryImpl) GetEggProduksiPiecesAndWeightKgByProjectFlockKanda
return 0, 0, err
}
var adjustmentTotals struct {
TotalQty float64
TotalWeight float64
}
err = r.db.WithContext(ctx).
Table("adjustment_stocks AS ast").
Select("COALESCE(SUM(ast.total_qty), 0) AS total_qty, COALESCE(SUM(ast.price), 0) AS total_weight").
Joins("JOIN product_warehouses AS pw ON pw.id = ast.product_warehouse_id").
Where("pw.project_flock_kandang_id IN (?)", projectFlockKandangIDs).
Where("ast.function_code = ?", string(utils.AdjustmentTransactionSubtypeRecordingEggIn)).
Where("ast.created_at <= ?", *date).
Scan(&adjustmentTotals).Error
if err != nil {
return 0, 0, err
}
totals.TotalPieces += adjustmentTotals.TotalQty
totals.TotalWeightKg += adjustmentTotals.TotalWeight
return totals.TotalPieces, totals.TotalWeightKg, nil
}