mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
86 lines
3.3 KiB
Go
86 lines
3.3 KiB
Go
package adjustments
|
|
|
|
import (
|
|
"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"
|
|
rAdjustmentStock "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/adjustments/repositories"
|
|
sAdjustment "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/adjustments/services"
|
|
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
|
rproduct "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/repositories"
|
|
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
|
|
rProjectFlockKandang "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
|
rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories"
|
|
rUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/repositories"
|
|
sUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/utils/fifo"
|
|
)
|
|
|
|
type AdjustmentModule struct{}
|
|
|
|
func (AdjustmentModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
|
|
// Repositories
|
|
stockLogsRepo := rStockLogs.NewStockLogRepository(db)
|
|
warehouseRepo := rWarehouse.NewWarehouseRepository(db)
|
|
productWarehouseRepo := rProductWarehouse.NewProductWarehouseRepository(db)
|
|
projectFlockKandangRepo := rProjectFlockKandang.NewProjectFlockKandangRepository(db)
|
|
userRepo := rUser.NewUserRepository(db)
|
|
productRepo := rproduct.NewProductRepository(db)
|
|
adjustmentStockRepo := rAdjustmentStock.NewAdjustmentStockRepository(db)
|
|
stockAllocRepo := commonRepo.NewStockAllocationRepository(db)
|
|
|
|
fifoService := commonSvc.NewFifoService(db, stockAllocRepo, productWarehouseRepo, utils.Log)
|
|
fifoStockV2Service := commonSvc.NewFifoStockV2Service(db, utils.Log)
|
|
|
|
err := fifoService.RegisterStockable(fifo.StockableConfig{
|
|
Key: fifo.StockableKeyAdjustmentIn,
|
|
Table: "adjustment_stocks",
|
|
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"},
|
|
})
|
|
if err != nil {
|
|
panic("Failed to register ADJUSTMENT_IN as Stockable: " + err.Error())
|
|
}
|
|
|
|
err = fifoService.RegisterUsable(fifo.UsableConfig{
|
|
Key: fifo.UsableKeyAdjustmentOut,
|
|
Table: "adjustment_stocks",
|
|
Columns: fifo.UsableColumns{
|
|
ID: "id",
|
|
ProductWarehouseID: "product_warehouse_id",
|
|
UsageQuantity: "usage_qty",
|
|
PendingQuantity: "pending_qty",
|
|
CreatedAt: "created_at",
|
|
},
|
|
OrderBy: []string{"created_at ASC", "id ASC"},
|
|
})
|
|
if err != nil {
|
|
panic("Failed to register ADJUSTMENT_OUT as Usable: " + err.Error())
|
|
}
|
|
|
|
adjustmentService := sAdjustment.NewAdjustmentService(
|
|
productRepo,
|
|
stockLogsRepo,
|
|
warehouseRepo,
|
|
productWarehouseRepo,
|
|
adjustmentStockRepo,
|
|
fifoService,
|
|
fifoStockV2Service,
|
|
validate,
|
|
projectFlockKandangRepo,
|
|
)
|
|
userService := sUser.NewUserService(userRepo, validate)
|
|
|
|
AdjustmentRoutes(router, userService, adjustmentService)
|
|
}
|