mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): fix report closing keuangan duplicate ovk, and closing keuangan devided by last recording
This commit is contained in:
@@ -294,6 +294,9 @@ func (s closingKeuanganService) calculateProductionData(c *fiber.Ctx, projectFlo
|
||||
func (s closingKeuanganService) buildHPPSection(c *fiber.Ctx, projectFlock *entity.ProjectFlock, projectFlockKandangs []entity.ProjectFlockKandang, costs *CostData, production *ProductionData) dto.HPPSection {
|
||||
|
||||
actualPopulation := production.TotalPopulationIn - production.TotalDepletion
|
||||
if lastPopulation, ok := s.getLastPopulationFromRecordings(c, projectFlockKandangs); ok {
|
||||
actualPopulation = lastPopulation
|
||||
}
|
||||
totalWeightProduced := production.TotalWeightProduced
|
||||
totalEggWeightKg := production.TotalEggWeightKg
|
||||
|
||||
@@ -529,6 +532,35 @@ func (s closingKeuanganService) buildProfitLossSection(projectFlock *entity.Proj
|
||||
return dto.ToProfitLossSection(plItems, plSummary)
|
||||
}
|
||||
|
||||
func (s closingKeuanganService) getLastPopulationFromRecordings(c *fiber.Ctx, projectFlockKandangs []entity.ProjectFlockKandang) (float64, bool) {
|
||||
if s.RecordingRepo == nil || len(projectFlockKandangs) == 0 {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
total := 0.0
|
||||
recordedCount := 0
|
||||
for _, kandang := range projectFlockKandangs {
|
||||
latest, err := s.RecordingRepo.GetLatestByProjectFlockKandangID(c.Context(), kandang.Id)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to fetch latest recording for project_flock_kandang_id=%d: %+v", kandang.Id, err)
|
||||
return 0, false
|
||||
}
|
||||
if latest == nil || latest.TotalChickQty == nil {
|
||||
continue
|
||||
}
|
||||
recordedCount++
|
||||
if *latest.TotalChickQty > 0 {
|
||||
total += *latest.TotalChickQty
|
||||
}
|
||||
}
|
||||
|
||||
if recordedCount != len(projectFlockKandangs) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return total, true
|
||||
}
|
||||
|
||||
func containsFlag(flags []entity.Flag, name string) bool {
|
||||
for _, flag := range flags {
|
||||
if flag.Name == name {
|
||||
|
||||
Reference in New Issue
Block a user