IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#30928 - 04/20/10 06:02 AM adding a subtotal from a range of data
vlaardim Offline
OL Newbie

Registered: 03/12/10
Posts: 20
Loc: The Netherlands
Hello,

I'm trying to make a calculated subtotal at the end of each page in a multipage invoice.

The data is in @(25,83,92). I already made a GlobalVar type curency, defaul "0"
But I Don't know how to tell the system that it has to add the values.

Can you give me a hint??

Top
#30929 - 04/20/10 10:28 AM Re: adding a subtotal from a range of data
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
vlaardim,

First, we have to know exactly what there is in this line. Is this a serie of currency values separated by some character? Please explain exactly what the subtotal is calculated from, and if possible, give us an example of data that you have in your file.

Regards,
Rapha

Top
#30930 - 04/21/10 02:20 AM Re: adding a subtotal from a range of data
vlaardim Offline
OL Newbie

Registered: 03/12/10
Posts: 20
Loc: The Netherlands
Hi Rapha

Top
#30931 - 04/21/10 10:44 AM Re: adding a subtotal from a range of data
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
Marcel,

Making the subtotal for one line is a bit tricky, because there is nothing that is specifically made to mark the start of the various amounts. We cannot use the spacing between the various entries, because it's not constant(the third block, for example, has more spaces due to a longer name than the first two).

We could sort-of simulate it using the dots in the currency values to know where to start, then make a presstalk function that returns the amount. Here's an example:

Code:
function @TotalPerLines(&line:integer):string
  define(&res, string, '')
  define(&curline, string, '')
  define(&i, integer, 0)
  define(&totalamounts, currency, 0.0)
  define(&s, string, '')

  &curline := @(&line, 1, 1000)

  if(pos('.', &curline) > 0)
    &i := pos('.', &curline)
    % Read characters backward until we find a space.
    repeat
      &i := &i - 1
    until(mid(&curline, &i, 1) = ' ')
    % Read the amounts.
    &i := &i + 1
    repeat
      if((mid(&curline, &i, 1) = ' ') or (&i = length(&curline)))
        if(&i = length(&curline))
          &s := &s + mid(&curline, &i, 1)
        endif()
        &totalamounts := &totalamounts + strtocur(&s)
        &s := ''
      else()
        &s := &s + mid(&curline, &i, 1)
      endif()
      &i := &i + 1
    until(&i > length(&curline))
    % Prepare the total to be displayed.
    &res := curtostr(&totalamounts)
  else()
    % In cases where there is no dots(therefore no amounts), we return a blank string.
    &res := ''
  endif()

  % Return the final result.
  &Result := &res
endfunction()
This function will add all three(or more) amount values that are at the end of the line you specify. So in a custom data selection, you could type:

=@TotalPerLines(1)

That would add up the values on the first line, and would display, in this case, 266.68. Note that if you use this function on a line with no currency values, it will return a blank string.

Hope that helps!

Regards,
Rapha

Top
#30932 - 04/22/10 03:15 AM Re: adding a subtotal from a range of data
vlaardim Offline
OL Newbie

Registered: 03/12/10
Posts: 20
Loc: The Netherlands
Rapha

Top
#30933 - 04/22/10 09:27 AM Re: adding a subtotal from a range of data
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
If the last value on the line is the total, you can get it by making a simple change to the above function. You can change:

Code:
&totalamounts := &totalamounts + strtocur(&s)
Into:
Code:
&totalamounts := strtocur(&s)
And you could rename the function into something like GetTotal instead of TotalPerLines, as it would be closer to what it does.


After that, you can create a presstalk object, and loop through the lines of data to add up the totals and display it. Here's an example(assuming you renamed the function to GetTotal):

Code:
define(&t, currency, 0.0)
define(&i, integer, 0)

for(&i, 1, 1, &current.lpp)
  if(pos('.', @(&i, 1, 1000)) > 0)
    &t := &t + strtocur(@GetTotal(&i))
  endif()
endfor()

show(curtostr(&t))
This will add up the totals of each lines that have one, looping through every lines on your data page, and display it at the end. Of course, you could instead create a global variable, and put the value of &t in that variable, so it becomes usable at other places.

Hope that helps!

Regards,
Rapha

Top
#30934 - 04/23/10 09:41 AM Re: adding a subtotal from a range of data
vlaardim Offline
OL Newbie

Registered: 03/12/10
Posts: 20
Loc: The Netherlands
Wow, I thought it would be simple...
Ok I'll test this next week. Thanks

Regards Marcel Vlaardingerbroek

Top