mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FEAT/BE] fix status closed project flock, closing perhitungan sapronak
This commit is contained in:
@@ -317,6 +317,27 @@ func ToSapronakProjectAggregatedFromReport(report *SapronakReportDTO, flag strin
|
||||
}
|
||||
}
|
||||
|
||||
// For chicken categories, keep qty_used aligned with qty_in - qty_out.
|
||||
// Sales are excluded; usage represents remaining after transfers.
|
||||
adjustChicken := func(cat *SapronakCategoryDTO) {
|
||||
if cat == nil {
|
||||
return
|
||||
}
|
||||
for i := range cat.Rows {
|
||||
row := &cat.Rows[i]
|
||||
remaining := row.QtyIn - row.QtyOut
|
||||
if remaining < 0 {
|
||||
remaining = 0
|
||||
}
|
||||
row.QtyUsed = remaining
|
||||
if row.UnitPrice > 0 {
|
||||
row.TotalAmount = row.QtyUsed * row.UnitPrice
|
||||
}
|
||||
}
|
||||
}
|
||||
adjustChicken(result.Doc)
|
||||
adjustChicken(result.Pullet)
|
||||
|
||||
buildTotals := func(cat *SapronakCategoryDTO, label string) {
|
||||
if cat == nil {
|
||||
return
|
||||
@@ -345,5 +366,22 @@ func ToSapronakProjectAggregatedFromReport(report *SapronakReportDTO, flag strin
|
||||
buildTotals(result.Doc, "TOTAL DOC")
|
||||
buildTotals(result.Ovk, "TOTAL OVK")
|
||||
buildTotals(result.Pakan, "TOTAL PAKAN")
|
||||
|
||||
// For chicken categories, enforce total qty_used = qty_in - qty_out.
|
||||
adjustChickenTotal := func(cat *SapronakCategoryDTO) {
|
||||
if cat == nil {
|
||||
return
|
||||
}
|
||||
remaining := cat.Total.QtyIn - cat.Total.QtyOut
|
||||
if remaining < 0 {
|
||||
remaining = 0
|
||||
}
|
||||
cat.Total.QtyUsed = remaining
|
||||
if cat.Total.AvgUnitPrice > 0 {
|
||||
cat.Total.TotalAmount = cat.Total.AvgUnitPrice * remaining
|
||||
}
|
||||
}
|
||||
adjustChickenTotal(result.Doc)
|
||||
adjustChickenTotal(result.Pullet)
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user