Tuesday, 17 April 2018

Account Payable settle payment with invoice x++

Hello Guys..!

Here I'm sharing code for Settle Vendor Invoice/Payment through X++  

Code:
-----------
static void VendorSettlement(Args _args)
{
VendTable vendTable;
VendTrans invVendTrans, payVendTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
;
vendTable = VendTable::find("12345");
// Find the oldest unsettled invoice
select firstonly invVendTrans  order by TransDate asc
                            where invVendTrans.AccountNum == vendTable.AccountNum &&
                            invVendTrans.TransType == LedgerTransType::Purch &&
                            !invVendTrans.closed;
// Find the oldest unsettled payment
select firstonly payVendTrans order by TransDate asc
                    where payVendTrans.AccountNum == vendTable.AccountNum &&
                    payVendTrans.TransType == LedgerTransType::Payment &&
                    !payVendTrans.closed;
ttsbegin;
// Create an object of the CustVendTransData class with the invoice transaction as parameter
custVendTransData = CustVendTransData::construct(invVendTrans);
// Mark it for settlement
custVendTransData.markForSettlement(vendTable);
// Create an object of the CustVendTransData class with the payment transaction as parameter
custVendTransData = CustVendTransData::construct(payVendTrans);
//mark it for settlement
custVendTransData.markForSettlement(vendTable);
ttscommit;
// Settle all marked transactions
if(VendTrans::settleTransact(vendTable, null, true,SettleDatePrinc::DaysDate, systemdateget()))
info("Transactions settled");
}

reference Click Here

Account Payable create a payment journal x++

  LedgerJournalTable jourTable;
    LedgerJournalTrans jourTrans;
    LedgerJournalTableData jourTableData;
    JournalTransData jourTransData;
    LedgerJournalStatic jourStatic;
    DimensionDynamicAccount ledgerDim;
    DimensionDynamicAccount offsetLedgerDim;
    NumberSeq numberseq;

ttsBegin;
    ledgerDim = DimensionStorage::getDynamicAccount('29901-00162',LedgerJournalACType::Vend);
    offsetLedgerDim = AxdDimensionUtil::getLedgerAccountId(['1213011','1213011',1,'Vendor','29901-00162']); //DimensionStorage::getDynamicAccount('NBE.EGP',LedgerJournalACType::Bank);

    jourTableData = JournalTableData::newTable(jourTable);
    jourTable.JournalNum = jourTableData.nextJournalId();
    jourTable.JournalType = LedgerJournalType::Payment;
    jourTable.JournalName = '207';
    jourTableData.initFromJournalName(
    LedgerJournalName::find(jourTable.JournalName));
    jourStatic = jourTableData.journalStatic();
    jourTransData = jourStatic.newJournalTransData(
    jourTrans,
    jourTableData);
    jourTransData.initFromJournalTable();

    jourTrans.CurrencyCode ='EGP';
    jourTrans.initValue();
   numberseq = NumberSeq::NewGetVoucherFromCode('207');
    jourTrans.TransDate = systemDateGet();
    jourTrans.AccountType = LedgerJournalACType::Vend;
    jourTrans.LedgerDimension = ledgerDim;
    jourTrans.Txt = 'Vendor payment journal demo';
    jourTrans.OffsetAccountType = LedgerJournalACType::Ledger;
    jourTrans.OffsetLedgerDimension = offsetLedgerDim;
    jourTrans.AmountCurDebit = 1000;
    //jourTransData.create();
    jourTable.insert();
    jourTransData.insert();
    ttsCommit;
    info(strFmt(
    "Journal '%1' has been created", jourTable.JournalNum));
    ttsCommit;