mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
FIX[BE}: add stock logs for transfer stock
This commit is contained in:
@@ -266,6 +266,24 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
|||||||
}
|
}
|
||||||
s.Log.Infof("Source product warehouse updated: %+v", sourcePW.Id)
|
s.Log.Infof("Source product warehouse updated: %+v", sourcePW.Id)
|
||||||
|
|
||||||
|
// create stock log for decrease (source)
|
||||||
|
beforeQty := sourcePW.Quantity + product.ProductQty // sourcePW already decreased
|
||||||
|
decreaseLog := &entity.StockLog{
|
||||||
|
TransactionType: entity.TransactionTypeDecrease,
|
||||||
|
Quantity: product.ProductQty,
|
||||||
|
BeforeQuantity: beforeQty,
|
||||||
|
AfterQuantity: sourcePW.Quantity,
|
||||||
|
LogType: entity.LogTypeTransfer,
|
||||||
|
LogId: uint(entityTransfer.Id),
|
||||||
|
Note: "",
|
||||||
|
ProductWarehouseId: sourcePW.Id,
|
||||||
|
CreatedBy: 1,
|
||||||
|
}
|
||||||
|
if err := s.StockLogsRepository.WithTx(tx).CreateOne(c.Context(), decreaseLog, nil); err != nil {
|
||||||
|
s.Log.Errorf("Failed to create stock log decrease: %+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Tambah stok di gudang tujuan
|
// Tambah stok di gudang tujuan
|
||||||
destPW, err := s.ProductWarehouseRepo.GetProductWarehouseByProductAndWarehouseID(
|
destPW, err := s.ProductWarehouseRepo.GetProductWarehouseByProductAndWarehouseID(
|
||||||
c.Context(), uint(product.ProductID), uint(req.DestinationWarehouseID),
|
c.Context(), uint(product.ProductID), uint(req.DestinationWarehouseID),
|
||||||
@@ -296,6 +314,24 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
|||||||
}
|
}
|
||||||
s.Log.Infof("Destination product warehouse updated: %+v", destPW.Id)
|
s.Log.Infof("Destination product warehouse updated: %+v", destPW.Id)
|
||||||
|
|
||||||
|
// create stock log for increase (destination)
|
||||||
|
beforeDestQty := destPW.Quantity - product.ProductQty
|
||||||
|
increaseLog := &entity.StockLog{
|
||||||
|
TransactionType: entity.TransactionTypeIncrease,
|
||||||
|
Quantity: product.ProductQty,
|
||||||
|
BeforeQuantity: beforeDestQty,
|
||||||
|
AfterQuantity: destPW.Quantity,
|
||||||
|
LogType: entity.LogTypeTransfer,
|
||||||
|
LogId: uint(entityTransfer.Id),
|
||||||
|
Note: "",
|
||||||
|
ProductWarehouseId: destPW.Id,
|
||||||
|
CreatedBy: 1,
|
||||||
|
}
|
||||||
|
if err := s.StockLogsRepository.WithTx(tx).CreateOne(c.Context(), increaseLog, nil); err != nil {
|
||||||
|
s.Log.Errorf("Failed to create stock log increase: %+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user