add restrict for expense,purchase,adjustment transfer: unfinished

This commit is contained in:
ragilap
2025-12-09 15:16:01 +07:00
parent 7094d90034
commit 0fbf04fc1d
18 changed files with 681 additions and 395 deletions
@@ -14,6 +14,7 @@ import (
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
expenseRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/repositories"
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
kandangRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/repositories"
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/validations"
repository "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
@@ -26,6 +27,7 @@ type ProjectFlockKandangService interface {
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, error)
CheckClosing(ctx *fiber.Ctx, id uint) (*ClosingCheckResult, error)
Closing(ctx *fiber.Ctx, id uint, req *validation.Closing) (*entity.ProjectFlockKandang, error)
GetProjectFlockKandangClosingDate(c *fiber.Ctx, id uint) (*time.Time, error)
}
type projectFlockKandangService struct {
@@ -37,6 +39,7 @@ type projectFlockKandangService struct {
WarehouseRepo rWarehouse.WarehouseRepository
ProductWarehouseRepo rProductWarehouse.ProductWarehouseRepository
PopulationRepo repository.ProjectFlockPopulationRepository
KandangRepo kandangRepo.KandangRepository
}
type ClosingCheckResult struct {
@@ -66,7 +69,7 @@ type ExpenseSummary struct {
Reference string `json:"reference_number"`
}
func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository, approvalSvc commonSvc.ApprovalService, expenseRepo expenseRepo.ExpenseRepository, warehouseRepo rWarehouse.WarehouseRepository, productWarehouseRepo rProductWarehouse.ProductWarehouseRepository, populationRepo repository.ProjectFlockPopulationRepository, validate *validator.Validate) ProjectFlockKandangService {
func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository, approvalSvc commonSvc.ApprovalService, expenseRepo expenseRepo.ExpenseRepository, warehouseRepo rWarehouse.WarehouseRepository, productWarehouseRepo rProductWarehouse.ProductWarehouseRepository, populationRepo repository.ProjectFlockPopulationRepository, kandangRepo kandangRepo.KandangRepository, validate *validator.Validate) ProjectFlockKandangService {
return &projectFlockKandangService{
Log: utils.Log,
Validate: validate,
@@ -76,6 +79,7 @@ func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository
WarehouseRepo: warehouseRepo,
ProductWarehouseRepo: productWarehouseRepo,
PopulationRepo: populationRepo,
KandangRepo: kandangRepo,
}
}
@@ -321,7 +325,7 @@ func (s projectFlockKandangService) CheckClosing(c *fiber.Ctx, id uint) (*Closin
}
// getProjectFlockKandangClosingDate mengembalikan tanggal closing PFK jika sudah di-close.
func (s projectFlockKandangService) getProjectFlockKandangClosingDate(c *fiber.Ctx, id uint) (*time.Time, error) {
func (s projectFlockKandangService) GetProjectFlockKandangClosingDate(c *fiber.Ctx, id uint) (*time.Time, error) {
if id == 0 {
return nil, nil
}
@@ -417,6 +421,15 @@ func (s projectFlockKandangService) Closing(c *fiber.Ctx, id uint, req *validati
if err := s.Repository.UpdateClosedAt(c.Context(), id, &closeTime); err != nil {
return nil, err
}
if s.KandangRepo != nil {
if err := s.KandangRepo.UpdateStatusByIDs(
c.Context(),
[]uint{pfk.KandangId},
utils.KandangStatusNonActive,
); err != nil {
return nil, err
}
}
if s.ApprovalSvc != nil {
closeAction := entity.ApprovalActionApproved
if _, aerr := s.ApprovalSvc.CreateApproval(
@@ -477,6 +490,15 @@ func (s projectFlockKandangService) Closing(c *fiber.Ctx, id uint, req *validati
if err := s.Repository.UpdateClosedAt(c.Context(), id, nil); err != nil {
return nil, err
}
if s.KandangRepo != nil {
if err := s.KandangRepo.UpdateStatusByIDs(
c.Context(),
[]uint{pfk.KandangId},
utils.KandangStatusActive,
); err != nil {
return nil, err
}
}
default:
return nil, fiber.NewError(fiber.StatusBadRequest, "action harus close atau unclose")
}