mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-26 00:05:44 +00:00
feat(BE): integrate FIFO service for stock adjustments and transfers
- 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.
This commit is contained in:
+23
-1
@@ -81,9 +81,29 @@ func (r *ProductWarehouseRepositoryImpl) ProductWarehouseExistByProductAndWareho
|
||||
|
||||
func (r *ProductWarehouseRepositoryImpl) GetProductWarehouseByProductAndWarehouseID(ctx context.Context, productId, warehouseId uint) (*entity.ProductWarehouse, error) {
|
||||
var productWarehouse entity.ProductWarehouse
|
||||
if err := r.DB().WithContext(ctx).Where("product_id = ? AND warehouse_id = ?", productId, warehouseId).First(&productWarehouse).Error; err != nil {
|
||||
|
||||
err := r.DB().WithContext(ctx).
|
||||
Where("product_id = ? AND warehouse_id = ? AND project_flock_kandang_id IS NOT NULL", productId, warehouseId).
|
||||
Order("id DESC").
|
||||
Preload("ProjectFlockKandang").
|
||||
First(&productWarehouse).Error
|
||||
|
||||
if err == nil {
|
||||
|
||||
if productWarehouse.ProjectFlockKandang.ClosedAt == nil {
|
||||
return &productWarehouse, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err = r.DB().WithContext(ctx).
|
||||
Where("product_id = ? AND warehouse_id = ? AND project_flock_kandang_id IS NULL", productId, warehouseId).
|
||||
First(&productWarehouse).Error
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &productWarehouse, nil
|
||||
}
|
||||
|
||||
@@ -244,6 +264,8 @@ func (r *ProductWarehouseRepositoryImpl) GetDetailByID(ctx context.Context, id u
|
||||
Preload("Warehouse").
|
||||
Preload("Warehouse.Area").
|
||||
Preload("Warehouse.Location").
|
||||
Preload("ProjectFlockKandang").
|
||||
Preload("ProjectFlockKandang.ProjectFlock").
|
||||
First(&productWarehouse, id).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user