06 December 2013

X++ coding for Ledger Voucher posting with example / Ledger Voucher posting / voucher posting in AX

Example Class for Reference : \Classes\TutorialLedgerVoucher\runSalesPost
Example: Using LedgerVoucher
The following job posts a petty cash disbursement for a payment for a stapler and
some stamps. The accounts and amounts are set in the variable declaration.
Usually these would be obtained from parameters, user input or a calculation.

static void ExampleLedgerVoucher(Args _args)
{
LedgerVoucher ledgerVoucher;
LedgerVoucherTransObject ledgerVoucherTransObject;
Dimension dimension;
NumberSeq numSeq;
NumberSequenceCode NumberSequenceCode =
'Acco_18';
ledgerAccount accountNumPetty = '110180';
// Petty cash
ledgerAccount accountNumOffsetOffice =
'606300'; // Office Supplies
ledgerAccount accountNumOffsetPostage =
'606500'; // Postage
amountMST amountPetty = 55;
amountMST amountOffice = 50;
amountMST amountPostage = 5;
;
numSeq =
NumberSeq::newGetNumFromCode(NumberSequenceCode);
ttsbegin;
//First Step - Create Voucher
ledgerVoucher =
ledgerVoucher::newLedgerPost(DetailSummary::Summary,
SysModule::Ledger,
LedgerParameters::numRefLedgerExchAdjVoucher().NumberSequen
ce) ;
//Second Step - Create Voucher Number
ledgerVoucher.AddVoucher(LedgerVoucherObject::newVoucher(nu
mseq.num(),
today(),
Sysmodule::Ledger,
LedgerTransType::None));
//Create the first Transaction - this is the credit
side of the transaction (-55)
//The other two DR transactions should total to the CR
otherwise it won't post.
ledgerVoucherTransObject =
LedgerVoucherTransObject::newCreateTrans(
ledgerVoucher.findLedgerVoucherObject(),
LedgerPostingType::LedgerJournal,
accountNumPetty, // Ledger Account
dimension,
CompanyInfo::standardCurrency(),
-
amountPetty, // Amount
0, //
TableId
0); //
ReciID
ledgerVoucherTransObject.parmTransTxt("Petty cash
disbursement");
ledgerVoucher.addTrans(ledgerVoucherTransObject);
//Create the second Transaction
ledgerVoucherTransObject =
LedgerVoucherTransObject::newCreateTrans(
ledgerVoucher.findLedgerVoucherObject(),
LedgerPostingType::LedgerJournal,
accountNumOffsetOffice,
dimension,
CompanyInfo::standardCurrency(),
amountOffice, // Amount
0,
// TableId
0);
// ReciID
ledgerVoucherTransObject.parmTransTxt("Red stapler");
ledgerVoucher.addTrans(ledgerVoucherTransObject);
//Create third Transaction
ledgerVoucherTransObject =
LedgerVoucherTransObject::newCreateTrans(
ledgerVoucher.findLedgerVoucherObject(),
LedgerPostingType::LedgerJournal,
accountNumOffsetPostage,
dimension,
CompanyInfo::standardCurrency(),
amountPostage,
0,
// TableId
0);
// ReciID
ledgerVoucherTransObject.parmTransTxt("Stamps");
ledgerVoucher.addTrans(ledgerVoucherTransObject);
//Last Step - To Balance Voucher and Close
ledgerVoucher.end();
numseq.used();
ttsCommit;
}

1 comment:

  1. coding curriculum I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.

    ReplyDelete

Give me the commetns and solutions

DB restore production DB to DEV environment in D365 FO using Bacpac file

  https://www.linkedin.com/pulse/restore-production-database-dev-environment-d365fo-using-abbas-tfwbe SQLPackage link : https://www.linkedin...