diff --git a/internal/modules/production/chickins/services/chickin.service.go b/internal/modules/production/chickins/services/chickin.service.go index 5ba665ca..9784ef8a 100644 --- a/internal/modules/production/chickins/services/chickin.service.go +++ b/internal/modules/production/chickins/services/chickin.service.go @@ -572,6 +572,7 @@ func (s *chickinService) convertChickinsToTarget(ctx *fiber.Ctx, chickins []enti } ProjectFlockPopulationRepotx := s.ProjectflockPopulationRepo.WithTx(dbTransaction) + chickinRepoTx := s.Repository.WithTx(dbTransaction) var totalQuantityAdded float64 @@ -601,6 +602,13 @@ func (s *chickinService) convertChickinsToTarget(ctx *fiber.Ctx, chickins []enti return err } + // Reset PendingUsageQty to 0 since population has been created + if err := chickinRepoTx.PatchOne(ctx.Context(), chickin.Id, map[string]any{ + "pending_usage_qty": 0, + }, nil); err != nil { + return fmt.Errorf("failed to reset pending usage qty for chickin %d: %w", chickin.Id, err) + } + totalQuantityAdded += quantityToConvert } diff --git a/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go b/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go index a2ba8ad2..58f04f1b 100644 --- a/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go +++ b/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go @@ -204,6 +204,11 @@ func toAvailableQtyDTOsFromMap(chickins []entity.ProjectChickin, availableQtyMap result := make([]AvailableQtyDTO, 0, len(availableQtyMap)) for pwId, availableQty := range availableQtyMap { + // Skip jika available qty = 0 + if availableQty <= 0 { + continue + } + pw, exists := pwMap[pwId] if !exists || pw == nil { continue