public void markTransaction(LedgerJournalTrans _journalTrans)
{
CustTransOpen custTransOpen;
CustTrans custTrans;
CustVendOpenTransManager manager = CustVendOpenTransManager::construct(_journalTrans);
SpecTransManager specTransManager = manager.parmSpecTransManager();
AmountCur unmarkedAmount;
// 🔹 Find the matching CustTrans record
select firstonly custTrans
where custTrans.Invoice == _journalTrans.MarkedInvoice // Probably should map to invoice reference
&& custTrans.AccountNum == 'Test001'; // Replace hardcode with _journalTrans.CustomerAccount if possible
// 🔹 Find the open transaction for settlement
custTransOpen = CustTransOpen::findRefId(custTrans.RecId);
// 🔹 Check unmarked amount for this transaction
unmarkedAmount = specTransManager.findUnmarkedAmountForRef(custTransOpen.AmountCur,
custTransOpen.company(),custTransOpen.TableId,custTransOpen.RecId);
if (unmarkedAmount <= 0)
{
warning("Nothing left to settle for this transaction.");
}
// 🔹 Ensure not already marked by another specTrans
if (!manager.checkTransFullyMarkedByOtherSpec(custTransOpen))
{
manager.updateTransMarked(custTransOpen, NoYes::Yes);
manager.updateSettleAmountPaymCur(custTransOpen, custTransOpen.AmountCur);
}
ttsbegin;
_journalTrans.selectForUpdate(true);
_journalTrans.MarkedInvoice = custTrans.Invoice;
_journalTrans.SettleVoucher = SettlementType::SelectedTransact;
_journalTrans.doUpdate();
ttscommit;
}