diff --git a/internal/common/repository/common.stock_allocation.repository.go b/internal/common/repository/common.stock_allocation.repository.go index 38b1a93b..466fbe4a 100644 --- a/internal/common/repository/common.stock_allocation.repository.go +++ b/internal/common/repository/common.stock_allocation.repository.go @@ -63,13 +63,14 @@ func (r *StockAllocationRepositoryImpl) ReleaseByUsable( updates["note"] = *note } - q := r.DB().WithContext(ctx). + baseDB := r.DB() + if modifier != nil { + baseDB = modifier(baseDB) + } + + q := baseDB.WithContext(ctx). Model(&entity.StockAllocation{}). Where("usable_type = ? AND usable_id = ? AND status = ?", usableType, usableID, entity.StockAllocationStatusActive) - if modifier != nil { - q = modifier(q) - } - return q.Updates(updates).Error } diff --git a/internal/modules/production/project-flock-kandangs/services/project_flock_kandang.service.go b/internal/modules/production/project-flock-kandangs/services/project_flock_kandang.service.go index 883e64b0..87af4de1 100644 --- a/internal/modules/production/project-flock-kandangs/services/project_flock_kandang.service.go +++ b/internal/modules/production/project-flock-kandangs/services/project_flock_kandang.service.go @@ -499,6 +499,20 @@ func (s projectFlockKandangService) Closing(c *fiber.Ctx, id uint, req *validati return nil, err } } + if s.ApprovalSvc != nil { + reopenAction := entity.ApprovalActionApproved + if _, aerr := s.ApprovalSvc.CreateApproval( + c.Context(), + utils.ApprovalWorkflowProjectFlockKandang, + id, + utils.ProjectFlockKandangStepDisetujui, + &reopenAction, + actorID, + nil, + ); aerr != nil && !errors.Is(aerr, gorm.ErrDuplicatedKey) { + return nil, aerr + } + } default: return nil, fiber.NewError(fiber.StatusBadRequest, "action harus close atau unclose") }