#57307 - 11/18/19 11:00 AM
Calculate total of calculated Extended Prices
|
OL Newbie
Registered: 11/07/19
Posts: 20
|
Need help please. On my invoice form I have calculated extended prices for each line item. No problem with that. I created this:
=curtostr(strtocur(strip('*', XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/ShippedQuantity[1]'))) * strtocur(trim(XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/UnitPrice[1]'))))
I placed it in my text box as a custom data selection in a local variable named 'DETAIL_EXTENTEDPRICE'
Now I need to calculate the total of all iterations to put in a subtotal on the invoice. Can the guru's here please offer advice on getting the totals?
|
Top
|
|
|
|
#57308 - 11/18/19 11:16 AM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Expert
Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
|
If you wan this to show in the same Text Object, you could run this in the PressTalk Before of the Text Object and store the result in a global variable.
Simply do a for loop of your XML nodes and increment the global variable of the result.
_________________________
♪♫♪♫ 99 frigging bugs in my code 99 frigging bugs Take one down Code around 127 frigging bugs in my code ♪♫♪♫
|
Top
|
|
|
|
#57309 - 11/18/19 12:12 PM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Newbie
Registered: 11/07/19
Posts: 20
|
Seems like there would be a simple way to calculate the total of the iterations in the local variable?
'DETAIL_EXTENTEDPRICE' is the local variable the iterations are printing based on the calculation.
Would that be a way?
|
Top
|
|
|
|
#57310 - 11/18/19 12:24 PM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Expert
Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
|
When writing code in a local variable inside a Text object, the result will be shown. It is not its own PressTalk Editor.
What you want, to be able to display and addition to total at the same time, would need to be done in a different way.
You would need to execute a Press Talk object which would call your Text object for 1 line at the time, while giving it the node number which to display. At the same time, your PressTalk object would add the value to the total variable.
It is simpler the way I explained in the first place. Also know that the PressTalk language hasn't been created to handle mathematical calculation. It can do it but if your start playing with value that requires rounding, you might not get the proper decimal amount that you want.
_________________________
♪♫♪♫ 99 frigging bugs in my code 99 frigging bugs Take one down Code around 127 frigging bugs in my code ♪♫♪♫
|
Top
|
|
|
|
#57311 - 11/18/19 12:36 PM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Newbie
Registered: 11/07/19
Posts: 20
|
Yes sir. I know that presstalk is not really something designed to do this type of calculations reliably. I attempted to explain that to the customer that the calculations need to be done upstream and not done directly on the form , but, i'm attempting to do it for them. My druthers would be to do it up in the SQL and back to the system of record for the error handling. I called it out to the client but in the meanwhile, i'm working on this problem just in case they insist on the calculations happening on the form.
Also, the total does not show in the same text object. It shows in another text object on the footer. Would that change the method?
Edited by Stephenlnoe (11/18/19 12:37 PM)
|
Top
|
|
|
|
#57312 - 11/18/19 12:51 PM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Expert
Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
|
Nope...save the total into a global variable and then display it wherever you want.
As far as reliability goes, addition, subtraction and multiplication, are all right. It is division with floating point value that might cause a problem as the rounding in Postscript, which is the underlying language into which PressTalk is converted, isn't a financial programming language.
_________________________
♪♫♪♫ 99 frigging bugs in my code 99 frigging bugs Take one down Code around 127 frigging bugs in my code ♪♫♪♫
|
Top
|
|
|
|
#57313 - 11/18/19 05:02 PM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Newbie
Registered: 11/07/19
Posts: 20
|
I tried and came up with this:
&INVOICE_TOTAL:=&INVOICE_TOTAL+curtostr(strtocur(strip('*', XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/ShippedQuantity[1]'))) * strtocur(trim(XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/UnitPrice[1]'))))
I set the global variable as String, no dice, I set the global variable to currency, no dice. I set the global variable to integer, no dice.
|
Top
|
|
|
|
#57314 - 11/19/19 08:11 AM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Expert
Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
|
How about that?
&INVOICE_TOTAL:=&INVOICE_TOTAL+strtocur(strip('*', XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/ShippedQuantity[1]'))) * strtocur(trim(XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/UnitPrice[1]')))
and set your global variable as a measure.
If you leave it as a string, it will concatenate the string version of the amount and not add the amount.
_________________________
♪♫♪♫ 99 frigging bugs in my code 99 frigging bugs Take one down Code around 127 frigging bugs in my code ♪♫♪♫
|
Top
|
|
|
|
#57315 - 11/19/19 09:00 AM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Expert
Registered: 04/19/10
Posts: 316
Loc: London, UK
|
You're concatenating a string there rather than adding numbers together. I would also do this in steps for legibility reasons if nothing else. Set a global variable as Jean-Cédric suggests. Let's assume that is your variable &INVOICE_TOTAL and presuppose it is type currency.
define(&ShippedQty, currency, strtocur(XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/ShippedQuantity[1]')))
define(&UnitPrice, currency, strtocur(XmlGet('/Document[1]/Page[1]/SalesOrderLines[1]/SalesOrderLine['+inttostr(¤titeration)+']/UnitPrice[1]')))
&INVOICE_TOTAL := &INVOICE_TOTAL + (&ShippedQty * &UnitPrice)
NB: I wasn't sure on the relevant of stripping out the "*" from the example you give above so I have removed this step.Place this code in the Text Object in PressTalk Before (as advised above). Hope this helps. Regards, James.
|
Top
|
|
|
|
#57324 - 11/25/19 09:40 AM
Re: Calculate total of calculated Extended Prices
[Re: Stephenlnoe]
|
OL Newbie
Registered: 11/07/19
Posts: 20
|
Getting closer. I placed the code provided by James (thank you) in the press talk before and it gave me a result in the preview, however when I go to compile the form I get two errors.
"compilation error:PTK0038: Unknown integer variable "currentiteration"
&
"Run error: PTK 0083:[FOOTER_TOTALS] is empty: possible conversion error"
FOOTER_TOTALS is the text box where I put the press talk before and where the total would be inserted.
On the code James provided I'm wondering about the QTY part. Don't know if it makes a difference but it is not currency (with $.00). It is more of an integer (whole number).
|
Top
|
|
|
|
|
|