Monday, 23 April 2018

Mark Customer/Vendor Invoice/Invoices for settlement using X++ in D365 or AX 2012

Below method can be used to mark the Invoice amounts for settlement in very easy way.

In your code to loop through ledgerjournaltrans(assuming you already created payment lines for respective Customer/vendor, if not, then create payment record either by X++ or direct entry through payment screens).

Just for reference, i am creating payment via x++ and marked the invoices for settlement.
I am posting full process (create & Post SO, Create Payment entry, Mark invoice for settlement, post payment entry)

form class Declaration.
public class FormRun extends ObjectRun
{   
    CustTable   custtable_g;
    CustInvoiceJour     bitcustInvoiceJour;
}

Below method can be used for SO creation and Payment entry.

public void TestReceipt()
{
    SalesTable salesTable;
    NumberSeq NumberSeq;
    SalesLine salesLine;
    SalesFormLetter formLetterObj;
    InventTable inventTable;

    Ledgerjournalname           ledgerjournalname;
    LedgerjournalTable          LedgerjournalTable;
    LedgerjournalTrans          LedgerjournalTrans;
    LedgerJournalCheckPost      ledgerJournalCheckPost;

    ;

    try
    {
        ttsBegin;
        //Create sales header
        NumberSeq = NumberSeq::newGetNumFromId(SalesParameters::numRefSalesId().NumberSequenceId);
        salesTable.SalesId = NumberSeq.num();
        salesTable.initValue();
        salesTable.CustAccount = custtable_g.AccountNum; //custtable_g is already initialized
        salesTable.initFromCustTable();
        salesTable.insert();

        //Create Sales lines
        salesLine.clear();
        salesLine.SalesId   = salesTable.SalesId;
        salesLine.ItemId    = ItemId.valueStr(); 
        inventTable = InventTable::find(ItemId.valueStr());
        salesLine.initFromInventTable(inventTable);
        salesLine.SalesQty  = Quantity.value();
        salesLine.createLine(NoYes::Yes, // Validate
        NoYes::Yes, // initFromSalesTable
        NoYes::Yes, // initFromInventTable
        NoYes::Yes, // calcInventQty
        NoYes::Yes, // searchMarkup
        NoYes::Yes); // searchPrice

        //confirmation
        //formLetterObj = SalesFormLetter::construct(DocumentStatus::Confirmation);
        //formLetterObj.update(salesTable,Selldate.dateValue());

        //Packing Slip
        formLetterObj = SalesFormLetter::construct(DocumentStatus::PackingSlip);
        formLetterObj.update(salesTable,Selldate.dateValue());

        //Post Invoice
        formLetterObj = SalesFormLetter::construct(DocumentStatus::Invoice);
        formLetterObj.update(salesTable,Selldate.dateValue());

        ttsCommit; 

        //
        ttsBegin;
        bitcustInvoiceJour = formLetterObj.parmJournalRecord();

        //Generate and post receipt

        select ledgerjournalname where ledgerjournalname.JournalName == "PayJ"; //use correct payment journal name

        //ttsBegin;
        LedgerjournalTable.JournalName = ledgerjournalname.JournalName;
        LedgerjournalTable.initFromLedgerJournalName();
        LedgerjournalTable.JournalNum  = JournalTableData::newTable(LedgerjournalTable).nextJournalId();      
        LedgerjournalTable.insert();

        numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
        LedgerjournalTrans.Voucher              =   numberSeq.voucher();
        LedgerjournalTrans.JournalNum           =   LedgerjournalTable.JournalNum;
        LedgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
        LedgerjournalTrans.Company              =   curext();
        LedgerjournalTrans.parmAccount(custtable_g.AccountNum,LedgerjournalTrans.AccountType);
        LedgerjournalTrans.initFromCustTable(custtable_g);
        LedgerjournalTrans.TransDate            = Selldate.dateValue();

        LedgerjournalTrans.ExchRate             =   Currency::exchRate(LedgerjournalTrans.CurrencyCode);

        LedgerjournalTrans.Txt                  =   strFmt('Payment for item sale for sales id : %1',salestable.SalesId);


        LedgerjournalTrans.DefaultDimension         =   custtable_g.DefaultDimension;
        LedgerjournalTrans.OffsetDefaultDimension   =   custtable_g.DefaultDimension;
        LedgerjournalTrans.TransactionType          =   LedgerTransType::Payment;
        LedgerjournalTrans.AmountCurCredit          =   bitcustInvoiceJour.InvoiceAmount;
        LedgerjournalTrans.PaymMode                 =   CustPaymMode.valueStr();
        LedgerjournalTrans.SettleVoucher            =   SettlementType::SelectedTransact;
        LedgerjournalTrans.modifiedField(fieldNum(LedgerjournalTrans,PaymMode));
        LedgerjournalTrans.insert();


        element.settlement(LedgerjournalTrans,LedgerjournalTrans.AmountCurCredit); //look for method

        //Post Journal
        ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(LedgerjournalTable,NoYes::Yes);
        ledgerJournalCheckPost.run();

        ttsCommit;
      
        info(strFmt("Journal %1 created for item sales Id %2 to Student id %3",LedgerjournalTable.JournalNum,salestable.SalesId,custtable_g.AccountNum));

    }
    catch
    {
        error("error in generating receipt for sale.");
    }


}

Below method can be used for settlement of required amount
void settlement(ledgerJournalTrans _ledgerJournalTrans,real _amounttoSettle)
{
    SpecTrans insertSpecTrans;
    ;
    insertSpecTrans.SpecCompany = _ledgerJournalTrans.Company;
    insertSpecTrans.SpecTableId = TableNum(ledgerJournalTrans);
    insertSpecTrans.SpecRecId   = _ledgerJournalTrans.RecId;
    insertSpecTrans.RefCompany  = _ledgerJournalTrans.Company;
    insertSpecTrans.RefTableId  = TableNum(custTransOPen);
    insertSpecTrans.RefRecId    = custTransOPen::findRefId(bitcustInvoiceJour.custTrans().RecId).RecId;
    insertSpecTrans.Balance01   = _amounttoSettle;
    insertSpecTrans.Code        = _ledgerJournalTrans.CurrencyCode;
    insertSpecTrans.Payment     = NoYes::No;
    insertSpecTrans.LineNum     = 1;
    insertSpecTrans.insert();

}

yes, I am done here. Thanks!!!

7 comments:

  1. Halo,I'm Helena Julio from Ecuador,I want to talk good about Le_Meridian Funding Service on this topic.Le_Meridian Funding Service gives me financial support when all bank in my city turned down my request to grant me a loan of 500,000.00 USD, I tried all i could to get a loan from my banks here in Ecuador but they all turned me down because my credit was low but with god grace I came to know about Le_Meridian so I decided to give a try to apply for the loan. with God willing they grant me  loan of 500,000.00 USD the loan request that my banks here in Ecuador has turned me down for, it was really awesome doing business with them and my business is going well now. Here is Le_Meridian Funding Investment Email/WhatsApp Contact if you wish to apply loan from them.Email:lfdsloans@lemeridianfds.com / lfdsloans@outlook.comWhatsApp Contact:+1-989-394-3740.

    ReplyDelete
  2. New Safety Razor - Merit Casino
    Buy 카지노 사이트 주소 a new 카지노사이트luckclub safety razor at the Merit Casino. Merit's proprietary Merit razors feature 메리트 카지노 쿠폰 a 메리트 카지노 조작 longer lasting blade that provides the grip and $99.99 온 카지노 가입쿠폰 · ‎In stock

    ReplyDelete