From 8900937e711f656da313d6511666df3eae8fec86 Mon Sep 17 00:00:00 2001 From: giovanni Date: Tue, 5 May 2026 16:38:37 +0700 Subject: [PATCH] fix woa at hasil produksi --- .../modules/repports/services/repport.service.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/modules/repports/services/repport.service.go b/internal/modules/repports/services/repport.service.go index 02bfdf5a..54af581d 100644 --- a/internal/modules/repports/services/repport.service.go +++ b/internal/modules/repports/services/repport.service.go @@ -882,8 +882,6 @@ func (s *repportService) GetProductionResult(ctx *fiber.Ctx, params *validation. defaultBw = 0 defaultUniformText = "90% up" ) - defaultStartWoa := config.LayingWeekStart() - if params.Limit <= 0 { params.Limit = 10 } @@ -933,7 +931,7 @@ func (s *repportService) GetProductionResult(ctx *fiber.Ctx, params *validation. weeks := make([]int, len(weeklyResults)) for i := range weeklyResults { - weeks[i] = defaultStartWoa + i + weeks[i] = int(weeklyResults[i].Woa) } uniformityMap, err := s.getUniformityByWeek(ctx.Context(), params.ProjectFlockKandangID, weeks) if err != nil { @@ -943,13 +941,12 @@ func (s *repportService) GetProductionResult(ctx *fiber.Ctx, params *validation. var cumulativeButir int64 var cumulativeKg float64 for i := range weeklyResults { - weeklyResults[i].Woa = float64(defaultStartWoa + i) weeklyResults[i].StdBw = defaultStdBw weeklyResults[i].Bw = defaultBw if weeklyResults[i].StdUniformity == "" { weeklyResults[i].StdUniformity = defaultUniformText } - if uniformity, ok := uniformityMap[defaultStartWoa+i]; ok { + if uniformity, ok := uniformityMap[int(weeklyResults[i].Woa)]; ok { weeklyResults[i].Uniformity = uniformity.Uniformity if uniformity.AvgWeight != nil { weeklyResults[i].Bw = *uniformity.AvgWeight @@ -1356,8 +1353,8 @@ func mapRecordingToProductionResultDTO(record entity.Recording) dto.ProductionRe Ew: valueOrZero(record.EggWeight), } - if record.Day != nil { - result.Woa = float64(*record.Day) + if record.Day != nil && *record.Day > 0 { + result.Woa = float64((*record.Day + 6) / 7) // ceil(day/7) } avgWeight := 1.0 if avgWeight > 0 { @@ -1588,6 +1585,7 @@ func aggregateProductionResultGroup(group []dto.ProductionResultDTO, groupSize i CreatedAt: group[0].CreatedAt, UpdatedAt: group[0].UpdatedAt, StdUniformity: group[0].StdUniformity, + Woa: group[0].Woa, } var sumBw, sumStdBw, sumUniformity float64