From 8c58cc41036760a4a3084a0a67d56fa625f726e2 Mon Sep 17 00:00:00 2001 From: ragilap Date: Thu, 22 Jan 2026 17:49:46 +0700 Subject: [PATCH 1/3] [FIX/BE-US] fix uniformity relation chickin date --- .../production/uniformities/services/uniformity.service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/modules/production/uniformities/services/uniformity.service.go b/internal/modules/production/uniformities/services/uniformity.service.go index 41611ac3..79e4d3e7 100644 --- a/internal/modules/production/uniformities/services/uniformity.service.go +++ b/internal/modules/production/uniformities/services/uniformity.service.go @@ -375,7 +375,7 @@ func (s *uniformityService) CreateOne(c *fiber.Ctx, req *validation.Create, file var latestWeek int if err := s.Repository.DB().WithContext(c.Context()). Model(&entity.ProjectFlockKandangUniformity{}). - Where("project_flock_kandang_id = ? AND deleted_at IS NULL", req.ProjectFlockKandangId). + Where("project_flock_kandang_id = ?", req.ProjectFlockKandangId). Select("COALESCE(MAX(week), 0)"). Scan(&latestWeek).Error; err != nil { return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate uniformity week sequence") From 9928b4c97065a2aeff70eb5c80d574f5f5bdeb8a Mon Sep 17 00:00:00 2001 From: ragilap Date: Thu, 22 Jan 2026 17:50:04 +0700 Subject: [PATCH 2/3] [FIX/BE-US] fix uniformity relation chickin date --- .../controllers/projectflock.controller.go | 5 +++ .../dto/projectflock_kandang.dto.go | 3 ++ .../services/projectflock.service.go | 31 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/internal/modules/production/project_flocks/controllers/projectflock.controller.go b/internal/modules/production/project_flocks/controllers/projectflock.controller.go index e82d3af5..8c5a9298 100644 --- a/internal/modules/production/project_flocks/controllers/projectflock.controller.go +++ b/internal/modules/production/project_flocks/controllers/projectflock.controller.go @@ -287,6 +287,11 @@ func (u *ProjectflockController) LookupProjectFlockKandang(c *fiber.Ctx) error { } else { dtoResult.AvailableQuantity = population } + if chickinDate, err := u.ProjectflockService.GetProjectFlockKandangChickinDate(c, result.Id); err != nil { + return err + } else if chickinDate != nil { + dtoResult.ChickInDate = chickinDate + } if warehouse, werr := u.ProjectflockService.GetWarehouseByKandangID(c, result.KandangId); werr != nil { return werr } else if warehouse != nil { diff --git a/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go b/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go index c18f3f65..39abfe62 100644 --- a/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go +++ b/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go @@ -1,6 +1,8 @@ package dto import ( + "time" + entity "gitlab.com/mbugroup/lti-api.git/internal/entities" areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto" fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto" @@ -38,6 +40,7 @@ type ProjectFlockKandangDTO struct { ProjectFlock *ProjectFlockWithPivotDTO `json:"project_flock,omitempty"` AvailableQuantity float64 `json:"available_quantity"` Population *float64 `json:"population,omitempty"` + ChickInDate *time.Time `json:"chick_in_date,omitempty"` } func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangDTO { diff --git a/internal/modules/production/project_flocks/services/projectflock.service.go b/internal/modules/production/project_flocks/services/projectflock.service.go index 05e21894..21925a24 100644 --- a/internal/modules/production/project_flocks/services/projectflock.service.go +++ b/internal/modules/production/project_flocks/services/projectflock.service.go @@ -6,6 +6,7 @@ import ( "fmt" "strconv" "strings" + "time" commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository" commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service" @@ -42,6 +43,7 @@ type ProjectflockService interface { DeleteOne(ctx *fiber.Ctx, id uint) error GetProjectFlockKandangByProjectAndKandang(ctx *fiber.Ctx, projectFlockID uint, kandangID uint) (*entity.ProjectFlockKandang, float64, error) GetProjectFlockKandangPopulation(ctx *fiber.Ctx, projectFlockKandangID uint) (float64, error) + GetProjectFlockKandangChickinDate(ctx *fiber.Ctx, projectFlockKandangID uint) (*time.Time, error) GetPeriodSummary(ctx *fiber.Ctx, locationID uint) ([]KandangPeriodSummary, error) GetProjectPeriods(ctx *fiber.Ctx, projectIDs []uint) (map[uint]int, error) Approval(ctx *fiber.Ctx, req *validation.Approve) ([]entity.ProjectFlock, error) @@ -459,6 +461,35 @@ func (s projectflockService) GetProjectFlockKandangPopulation(ctx *fiber.Ctx, pr return total, nil } +func (s projectflockService) GetProjectFlockKandangChickinDate(ctx *fiber.Ctx, projectFlockKandangID uint) (*time.Time, error) { + if s.PopulationRepo == nil { + return nil, fiber.NewError(fiber.StatusInternalServerError, "Project flock population repository is not configured") + } + if projectFlockKandangID == 0 { + return nil, fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required") + } + + populations, err := s.PopulationRepo.GetByProjectFlockKandangID(ctx.Context(), projectFlockKandangID) + if err != nil { + s.Log.Errorf("Failed to fetch populations for project flock kandang %d: %+v", projectFlockKandangID, err) + return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandang chick in date") + } + + var earliest *time.Time + for _, pop := range populations { + if pop.ProjectChickin == nil || pop.ProjectChickin.ChickInDate.IsZero() { + continue + } + chickinDate := pop.ProjectChickin.ChickInDate + if earliest == nil || chickinDate.Before(*earliest) { + copy := chickinDate + earliest = © + } + } + + return earliest, nil +} + func (s projectflockService) GetProjectFlockKandangByParams(ctx *fiber.Ctx, idStr string, projectFlockIdStr string, kandangIdStr string) (*entity.ProjectFlockKandang, float64, error) { idStr = strings.TrimSpace(idStr) projectFlockIdStr = strings.TrimSpace(projectFlockIdStr) From f82ac01e7c54d46e4c6b3b45a6fbe1bff57a53ce Mon Sep 17 00:00:00 2001 From: ragilap Date: Fri, 23 Jan 2026 12:02:26 +0700 Subject: [PATCH 3/3] [FIX/BE-US] fix recording date --- .../recordings/controllers/recording.controller.go | 13 ++++++++++++- .../recordings/services/recording.service.go | 11 +++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/modules/production/recordings/controllers/recording.controller.go b/internal/modules/production/recordings/controllers/recording.controller.go index 7edb7b9a..51e3100d 100644 --- a/internal/modules/production/recordings/controllers/recording.controller.go +++ b/internal/modules/production/recordings/controllers/recording.controller.go @@ -3,6 +3,8 @@ package controller import ( "math" "strconv" + "strings" + "time" "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/dto" service "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/services" @@ -82,7 +84,16 @@ func (u *RecordingController) GetNextDay(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required") } - nextDay, err := u.RecordingService.GetNextDay(c, uint(projectFlockID)) + recordTime := time.Now().UTC() + if recordDate := strings.TrimSpace(c.Query("record_date")); recordDate != "" { + parsed, err := time.Parse("2006-01-02", recordDate) + if err != nil { + return fiber.NewError(fiber.StatusBadRequest, "record_date must be in YYYY-MM-DD format") + } + recordTime = parsed.UTC() + } + + nextDay, err := u.RecordingService.GetNextDay(c, uint(projectFlockID), recordTime) if err != nil { return err } diff --git a/internal/modules/production/recordings/services/recording.service.go b/internal/modules/production/recordings/services/recording.service.go index b408995f..d490185d 100644 --- a/internal/modules/production/recordings/services/recording.service.go +++ b/internal/modules/production/recordings/services/recording.service.go @@ -13,8 +13,8 @@ import ( sProductionStandard "gitlab.com/mbugroup/lti-api.git/internal/modules/master/production-standards/services" rProjectFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories" repository "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/repositories" - rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories" validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/validations" + rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories" "gitlab.com/mbugroup/lti-api.git/internal/utils" approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals" "gitlab.com/mbugroup/lti-api.git/internal/utils/fifo" @@ -32,7 +32,7 @@ import ( type RecordingService interface { GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.Recording, int64, error) GetOne(ctx *fiber.Ctx, id uint) (*entity.Recording, error) - GetNextDay(ctx *fiber.Ctx, projectFlockKandangId uint) (int, error) + GetNextDay(ctx *fiber.Ctx, projectFlockKandangId uint, recordTime time.Time) (int, error) CreateOne(ctx *fiber.Ctx, req *validation.Create) (*entity.Recording, error) UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint) (*entity.Recording, error) DeleteOne(ctx *fiber.Ctx, id uint) error @@ -160,12 +160,15 @@ func (s recordingService) GetOne(c *fiber.Ctx, id uint) (*entity.Recording, erro return recording, nil } -func (s recordingService) GetNextDay(c *fiber.Ctx, projectFlockKandangId uint) (int, error) { +func (s recordingService) GetNextDay(c *fiber.Ctx, projectFlockKandangId uint, recordTime time.Time) (int, error) { if projectFlockKandangId == 0 { return 0, fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required") } - day, err := s.computeRecordingDay(c.Context(), projectFlockKandangId, time.Now().UTC()) + if recordTime.IsZero() { + recordTime = time.Now().UTC() + } + day, err := s.computeRecordingDay(c.Context(), projectFlockKandangId, recordTime) if err != nil { s.Log.Errorf("Failed to compute recording day for project_flock_kandang_id=%d: %+v", projectFlockKandangId, err) return 0, err