sum of the Sales Line

dyn45dyn45 Member Posts: 67
edited 2008-04-15 in Navision Attain
hi to all,

I have a little problem here...
I am working with a form 42 Sales Order and I would like to add one field in the header which will show me the Invoice Amount (don't need in the table).
When I enter the Sales line, line by line, the new created field should be filled with the sum of all lines.

The field "Amount Including VAT" is not of use to me because it will not show the value until the document is shipped.

What is the best way to do this calculation?

Answers

  • krikikriki Member, Moderator Posts: 9,115
    Put a new field (a global and not a field in the table) on the subform. And in the OnAfterGetCurrentREcord-trigger, calculate the total. BTW : don't use "rec" but use a new variable to do it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • pri_1_ranjanpri_1_ranjan Member Posts: 67
    but probably this will update only , we try to select the record at the header level or refresh it ? {though I have not tried it}

    Amount including vat is updated when the document is released.
    /PDR
  • dyn45dyn45 Member Posts: 67
    thanx kriki, pri_1_ranjan...

    I need this field just to see that amount as I entering the sales line, without releasing it.

    could someone send me an code example with the calculation, still have problems...
  • krikikriki Member, Moderator Posts: 9,115
    but probably this will update only , we try to select the record at the header level or refresh it ? {though I have not tried it}
    You need to put it on the subform, so it will refresh each time you change record there.

    the code:
    recSalesLine.RESET;
    recSalesLine.SETCURRENTKEY("DOcument Type","Document No.","Line No.");
    recSalesLine.SETRANGE("Document Type","Document Type");
    recSalesLine.SETRANGE("Document No.","Document No.");
    recSalesLine.CALCSUMS(Amount);
    

    And put recSalesLine.Amount on the subform, but outside the tablebox and make it non-editable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • pri_1_ranjanpri_1_ranjan Member Posts: 67
    yes. That is correct
    /PDR
  • SavatageSavatage Member Posts: 7,142
    I use "LINE AMOUNT" field
  • emulsifiedemulsified Member Posts: 139
    The fields for Amount and "Amount Including VAT" are 0 until the SIO or SO is posted.

    I used something similar to this code after a user is finished doing entry to obtain the TOTAL before posting. We also write some of our orders to an intermediate database for WEB purposes so we needed to be able to obtain the TOTAL before posting. Simply put this in a button on the form, works just about the same as pressing 'F9' key.
    Sum("Sales Line"."Outstanding Amount (LCY)" WHERE (Document Type=FIELD(Document Type),Document No.=FIELD(No.)))
    

    You might want to add a textbox and/or use it in a trigger in some way.
    Half-empy or half-full how do you view your database?

    Thanks.
  • bbrownbbrown Member Posts: 3,268
    emulsified wrote:
    The fields for Amount and "Amount Including VAT" are 0 until the SIO or SO is posted.

    ...

    Those values are calculated what the Sales Order is released.
    There are no bugs - only undocumented features.
  • dyn45dyn45 Member Posts: 67
    thank you guys for your help...

    emulsified, you were right. I can't use Amount and "Amount Including VAT".
    could you explain your code, please, I am not quite sure that I understand it (still newbee). where should I put this code? How should I use this code with a textbox?
    I would like not to use any buttons to CALC that field.
  • SavatageSavatage Member Posts: 7,142
    edited 2010-02-11
    click on a sales line->Tools-Designer
    Select the table box and drag it up to create just enuf space at the bottom or top to fit a textbox.

    View->Globals
    -Add a function called CalcRunningTotal (or something)
    -Add a Variable: recSalesLine-Record-Sales Line

    Add this code to the function
    CalcRunningTotal()
    recSalesLine.RESET;
    recSalesLine.SETCURRENTKEY("Document Type", "Document No.", "Line No.");
    recSalesLine.SETRANGE("Document Type", "Document Type");
    recSalesLine.SETRANGE("Document No.","Document No.");
    recSalesLine.CALCSUMS("Line Amount");
    

    Now add a textbox to the space created when moving up the Table Box.
    Add to it's sourceExp: recSalesLine."Line Amount"
    Make sure the property VertGlue is Bottom

    It should look like this:
    http://savatage99.googlepages.com/Textb ... bleBox.JPG

    finally add
    OnAfterGetCurrRecord()
    CalcRunningTotal;
    
  • tinoruijstinoruijs Member Posts: 1,226
    Just noticed form 55 (Purch. Invoice Subform) has new functionality in NAV 5.0! 8)

    Depending on boolean "Show Totals on Purch. Inv./CM." in the Purchase Setup form 55 shows the total of the lines like you want it in the Sales Order.
    Maybe you could take a look how it's made and use same functionality for the sales order?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
Sign In or Register to comment.