Gossamer Forum
Home : Products : DBMan : Customization :

Total $ amount of column

Quote Reply
Total $ amount of column
I'm working on some reports and I need a way to total up the Subtotal column of all displayed records. So let's say I do a search for June 10. Right now I have a summary search showing each order with the data and subtotal. What I want to do is display up top the total of all the subtotals displayed. And if the search is for just June, then it would add all the subtotals for the whole month and display one total up top. My Subtotal column is consistent and includes numbers only, such as 99.99 . I'd appreciate any help you guys can give me. Thanks!
Quote Reply
Re: [idg-usa] Total $ amount of column In reply to
Try this link if you have not already solved the problem.

http://www.gossamer-threads.com/..._reply;so=ASC;mh=25;
Quote Reply
Re: [joematt] Total $ amount of column In reply to
Hi Joematt Smile

Thanks for replying. I tried that code and making a few modifications but it appears that the code is based on the previousname field or something. I simply need to add up the column specified in my config file as "Subtotal". I simply need it to calculate only for the returned results.

TIA
Quote Reply
Re: [idg-usa] Total $ amount of column In reply to
This is just a quick reply as I will be out of the office all day.

I believe from what I recall of reading the thread that the previousname variable is not something from the config, rather a temporary variable to keep track of when to the category to subtotal changes. The is being done on the search results, so yes you are correct, if you are searching for June only, and want a total, you do not need that part.

Should make it easier.

I'll be back tommorrow.
Quote Reply
Re: [joematt] Total $ amount of column In reply to
Joematt,

I tried it again with the what I think is the proper mods. Here's what I've got and I'm getting a "0" displayed:

Code:
if ($rec{'DateDay'} eq $PreviousDateDay) {
$subtotal += $rec{'Subtotal'};
}
else {
if ($subtotal) {
}
$subtotal = $rec{'Subtotal'};
$PreviousName = $rec{'DateDay'};
}


Notice I removed the print qq| after the else { because I had to place this routine above the print header subroutine. I need to display the subtotal in the header and by leaving the print qq| there, it doesn't display at all. So I went ahead and in the body of the header I have the following:

Code:
<FONT FACE=arial size=2>Total for Period: $subtotal</font>


All I get is a "0". Any ideas?
Quote Reply
Re: [idg-usa] Total $ amount of column In reply to
I think the problem is that you are trying to do the subtotaling in the header. Not that you could not display the subtotal in the header, but since we are dealing with search results we are working with @hits. If you notice that within html_view_sucess the @hits is passed through several steps, see below from html_view_sucess.

Code:
# Go through each hit and convert the array to hash and send to
# html_record for printing.
for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
}

Then html_record reads the values as $rec

So until you do those steps, you cannot use $rec{'DateDay'}.

Sorry. The obvious thing to do seems to do the subtotaling within html_record and set some sort of trigger (based on the last record) to put the subtotal at the bottom of the search results.

Hum? Otherwise it seems you need a seperate sub to subtotal prior to html_header.
Quote Reply
Re: [joematt] Total $ amount of column In reply to
ok so I suppose that totaling in the header won't work - at least with that code. No problem. I'll total at the bottom. To make the situation clearer, here's what I need to do. I have a database of transactions and this "report" (unique setup of DBMan) displays a summary of transactions based on the date selected. The actual datafile has about 30 delimited fields. For this display I am only using 5.

Here's the format of the display using the field names:

DateDay Firstname Lastname Subtotal Referrer

The sorting is based on DateDay which is actually the month and day. So a report for one day will show several hundred transactions (records). I need to total the subtotals of all the records that are displayed. If I can't do it up top (where I have the number of transaction displayed using $db_max_hits, I can total on the bottom.

So.. based on the code in the other thread, how can I get the subototal only at the bottom of all the displayed records?

Last edited by:

idg-usa: Jun 17, 2003, 3:40 PM
Quote Reply
Re: [idg-usa] Total $ amount of column In reply to
I suggest, near the bottom of html_record after the |; but before the last }

add
Code:
$total_field = $rec{'Subtotal'};

$total_field =~ s/(<b>|<\/b> )//gi;

$Pagetotal += $total_field;

then in html_view_success following the lines that say;

Code:
# Go through each hit and convert the array to hash and send to
# html_record for printing.
for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
}

you can use the new variable such as;
Code:
print "<BR> Total of the Subtotals = $Pagetotal<BR>";

I tested this only a little, so double check your results.
Also note that the $Pagetotal is just that, the total for the displayed records, not all the $hits.
Quote Reply
Re: [joematt] Total $ amount of column In reply to
Like a charm! Thank you sir! Cool