Thursday, February 3, 2011

Inventory Verification - Placing values from PurchParmTotals on PurchEditLines Form in AX 2009


Today I had to fulfill the following requirement:
  1. When the user clicks "Invoice Verification" from the Purch Order Form, place the following in the PurchEditLines Form
    • Invoice Balance
    • SalesTax
    • Line Discount
    • Balance
Usually you can see these values when clicking the Totals button from the PurchEditLines Form object in AX 2009.



Figure1. 

When you clicked the Totals button the PurchParmTableTotals Form gets activated and the PurchTotals class gets instantiated. So I needed to basically replicate what this form is doing to present the values we see above in the PurchEditLines form as show below.

 Figure 2.


To accomplish this I went to the PurchEditLines form and I open the Methods node and I added two new methods:

1- calcPurchParmTotals() : This methods instantiate the abstract class named PurchTotals. and calls the second method I created (setDisplaysFields()).

void calcPurchParmTotals()
{
    Object  purchEditLines;
    ;

    purchEditLines = element.args().caller();


    if(purchParmTable.ParmId)
    {
        purchTotals = PurchTotals::newPurchParmTable(purchParmTable, purchEditLines.specQty(), AccountOrder::None, purchParmTable.ParmId,
                                             '', purchParmTable.Ordering);

        purchTotals.calc();
        element.setDisplayFields();
    }
}
2- setDisplaysFields() : As the abstract class PurchTotals was instantiated in the prior method, now I can create a container and assign the container values to the new fields I created in the PurchEditLines forms as shown below.
void  setDisplayFields()
{
    container  displayFields = purchTotals.displayFields([PurchTotals::posCashDisc(),
                                                          PurchTotals::posCashDiscDate(),
                                                          PurchTotals::posEndDisc(),
                                                          PurchTotals::posTaxRoundOff(),
                                                          PurchTotals::posRoundOff(),
                                                          PurchTotals::posCurrency(),
                                                          PurchTotals::posExchRate(),
                                                          PurchTotals::posLineDisc(),
                                                          PurchTotals::posBalance(),
                                                          PurchTotals::posMarkup(),
                                                          PurchTotals::posTaxTotal(),
                                                          PurchTotals::posTotalAmount(),
                                                          PurchTotals::posRoundOff()]);
    ;



   
   
    LineDiscount.realValue     (conpeek(displayFields, PurchTotals::posLineDisc()));
    Balance.realValue          (conpeek(displayFields, PurchTotals::posBalance()));
    SalesTax.realValue         (conpeek(displayFields, PurchTotals::posTaxTotal()));
    InvoiceAmount.realValue    (conpeek(displayFields, PurchTotals::posTotalAmount()));

    purchParmTable.dataSource().reread();
    purchParmTable.dataSource().refresh();
   
}

Then I opened the PurchEditLines form and I went to the Data Source node. I expanded the PurchParmTable Data source and I added the following line of code in the active() method:

element.calcPurchParmTotals();

 The result can be seen in Figure 2.

No comments:

Post a Comment

Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!