Thursday, March 17, 2016

Totals for Purchase order, Sales order and Sales quotation.

There are some forms in Ax 2012 which displays the totals for the selected records such as purchase order, sales order, sales quotation, etc. These totals will be calculated based on the line details of those orders. The following piece of code can be used to get the totals for the orders at the header level.


Totals for purchase order:
    
    PurchtotalsForm     purchTotals;
    PurchTable             purchTable;    
    real                         a, b, c, d;
    ;
    purchTable      = purchTable::find('PO-000000132', false);
    purchTotals     = PurchtotalsForm::newPurchTotalsForm(purchTable, PurchUpdate::All);
    purchTotals.calctotals();
    purchTotals.doPack();
    
    a = purchTotals.invoiceAmountValue();
    b = purchTotals.invoiceRoundOffValue();
    c = purchTotals.sumMarkUpValue();
    d = purchTotals.qtyValue();
    
    info(strFmt("%1, %2, %3, %4", a, b, c, d));


Totals for sales order:

    container                       salesTotals;
    SalesTable                     salesTable;
    Amount                         a, b, c, d;
    ;
    salesTable          = SalesTable::find('SO-000000114', false);
    salesTotals         = SalesTotals::displayFieldsServer(salesTable, SalesUpdate::All);

    a = conPeek(salesTotals, TradeTotals::posEndDisc());
    b = conPeek(salesTotals, TradeTotals::posMarkup());
    c = conPeek(salesTotals, TradeTotals::posRoundOff());
    d = conPeek(salesTotals, TradeTotals::posTotalAmount()); 

    info(strFmt("%1, %2, %3, %4", a, b, c, d));


Totals for sales quotation:

    container                       displayFields;
    SalesQuotationTotals     quotationTotals;
    SalesQuotationTable      quotationTable;
    Amount                         a, b, c, d;
    ;
    quotationTable      = SalesQuotationTable::find('SQ-000031', false);
    quotationTotals     = SalesQuotationTotals::construct(quotationTable, SalesUpdate::All);
    displayFields        = quotationTotals.displayFieldsCurrency('SAR');

    a = conPeek(displayFields, TradeTotals::posBalance());
    b = conPeek(displayFields, TradeTotals::posMarkup());
    c = conPeek(displayFields, TradeTotals::posRoundOff());
    d = conPeek(displayFields, TradeTotals::posTotalAmount());

    info(strFmt("%1, %2, %3, %4", a, b, c, d));


No comments:

Post a Comment