mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
ini ar fifo
This commit is contained in:
@@ -61,6 +61,7 @@ func (PurchaseModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate
|
||||
expenseRealizationRepo,
|
||||
projectFlockKandangRepository,
|
||||
documentSvc,
|
||||
commonSvc.NewFifoPaymentService(db, utils.Log),
|
||||
validate,
|
||||
)
|
||||
expenseBridge := service.NewExpenseBridge(
|
||||
@@ -72,6 +73,7 @@ func (PurchaseModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate
|
||||
)
|
||||
|
||||
fifoStockV2Service := commonSvc.NewFifoStockV2Service(db, utils.Log)
|
||||
fifoPaymentService := commonSvc.NewFifoPaymentService(db, utils.Log)
|
||||
|
||||
purchaseService := service.NewPurchaseService(
|
||||
validate,
|
||||
@@ -84,6 +86,7 @@ func (PurchaseModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate
|
||||
approvalService,
|
||||
expenseBridge,
|
||||
fifoStockV2Service,
|
||||
fifoPaymentService,
|
||||
documentSvc,
|
||||
)
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ type purchaseService struct {
|
||||
ApprovalSvc commonSvc.ApprovalService
|
||||
ExpenseBridge PurchaseExpenseBridge
|
||||
FifoStockV2Svc commonSvc.FifoStockV2Service
|
||||
FifoPaymentSvc commonSvc.FifoPaymentService
|
||||
DocumentSvc commonSvc.DocumentService
|
||||
approvalWorkflow approvalutils.ApprovalWorkflowKey
|
||||
}
|
||||
@@ -91,6 +92,7 @@ func NewPurchaseService(
|
||||
approvalSvc commonSvc.ApprovalService,
|
||||
expenseBridge PurchaseExpenseBridge,
|
||||
fifoStockV2Svc commonSvc.FifoStockV2Service,
|
||||
fifoPaymentSvc commonSvc.FifoPaymentService,
|
||||
documentSvc commonSvc.DocumentService,
|
||||
) PurchaseService {
|
||||
return &purchaseService{
|
||||
@@ -105,6 +107,7 @@ func NewPurchaseService(
|
||||
ApprovalSvc: approvalSvc,
|
||||
ExpenseBridge: expenseBridge,
|
||||
FifoStockV2Svc: fifoStockV2Svc,
|
||||
FifoPaymentSvc: fifoPaymentSvc,
|
||||
DocumentSvc: documentSvc,
|
||||
approvalWorkflow: utils.ApprovalWorkflowPurchase,
|
||||
}
|
||||
@@ -1406,6 +1409,16 @@ func (s *purchaseService) ReceiveProducts(c *fiber.Ctx, id uint, req *validation
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Refresh purchase.grand_total + reallocate payment FIFO untuk supplier (new debt baru emerges).
|
||||
if s.FifoPaymentSvc != nil && receivingAction == entity.ApprovalActionApproved {
|
||||
if err := s.FifoPaymentSvc.RecomputeGrandTotal(c.Context(), nil, commonSvc.ParentKindPurchase, purchase.Id); err != nil {
|
||||
s.Log.Warnf("Failed to recompute grand_total for purchase %d: %+v", purchase.Id, err)
|
||||
}
|
||||
if err := s.FifoPaymentSvc.ReallocateForParty(c.Context(), nil, string(utils.PaymentPartySupplier), uint(purchase.SupplierId)); err != nil {
|
||||
s.Log.Warnf("Failed to reallocate payments for supplier %d: %+v", purchase.SupplierId, err)
|
||||
}
|
||||
}
|
||||
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user