Thursday, August 15, 2019

Post a Sales invoice in D365 Finance & Operations X++

Below is the job I created for posting sales invoices.

Solution 1
------------------

Public static void salesOrderInvoiceByLine(SalesLine    _salesline)
{
        salesFormLetter         salesFormLetter;
        salesFormletterParmData salesFormLetterParmData;
        salesParmUpdate         salesParmUpdate;
        salesParmTable          salesParmTable;
        salesParmLine           salesParmLine;
        salesTable              salesTable;
      
        ttsbegin;
        salesTable  = salesTable::find(_salesline.SalesId);
        salesFormLetterParmData = salesFormletterParmData::newData(DocumentStatus::Invoice, VersioningUpdateType::Initial);

        salesFormLetterParmData.parmOnlyCreateParmUpdate(true);
        salesFormLetterParmData.createData(false);
        salesParmUpdate = salesFormLetterParmData.parmParmUpdate();

        salesParmTable.clear();
        salesParmTable.TransDate                = _salesline.ReceiptDateRequested;
        salesParmTable.Ordering                 = DocumentStatus::Invoice;
        salesParmTable.ParmJobStatus            = ParmJobStatus::Waiting;
        salesParmTable.salesId                  = salesTable.salesId;

        salesParmTable.salesName                = salesTable.salesName;
        salesParmTable.DeliveryName             = salesTable.DeliveryName;
        salesParmTable.DeliveryPostalAddress    = salesTable.DeliveryPostalAddress;
        salesParmTable.CustAccount              = salesTable.CustAccount;
        salesParmTable.CurrencyCode             = salesTable.CurrencyCode;
        salesParmTable.InvoiceAccount           = salesTable.InvoiceAccount;
        salesParmTable.ParmId                   = salesParmUpdate.ParmId;
        salesParmTable.insert();
           
        if (_salesline)
        {
            salesParmLine.InitFromsalesLine(_salesline);
            salesParmLine.DeliverNow    = _salesline.SalesQty;
            salesParmLine.ParmId        = salesParmTable.ParmId;
            salesParmLine.TableRefId    = salesParmTable.TableRefId;
            salesParmLine.setQty(DocumentStatus::Invoice, falsetrue);
            salesParmLine.setLineAmount(_salesline);
            salesParmLine.insert();
        }
        ttscommit;
        salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice);
        salesFormLetter.transDate(_salesline.ReceiptDateRequested);
        salesFormLetter.proforma(false);
        salesFormLetter.specQty(salesUpdate::All);
        salesFormLetter.salesTable(salesTable);
        salesFormLetter.parmId(salesParmTable.ParmId);
        salesFormLetter.salesParmUpdate(salesFormLetterParmData.parmParmUpdate());
        salesFormLetter.run();
}


Solution 2
------------------

class Test_PostPackingSlip
{     
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        SalesTable _SalesTable;
        SalesFormLetter_Invoice invoice;
            ttsbegin;
            _SalesTable.clear();
            _SalesTable = SalesTable::find("SO00125116");
            invoice = SalesFormLetter::construct(DocumentStatus::Invoice);
            // Post the invoice
            invoice.update(_SalesTable,
            SystemDateGet(),
            SalesUpdate::All,
            AccountOrder::None,
            false,
            true); // Set to true to print the invoice
              ttsCommit;
    }

}

5 comments:

  1. The curriculum for free sales courses usually begins with the sales introduction. This is the process of creating rapport with the prospective customers. קורס מכירות

    ReplyDelete
  2. This will result in a higher page ranking on the SERP. As you know, a higher search engine result page rank you get, the more people are going to click on your website link. free invoice template UK

    ReplyDelete
  3. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your.
    presales

    ReplyDelete
  4. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.
    pożyczka w 5 minut bez zaświadczeń

    ReplyDelete
  5. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post. invoice factoring

    ReplyDelete

Why do users often get confused about Dynamics 365 Customer Engagement (D365 CE), Dataverse, and the Power Platform?

  The Microsoft ecosystem for business applications can sometimes be difficult to navigate, especially when discussing Dynamics 365 Customer...