mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
102 lines
4.1 KiB
Go
102 lines
4.1 KiB
Go
package transfer_layings
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
"github.com/gofiber/fiber/v2"
|
|
"gorm.io/gorm"
|
|
|
|
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
|
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/utils/fifo"
|
|
rProjectFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
|
rTransferLaying "gitlab.com/mbugroup/lti-api.git/internal/modules/production/transfer_layings/repositories"
|
|
sTransferLaying "gitlab.com/mbugroup/lti-api.git/internal/modules/production/transfer_layings/services"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
|
|
|
rInventory "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
|
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
|
|
rUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/repositories"
|
|
sUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
|
|
)
|
|
|
|
type TransferLayingModule struct{}
|
|
|
|
func (TransferLayingModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
|
|
transferLayingRepo := rTransferLaying.NewTransferLayingRepository(db)
|
|
layingTransferSourceRepo := rTransferLaying.NewLayingTransferSourceRepository(db)
|
|
layingTransferTargetRepo := rTransferLaying.NewLayingTransferTargetRepository(db)
|
|
userRepo := rUser.NewUserRepository(db)
|
|
projectFlockRepo := rProjectFlock.NewProjectflockRepository(db)
|
|
projectFlockKandangRepo := rProjectFlock.NewProjectFlockKandangRepository(db)
|
|
projectFlockPopulationRepo := rProjectFlock.NewProjectFlockPopulationRepository(db)
|
|
productWarehouseRepo := rInventory.NewProductWarehouseRepository(db)
|
|
warehouseRepo := rWarehouse.NewWarehouseRepository(db)
|
|
|
|
stockAllocationRepo := commonRepo.NewStockAllocationRepository(db)
|
|
fifoService := commonSvc.NewFifoService(db, stockAllocationRepo, productWarehouseRepo, utils.Log)
|
|
fifoStockV2Service := commonSvc.NewFifoStockV2Service(db, utils.Log)
|
|
|
|
// daftarin jadi stockable
|
|
if err := fifoService.RegisterStockable(fifo.StockableConfig{
|
|
Key: fifo.StockableKeyTransferToLayingIn,
|
|
Table: "laying_transfer_targets",
|
|
Columns: fifo.StockableColumns{
|
|
ID: "id",
|
|
ProductWarehouseID: "product_warehouse_id",
|
|
TotalQuantity: "total_qty",
|
|
TotalUsedQuantity: "total_used",
|
|
CreatedAt: "created_at",
|
|
},
|
|
OrderBy: []string{"created_at ASC", "id ASC"},
|
|
}); err != nil {
|
|
if !strings.Contains(strings.ToLower(err.Error()), "already registered") {
|
|
panic(fmt.Sprintf("failed to register transfer to laying stockable workflow: %v", err))
|
|
}
|
|
}
|
|
|
|
// daftarin jadi usable
|
|
if err := fifoService.RegisterUsable(fifo.UsableConfig{
|
|
Key: fifo.UsableKeyTransferToLayingOut,
|
|
Table: "laying_transfer_sources",
|
|
Columns: fifo.UsableColumns{
|
|
ID: "id",
|
|
ProductWarehouseID: "product_warehouse_id",
|
|
UsageQuantity: "usage_qty",
|
|
PendingQuantity: "pending_usage_qty",
|
|
CreatedAt: "created_at",
|
|
},
|
|
OrderBy: []string{"created_at ASC", "id ASC"},
|
|
}); err != nil {
|
|
if !strings.Contains(strings.ToLower(err.Error()), "already registered") {
|
|
panic(fmt.Sprintf("failed to register transfer to laying usable workflow: %v", err))
|
|
}
|
|
}
|
|
|
|
approvalRepo := commonRepo.NewApprovalRepository(db)
|
|
approvalService := commonSvc.NewApprovalService(approvalRepo)
|
|
if err := approvalService.RegisterWorkflowSteps(utils.ApprovalWorkflowTransferToLaying, utils.TransferToLayingApprovalSteps); err != nil {
|
|
panic(fmt.Sprintf("failed to register transfer to laying approval workflow: %v", err))
|
|
}
|
|
|
|
transferLayingService := sTransferLaying.NewTransferLayingService(
|
|
transferLayingRepo,
|
|
layingTransferSourceRepo,
|
|
layingTransferTargetRepo,
|
|
projectFlockRepo,
|
|
projectFlockKandangRepo,
|
|
projectFlockPopulationRepo,
|
|
productWarehouseRepo,
|
|
warehouseRepo,
|
|
approvalService,
|
|
fifoService,
|
|
fifoStockV2Service,
|
|
validate,
|
|
)
|
|
userService := sUser.NewUserService(userRepo, validate)
|
|
|
|
TransferLayingRoutes(router, userService, transferLayingService)
|
|
}
|