web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How can generate voucher with CustVendVoucher class?

(0) ShareShare
ReportReport
Posted on by

Hi,

I need generate voucher with CustVendVoucher with the goal replicate method post of TrvPost, but only generate the voucher without transactions. This is my code:

public static Voucher grwPostCustVendTransactions( TrvExpTable _trvExpTable,

                                                CustVendAC _custVendAccount,

                                                AmountCur _transactionAmount,

                                                CurrencyCode _transactionCurrency,

                                                TrvDateStd _transDate,

                                                ExchRate _exchRate,

                                                TransTxt _transTxt,

                                                InvoiceId _invoiceId,

                                                DimensionDefault _defaultDimension = 0)

{

    DimensionDefault        defaultDimension;

    VendVoucher         custVendVoucher;

    SysModule               module;

    LedgerTransTxt          ledgerTransTxt = LedgerTransTxt::None;

    PostingProfile          postingProfile = '';

    VendTable               vendTable;

    CustVoucher             custVoucher;

    VendTrans               vendTrans;

    CustTrans               custTrans;

    Voucher                 voucherNum;

    TrvExpTrans             trvExpTrans;

    LedgerVoucher           ledgerVoucher;

    NumberSequenceCode      voucherSeriesCode;

    LedgerVoucherObject     ledgerVoucherObject;

    NumberSequenceReference numberSequenceReference;

    LedgerVoucherTransObject    ledgerVoucherTransObject, ledgerVoucherTransObject2;

 

 

    numberSequenceReference = TrvParameters::numRefExpenseVoucher();

    if(numberSequenceReference.RecId == 0)

    {

        error("@SYS305186");

        return "";

    }

    voucherSeriesCode   = numberSequenceReference.numberSequenceTable().NumberSequence;

    voucherNum          = NumberSeq::newGetVoucherFromCode(voucherSeriesCode, NumberSeqScopeFactory::createDataAreaScope(), true).voucher();

    module              = SysModule::Vend;

    ledgerVoucher       = LedgerVoucher::newLedgerPost(DetailSummary::Detail, SysModule::Ledger, voucherSeriesCode);

    ledgerVoucherObject = LedgerVoucherObject::newVoucher(  voucherNum,

                                                            today(),

                                                            SysModule::Ledger);

    ledgerVoucher.addVoucher(ledgerVoucherObject);

 

    defaultDimension = VendTable::find(_custVendAccount).DefaultDimension;

 

    // Initialize custVendVoucher

    custVendVoucher = CustVendVoucher::construct(module,

                                _custVendAccount,

                                _transactionAmount,

                                _transactionCurrency,

                                ledgerTransTxt,

                                defaultDimension,

                                postingProfile,

                                LedgerPostingType::VendBalance);

 

    custVendVoucher.parmTransDate(_transDate);

    custVendVoucher.parmExchRate(_exchRate);

 

    custVendVoucher.parmTransVoucher(voucherNum);

    custVendVoucher.parmTransTxt(_transTxt);

    custVendVoucher.parmDocumentDate(_trvExpTable.trvReportDate());

    custVendVoucher.parmDocumentNum(_trvExpTable.ExpNumber);

    custVendVoucher.parmInvoiceId(_invoiceId);

    custVendVoucher.parmCustVendNegInstStatus(CustVendNegInstStatus::Invoiced);

 

    custVendVoucher.parmApproved(NoYes::Yes);

    custVendVoucher.parmApprover(currentWorker());

 

    //agregar las transacciones

 

    ledgerVoucherTransObject = ledgerVoucherTransObject::newBasicDefault(ledgerVoucherObject, LedgerPostingType::LedgerJournal,

                                                                        DimensionStorage::accountNum2LedgerDimension(vendTable.AccountNum,LedgerJournalACType::Vend), _transactionCurrency,

                                                                        _transactionAmount, _transactionAmount, _transactionAmount);

    ledgerVoucherTransObject2 = ledgerVoucherTransObject::newBasicDefault(ledgerVoucherObject, LedgerPostingType::LedgerJournal,

                                                                        DimensionStorage::accountNum2LedgerDimension(vendTable.AccountNum,LedgerJournalACType::Vend), _transactionCurrency,

                                                                        -1*_transactionAmount, -1*_transactionAmount, -1*_transactionAmount);

 

    ledgerVoucherObject.addTrans(ledgerVoucherTransObject);

    ledgerVoucherObject.addTrans(ledgerVoucherTransObject2);

    //

 

    if(module == SysModule::Vend)

    {

        vendTable = VendTable::find(_custVendAccount);

        if(vendTable)

        {

            custVendVoucher.parmPaymId(vendTable.PaymId);

            custVendVoucher.parmPaymMode(vendTable.PaymMode);

            custVendVoucher.parmPaymTermId(vendTable.PaymTermId);

            custVendVoucher.parmPaymSpec(vendTable.PaymSpec);

            custVendVoucher.parmThirdPartyBankAccountId(vendtable.BankAccount);

            custVendVoucher.parmTransType(LedgerTransType::Vend);

        }

    }

 

    /*if(module == SysModule::Cust)

    {

        custVoucher = custVendVoucher;

        custVoucher.setTransRef(CustTransRefType::Invoice, _invoiceId );

    }*/

 

    //Post custVendVoucher

    if (custVendVoucher.validate())

    {

        if(module == SysModule::Vend)

        {

            custVendVoucher.post(ledgerVoucher, vendTrans);

        }

        else

        {

            custVendVoucher.post(ledgerVoucher, custTrans);

        }

    }

    return voucherNum;

}

 

And, for test, I create the next job:

static void EAVTEST3(Args _args)

{

 

    TrvPost::grwPostCustVendTransactions(TrvExpTable::find("DVINCG0000691"),

                                            "DVIP0000046",

                                            300,

                                            Ledger::accountingCurrency(),

                                            today(),

                                            100,

                                            "TEST_GRW",

                                            "INV6");

   

    info("termino");

}

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans