add approval projectflockkandang closed,expense must be done,stock must empty by flag unfinished:need info approval fix

This commit is contained in:
ragilap
2025-12-03 21:46:02 +07:00
parent d572d04e3b
commit ea294c6a18
6 changed files with 47 additions and 8 deletions
@@ -2,6 +2,7 @@ package service
import (
"errors"
"fmt"
"strings"
"time"
@@ -219,6 +220,27 @@ func (s projectFlockKandangService) Closing(c *fiber.Ctx, id uint, req *validati
return nil, fiber.NewError(fiber.StatusBadRequest, "Masih ada expense belum selesai untuk kandang ini")
}
}
if s.WarehouseRepo != nil && s.ProductWarehouseRepo != nil {
warehouse, werr := s.WarehouseRepo.GetByKandangID(c.Context(), pfk.KandangId)
if werr != nil {
return nil, werr
}
for _, flagName := range []utils.FlagType{utils.FlagPakan, utils.FlagOVK} {
productWarehouses, pwErr := s.ProductWarehouseRepo.GetByFlagAndWarehouseID(c.Context(), string(flagName), warehouse.Id)
if pwErr != nil {
return nil, pwErr
}
for _, pw := range productWarehouses {
if pw.Quantity > 0 {
return nil, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Stok %s masih tersedia (product warehouse %d: %.2f)", flagName, pw.Id, pw.Quantity))
}
}
}
}
closeTime := now
if req.ClosedDate != nil {
parsed, perr := utils.ParseDateString(strings.TrimSpace(*req.ClosedDate))
@@ -236,7 +258,7 @@ func (s projectFlockKandangService) Closing(c *fiber.Ctx, id uint, req *validati
c.Context(),
utils.ApprovalWorkflowProjectFlockKandang,
id,
utils.ProjectFlockKandangStepDisetujui,
utils.ProjectFlockKandangStepClosed,
&closeAction,
actorID,
nil,