Settle customer Invoice through X++.
CustTable custTable;
CustTrans invCustTrans, payCustTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
CustVendOpenTransManager manager;
CustTransOpen custTransOpen;
;
custTable = CustTable::find(Accnum);
// Find the oldest unsettled invoice
select firstonly invCustTrans order by TransDate asc
where invCustTrans.AccountNum == custTable.AccountNum &&
invCustTrans.TransType == LedgerTransType::Sales &&
!invCustTrans.closed;
//!invCustTrans.LastSettleDate;
// Find the oldest unsettled payment
select firstonly payCustTrans order by TransDate asc
where payCustTrans.AccountNum == custTable.AccountNum &&
payCustTrans.TransType == LedgerTransType::Payment &&
!payCustTrans.closed;
//!payCustTrans.LastSettleDate;
select firstonly custTransOpen
where custTransOpen.RefRecId == payCustTrans.RecId
&& custTransOpen.AccountNum == payCustTrans.AccountNum;
if (invCustTrans.RecId && payCustTrans.RecId && custTransOpen.RecId)
{
//manager = CustVendOpenTransManager::construct(ledgerJournalTrans);
manager = CustVendOpenTransManager::construct(custTable);
manager.updateTransMarked(custTransOpen,true);
//manager.updateSettleAmount(custTransOpen, Amount);
//manager.settleMarkedTrans();
ttsbegin;
// Mark it for settlement
custVendTransData = CustVendTransData::construct(invCustTrans);
custVendTransData.markForSettlement(CustTable);
custVendTransData = CustVendTransData::construct(payCustTrans);
custVendTransData.markForSettlement(CustTable);
// Settle all marked transactions
//CustTrans::settleTransact(custTable, null, true, SettleDatePrinc::SelectDate, systemdateget());
CustTrans::settleTransact(custTable, null, true, SettleDatePrinc::DaysDate, systemdateget());
ttscommit;
}
Keep Daxing!!
No comments:
Post a Comment