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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Multiple Purchase order's in single invoices through x++ code

(0) ShareShare
ReportReport
Posted on by

Hi all, know Multiple Purchase order's in single invoices through x++ code

do anyone know how to do Multiple Purchase order's in single invoices through x++ code

Regards,

Gopal RC

*This post is locked for comments

I have the same question (0)
  • amoxto Profile Picture
    90 on at

    Hi Gopal RC,

    Do you want consolidate Purchase Order for then register?  check the next link, can you help:

    learnax.blogspot.com/.../ax-2012-x-code-to-create-and-post.html

    Regards

    amoxto

  • Verified answer
    Community Member Profile Picture
    on at

     Amoxto, thank you for you reply. the issue has been solved.

    please feel free to ask code, if you need in future.

    Regards,

    Gopal RC

  • Community Member Profile Picture
    on at

    Hi Gopal,

    Can you please share the code to post single invoice for multiple POs.

    I am using ax 2012 R2. Thanks

  • Verified answer
    Community Member Profile Picture
    on at

    public void createInvoiceHeader()
    {
    VendInvoiceInfoSubTable vendInvoiceInfoSubTable;
    VendInvoiceInfoLine vendInvoiceInfoLineLocal;
    PurchFormLetter_Invoice purchFormLetterInvoice;
    FilenameOpen file2;
    PurchFormLetter purchFormLetter;
    PurchTable PurchTableloc;
    //BBBBCareDate BBBBCareDate;
    TransDate transdateloc;
    TransDate fromDate,toDate;
    TimeZone tz;
    UtcDateTime fDateTime,tDateTime;
    VendInvoiceJour vendInvJour;
    int parm = 0;

    ;

    //fromDate = mkDate(30,05,2016);
    //toDate = mkDate(30,06,2011);
    //fDateTime = Global::datetobeginUtcDateTime(fromDate,tz);
    //tDateTime = Global::datetoendUtcDateTime(toDate,tz);

    //fDateTime = str2datetime("06/05/2016 00:00:00", 213);
    //FilenameOpen file2 = "C:\\Test\\Error_File.csv";
    //file2 = "C:\\Test\\Error_File.csv";
    //Gopal RC Added 3 line of code
    /* file2 = "\\\\COAUAPPDEV003\\ErrorFile\\ErrorFile" + "_" + date2str(systemDateGet(),321,2,0,2,0,4) + "_" + int2str(timeNow()) + ".csv";
    new FileIOPermission(file2, #io_write).assert();
    io1 = new TextIo(file2,'w');*/

    while select purchline order by BBBBinvoicereferencenum
    where purchline.BBBBInvoiceReferenceNum != ""
    && purchline.PurchStatus == PurchStatus::Backorder
    && purchline.RemainPurchPhysical > 0
    //&& purchline.PurchId == "BHD2-158736"

    // && purchline.createdDateTime >= fDateTime
    // purchline.createdBy == "99904214" && purchline.createdDateTime == utcdTime

    {
    //ttsBegin;
    select vendInvJour
    where vendInvJour.InvoiceId == purchline.BBBBInvoiceReferenceNum;
    if(!vendInvJour)
    {
    try
    {
    //where values comes for "invoicereferencenumber"
    //con = [purchline.PurchId, invoicereferencenumber];

    if (invoicereferencenumber != purchline.BBBBInvoiceReferenceNum)
    {
    purchtable = PurchTable::find(purchline.PurchId);
    invoicereferencenumber = purchline.BBBBInvoiceReferenceNum;
    con = [purchline.BBBBInvoiceReferenceNum];

    if (vendInvoiceInfoTable &&
    vendInvoiceInfoTable.Num)
    {
    ttsbegin;

    /*purchtableLoc = PurchTable::find(purchline.PurchId);
    transdateloc = DatetimeUtil::date(purchtableLoc.BBBBCareDate);
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
    purchFormLetter.update(purchtableLoc, invoicereferencenumber ,transdateloc);*/


    purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
    purchFormLetterInvoice.showQueryForm(false);
    purchFormLetterInvoice.update(vendInvoiceInfoTable, vendInvoiceInfoTable.Num, vendInvoiceInfoTable.transdate);
    ttsCommit;
    }
    }

    if(purchtable)
    {
    //ttsBegin;
    vendInvoiceInfoTable.clear();
    vendInvoiceInfoTable.initValue();
    vendInvoiceInfoTable.initFromPurchTable(purchtable);

    vendInvoiceInfoTable.DocumentOrigin = DocumentOrigin::Manual;
    vendInvoiceInfoTable.CurrencyCode = purchtable.CurrencyCode;
    vendInvoiceInfoTable.DeliveryName = purchtable.DeliveryName;
    vendInvoiceInfoTable.Num = purchline.BBBBInvoiceReferenceNum;
    vendInvoiceInfoTable.PurchName = purchtable.PurchName;
    vendInvoiceInfoTable.VendInvoiceSaveStatus= VendInvoiceSaveStatus::Pending;
    vendInvoiceInfoTable.TransDate = systemDateGet();
    vendInvoiceInfoTable.DocumentDate = systemDateGet();
    //vendInvoiceInfoTable.
    vendInvoiceInfoTable.LastMatchVariance = LastMatchVarianceOptions::OK;
    vendInvoiceInfoTable.ParmJobStatus = ParmJobStatus::Waiting;
    vendInvoiceInfoTable.Approved = true;
    vendInvoiceInfoTable.Approver = DirPersonUser::currentWorker();
    vendInvoiceInfoTable.DefaultDimension = vendInvoiceInfoTable.copyDimension(purchtable.DefaultDimension);


    vendInvoiceInfoTable.defaultField(fieldNum(vendInvoiceInfoTable, RemittanceLocation),null, purchtable);
    vendInvoiceInfoTable.defaultField(fieldNum(vendInvoiceInfoTable, FixedDueDate),null,purchtable);
    vendInvoiceInfoTable.defaultField(fieldNum(vendInvoiceInfoTable, ExchRate),null, purchtable);
    vendInvoiceInfoTable.defaultField(fieldNum(vendInvoiceInfoTable, TransDate),null,purchtable);
    vendInvoiceInfoTable.defaultField(fieldNum(vendInvoiceInfoTable, PaymMode),null, purchtable);

    vendInvoiceInfoTable.insert();
    purchtable.clear();
    //ttsCommit;
    }
    //VendInvoiceInfoSubTable::find(vendInvoiceInfoTable.ParmId, vendInvoiceInfoTable.TableRefId, purchline.PurchId).RecId
    if(vendInvoiceInfoTable.RecId && !VendInvoiceInfoSubTable::find(vendInvoiceInfoTable.ParmId, vendInvoiceInfoTable.TableRefId, purchline.PurchId).RecId)
    {
    //ttsBegin;
    VendInvoiceInfoSubTable.clear();
    VendInvoiceInfoSubTable.initValue();
    VendInvoiceInfoSubTable.defaultRow();

    VendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
    VendInvoiceInfoSubTable.OrigPurchId = purchline.PurchId;
    VendInvoiceInfoSubTable.PurchName = purchline.purchTable().PurchName;
    VendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
    VendInvoiceInfoSubTable.insert();
    //ttsCommit;
    }

    this.createInvoiceline(vendInvoiceInfoTable, purchline);
    //ttsCommit;
    iCount++;

    }
    catch
    {
    //info(strFmt("Exception occured PO: %1 not invoiced",vendInvoiceInfoTable.PurchId));
    locError = strFmt('Error occured legacy id %1 purchid %2', conPeek(con,1));
    this.exportCSV(iCount,purchline);
    continue;
    }
    }
    }
    try
    {
    if (invoicereferencenumber != purchline.BBBBInvoiceReferenceNum)
    {

    invoicereferencenumber = purchline.BBBBInvoiceReferenceNum;
    con = [purchline.BBBBInvoiceReferenceNum];

    if (vendInvoiceInfoTable &&
    vendInvoiceInfoTable.Num)
    {
    ttsbegin;
    /*purchtableLoc = PurchTable::find(purchline.PurchId);
    transdateloc = DatetimeUtil::date(purchtableLoc.BBBBCareDate);
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
    purchFormLetter.update(purchtableLoc, invoicereferencenumber ,transdateloc);*/

    purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
    purchFormLetterInvoice.showQueryForm(false);
    purchFormLetterInvoice.update(vendInvoiceInfoTable, vendInvoiceInfoTable.Num, vendInvoiceInfoTable.transdate);
    ttsCommit;
    }
    }
    }
    catch
    {
    //info(strFmt("Exception occured PO: %1 not invoiced",vendInvoiceInfoTable.PurchId));
    this.exportCSV(iCount,purchline);
    }
    //io1.finalize();
    }

  • Gayathri  Profile Picture
    15 on at

    Hi gopal,

    Thank you for sharing the code.I am facing one problem on creating pending invoice with multiple orders with same invoice number. If you have any idea in that please share.

    Thanks in advance

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans