Show total invoice amount

Hi, Just for checking the total value, I’d like to add a button to calculate the total invoice amount on a Purchase Order, base on the “value” field. I’ve added the following code: WITH SalesLines DO SalesLines.INIT; invoice_amount := 0; BEGIN IF SalesLines.FIND(’-’) THEN window.OPEN(‘Total amount is: #1########’); REPEAT invoice_amount := invoice_amount + SalesLines.amount; UNTIL SalesLines.NEXT = 0; window.UPDATE(1, invoice_amount); window.INPUT; END; The problem is: it will show the a wrong figure, not the right total figure. SalesLines is datatype:record #39; invoice_amount is datatype:decimal; What I’m missing? Thanks.

Hi Xib If you press the F9 button you will get statistics of the current order. Regards Janus

Hi Janus, I understand I can get that info through F9, but I need to add this funcionality for cross-checking and further manipulation. Thanks.

Hi! Why do you need this code ???

quote:


… WITH SalesLines DO SalesLines.INIT;


Maybe your problem could be solved, if you set some Filters on the SalesLine ? e.g. (Sorry, i don’t know the right translations…)

 
SalesLine.SETRANGE(Belegart, Belegart);
SalesLine.SETRANGE("Belegnr.", "Nr.");
IF SalesLine.FIND('-') THEN
  REPEAT
  ...

Regards, Jörg Joerg A. Stryk Apollo-Optik, IT/ERP

I think you are running into a problem that the current line is not yet committed to the database so, your use of the SaleLine variable does not “see” the changed/new line. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

Bill is quite right // Filter the Records First SalesLines.RESET; SalesLines.SETRANGE(“Document Type”,“Document Type”); SalesLines.SETRANGE(“Document No.”,“Document No.”); // Exclude Current rec or Xrec from calculation SalesLines.SETFILTER(“Line No.”,’<>%1’,“Line No.”); // Find the first Record IF SalesLines.FIND(’-’)THEN REPEAT InvAmt:=InvAmt+SalesLines.Amount; UNTIL SalesLines.NEXT=0; // Add the rec Amount InvAmt:=InvAmt+Amount; Unless looking at your code you are not filtering properly? If you are running this from the Order function keys and not from the lines all you need is: CALCFIELDS(Amount); Message(‘Amount is %1’,Amount); Amount being a flow field on the Sales or Purchase Header! There are other Flow Fields on the header Like “Outstanding Amount (LCY)” you should look at before writing code! These are all calculated Values from the lines, And called the same CALCFIELDS(FieldName)! David Cox MindSource (UK) Limited Navision Solutions Partner Edited by - David Cox on 2001 Aug 29 09:36:14

Hi there, still awake? Quote “Just for checking the total value, I’d like to add a button to calculate the total invoice amount on a Purchase Order, base on the “value” field. I’ve added the following code: WITH SalesLines DO” Are you dead sure there isn’t a doubt whether it is a purchase order or a sales order. That may make some difference. Besides, I vouch for the F9 line. Analyse the code in the Statistics form. Use it and add your exta functionality. Pelle

Hi Pelle, variable name should be PurchaseLine instead of SalesLines, although it was assigned to the right table #39. Thanks.

I always thought that Navision programmmers need to follow a course and do an exam before they actually can program. Roelof.

Hi Roelef, You’re absolutely right!.. and I’m not a programmer, indeed. I appreciate your concern. Thanks.

quote:


Originally posted by Xib: Hi, Just for checking the total value, I’d like to add a button to calculate the total invoice amount on a Purchase Order, base on the “value” field. I’ve added the following code: WITH SalesLines DO SalesLines.INIT; invoice_amount := 0; BEGIN IF SalesLines.FIND(‘-’) THEN window.OPEN(‘Total amount is: #1########’); REPEAT invoice_amount := invoice_amount + SalesLines.amount; UNTIL SalesLines.NEXT = 0; window.UPDATE(1, invoice_amount); window.INPUT; END; The problem is: it will show the a wrong figure, not the right total figure. SalesLines is datatype:record #39; invoice_amount is datatype:decimal; What I’m missing? Thanks.


There are some errors in your code… but it’s an easy task :slight_smile: this is yours… WITH SalesLines DO // You’re initializating the variable… no sense… it puts your actual record in saleslines to 0 SalesLines.INIT; invoice_amount := 0; BEGIN // If saleslines is not filtered that will show all the saleslines, not only the ones in the purchase IF SalesLines.FIND(‘-’) THEN // this code will open a window with an empty value while reading the lines window.OPEN(‘Total amount is: #1########’); REPEAT invoice_amount := invoice_amount + SalesLines.amount; UNTIL SalesLines.NEXT = 0; // That’s ok… if you want a window that closes when ending the process… window.UPDATE(1, invoice_amount); window.input??? why??? are u trying to input a value?? // just window.close when finished… but it will close the window. // instead of a window use message… window.INPUT; END; and this is how you can do it… >) // if you’re on the saleslines subform (table 37) for sales or table 39 for purchases :slight_smile: SalesLines.RESET; SalesLines.INIT; SalesLines.TRANSFERFIELDS(Rec); SalesLines.SETRANGE(“Document type”,SalesLines.“Document type”); SalesLines.SETRANGE(“Document No.”,SalesLines.“Document No.”); // if your button is in the sales card form (not the subform) use this instead. SalesLines.RESET; SalesLines.SETRANGE(“Document type”,Rec.“Document type”); SalesLines.SETRANGE(“Document No.”,Rec.“No.”); // If there are registers on the sales lines: IF (SalesLines.FIND(‘-’)) THEN // You don’t need to make all the sum, as the Amount field as calcsums of the primary key // in standard Navision, so you can use directly the function Calcsums SalesLines.CALCSUMS(Amount); // Now you just need to show a message with the total amount, that will be in the field amount of // your variable saleslines. MESSAGE (SalesLines.Amount); As you can see it’s not too hard :_)

quote:


Originally posted by Roelof de Jong I always thought that Navision programmmers need to follow a course and do an exam before they actually can program. Roelof.


Just two things, Roelof: a) I’ve never seen on Anga’s anything about being a programmer… b) Not all people is as smart as you’re for not having troubles on the starts… may be a good way for helping them on learn is trying to solve their answers instead of blaming them for having the questions… I’m sure there are also some other things that you still don’t know about navision’s programming and other people in the forum consider them as basics or obvious tasks… but the forum is supossed to be a place for helping to ALL people… not only a-thousand-wars-survivor developers, but beginners ones… Regards from California, – Alfonso Pertierra apertierra@teleline.es Spain Western Computer Los Angeles, California

Janus, Joerg, William, David, Pelle and Alfonso: Thank you very much for your comments and suggestions! Suddenly, I had almost lost my faith in this forum… so there is still some space for REAL beginners… Again… many thanks!

question for information Do you want the total amount for (1)one order or (2)for the whole order. (1) in the table purchase header tou hava a field “Amount” attention it’s a flowfield use the instruction [currform.calcfields(amount)] for viewing the value. (2) use the step one but don’t forget to totalising the whole order. Excuse my english.

Hi Fabrice, I’m looking for option 2. Btw, your english is fine :slight_smile: Thanks.

Also… FYI, the F9 statistics screen is not always correct! I have recently reported this to Navision (as others may have). This relates to certain currency conversion configurations that lead to varying total quantities to be shown on the statistics screen. The reason for this is that these values are back calculated based on the lines and currencies etc. There is also some problems within Distribution that means you cant press F9 on a released order (as it tries to update the lines with certain currency rounding setups). I replicated these issues in Cronus 2.6, and also 3.0(!) before reporting them. More info when an answer comes back from Navision. Craig Bradney Technical Manager Navision Solutions & Services, Deloitte Touche Tohmatsu Email:cbradney@deloitte.com.au

Hi Craig, Thanks for sharing this info. Just being curious: how have you been dealing with that until now, when you want to check F9?