Thursday 10 January 2019

Complete Call center sales orders using x++ code


MCRCustPaymTable        mcrCustPaymTable;
RetailMCRChannelTable   retailMCRChannelTable;
boolean                 mcrCallCenterOrder;

//Returns whether the sales order is associated with a call center or not.
mcrCallCenterOrder = salesTable.mcrIsCallCenter();
           
if (mcrCallCenterOrder == true)
{
       select firstonly retailMCRChannelTable
                    where retailMCRChannelTable.RecId   == salesTable.RetailChannelTable;

       mcrCustPaymTable.CustAccount    = salesTable.CustAccount;
       mcrCustPaymTable.CurrencyCode   = salesTable.CurrencyCode;
       mcrCustPaymTable.Channel        = salesTable.RetailChannelTable;
       mcrCustPaymTable.LineNum        = 1;
       mcrCustPaymTable.OnAccountAuthorized = NoYes::Yes;
       mcrCustPaymTable.PercentAmount  = 100;
       mcrCustPaymTable.TenderTypeId   = retailMCRChannelTable.DOMServiceEventPaymMethod;
       mcrCustPaymTable.CustPaymType   = MCRCustPaymTable::getMCRTypeFromTender(mcrCustPaymTable.TenderTypeId,
                                                                                         mcrCustPaymTable.Channel,
                                                                                         mcrCustPaymTable.CardTypeId);
       mcrCustPaymTable.RefTableId     = salesTable.TableId;
       mcrCustPaymTable.RefRecId       = salesTable.RecId;
       mcrCustPaymTable.insert();

       MCRSalesOrderTotals mcrSalesOrderTotals = new MCRSalesOrderTotals(salesTable, true);

       //complete
       MCREndOrder::endOrder(salesTable.SalesId, true, mcrSalesOrderTotals, false);
}