Sum Amount After filter

klumklum Member Posts: 102
Hi All,

Maybe my problem is easily for somebody.. :o
I am working on NAV4.0Sp3. I created new form which have :

TabControl
- There are three filter variables are DateFilter,DocumentFilter and
VendorFilter

TableBox (Purchase Line)
- This tableBox where will show information when customer selected any filters

TextBox (TotalVatAmount-Decimal)
- My problem from this variable.

My question is How I can sum Amount field after I put some filters already and update TextBox Control???? ](*,)

Any help I will appreciate...Thank in advance :|

Wanvisa

Answers

  • DatapacDatapac Member Posts: 97
    Hi Wanvisa,
    I had a similar problem to this a couple of days ago and I created a function in the form to get around it. Your function would resemble the following:
    CalcTotalVat() TotalVat : Decimal
    
    TotalVat := 0;
    PurchLine.RESET;
    
    PurchLine.SETFILTER("Order Date", GETFILTER("Order Date"));
    PurchLine.SETRANGE("Vendor No.",GETFILTER("Vendor No."));
    PurchLine.SETRANGE("Document No.",GETFILTER("Document No."));
    IF PurchLine.FIND('-') THEN BEGIN
       REPEAT
        BEGIN
          TotalVAT += PurchLine."VAT Amount";
        END;
       UNTIL PurchLine.NEXT = 0;
    END;
    EXIT(TotalVat);
    

    PurchLine is a local variable in the function
    You then just need to call this function from the appropriate point in your process to refresh the TotalVatAmount field.
    (e.g. TotalVATAmount := CalcTotalVat;)

    Hope this helps
    Richie
  • klumklum Member Posts: 102
    Hi Richie :P

    Thank a lot for your fast answer to me...
    I put this function CalcTotalVat onValidate each filter variable so I wrote code like this:
    Function CalcTotalVat
    
    TotalVATAmount := 0;
    SETFILTER("Posting Date",DateFilter);
    SETFILTER("No.",DocumentFilter);
    SETFILTER("Buy-from Vendor No.",VendorFilter);
    SETFILTER("Wagon No.",WagonFilter);
    IF FINDFIRST THEN
      REPEAT
        TotalVATAmount += "Item Charges VAT Amount";
      UNTIL NEXT = 0;
    

    Now It's work well ....Thanks again

    Best Regards,
    Wanvisa
Sign In or Register to comment.