mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
812db3f79e
- Added FIFO service integration in the adjustments module to manage stockable and usable items for adjustments. - Created a new repository for adjustment stocks to handle database operations. - Enhanced the adjustment service to track stock adjustments using FIFO logic for both increase and decrease operations. - Updated product warehouse DTOs and repositories to include project flock information. - Implemented FIFO logic in the transfer module to manage stock transfers between warehouses. - Added integration tests for FIFO operations in stock transfers, ensuring correct stock consumption and replenishment.
88 lines
3.8 KiB
Go
88 lines
3.8 KiB
Go
package transfers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
|
rStockTransfer "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/transfers/repositories"
|
|
sTransfer "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/transfers/services"
|
|
rSupplier "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/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 TransferModule struct{}
|
|
|
|
func (TransferModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
|
|
stockTransferRepo := rStockTransfer.NewStockTransferRepository(db)
|
|
stockTransferDetailRepo := rStockTransfer.NewStockTransferDetailRepository(db)
|
|
stockTransferDeliveryRepo := rStockTransfer.NewStockTransferDeliveryRepository(db)
|
|
StockTransferDeliveryItemRepo := rStockTransfer.NewStockTransferDeliveryItemRepository(db)
|
|
stockLogsRepo := rStockLogs.NewStockLogRepository(db)
|
|
supplierRepo := rSupplier.NewSupplierRepository(db)
|
|
productWarehouseRepo := rProductWarehouse.NewProductWarehouseRepository(db)
|
|
userRepo := rUser.NewUserRepository(db)
|
|
warehouseRepo := rWarehouse.NewWarehouseRepository(db)
|
|
projectFlockKandangRepo := rProjectFlockKandang.NewProjectFlockKandangRepository(db)
|
|
documentRepo := commonRepo.NewDocumentRepository(db)
|
|
stockAllocRepo := commonRepo.NewStockAllocationRepository(db)
|
|
|
|
documentSvc, err := commonSvc.NewDocumentServiceFromConfig(context.Background(), documentRepo)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Initialize FIFO Service
|
|
fifoService := commonSvc.NewFifoService(db, stockAllocRepo, productWarehouseRepo, utils.Log)
|
|
|
|
// Register Transfer as Stockable (adds stock to destination warehouse)
|
|
err = fifoService.RegisterStockable(fifo.StockableConfig{
|
|
Key: fifo.StockableKey("STOCK_TRANSFER_IN"),
|
|
Table: "stock_transfer_details",
|
|
Columns: fifo.StockableColumns{
|
|
ID: "id",
|
|
ProductWarehouseID: "dest_product_warehouse_id",
|
|
TotalQuantity: "total_qty",
|
|
TotalUsedQuantity: "total_used",
|
|
CreatedAt: "created_at",
|
|
},
|
|
OrderBy: []string{"created_at ASC", "id ASC"},
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Register Transfer as Usable (consumes stock from source warehouse)
|
|
err = fifoService.RegisterUsable(fifo.UsableConfig{
|
|
Key: fifo.UsableKey("STOCK_TRANSFER_OUT"),
|
|
Table: "stock_transfer_details",
|
|
Columns: fifo.UsableColumns{
|
|
ID: "id",
|
|
ProductWarehouseID: "source_product_warehouse_id",
|
|
UsageQuantity: "usage_qty",
|
|
PendingQuantity: "pending_qty",
|
|
CreatedAt: "created_at",
|
|
},
|
|
OrderBy: []string{"created_at ASC", "id ASC"},
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
transferService := sTransfer.NewTransferService(validate, stockTransferRepo, stockTransferDetailRepo, stockTransferDeliveryRepo, StockTransferDeliveryItemRepo, stockLogsRepo, productWarehouseRepo, supplierRepo, warehouseRepo, projectFlockKandangRepo, documentSvc, fifoService)
|
|
userService := sUser.NewUserService(userRepo, validate)
|
|
|
|
TransferRoutes(router, userService, transferService)
|
|
}
|