Gossamer Forum
Home : Products : DBMan : Customization :

Totals and sub totals for sales report.

Quote Reply
Totals and sub totals for sales report.
I have a sales report that will give me the totals for any given time, week ,event or any other search. Below is the code I use
for this.

////////Code/////////

sub html_sales_report {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_;

print qq|
<TD>$rec{'Promotion'}</TD><TD>$rec{'Pdate'}</TD><TD>$rec{'Userid'}</TD><td>$rec{'Amount'}|;
if ($rec{'Bump'} =~ "Yes") {
print qq| &nbsp;<font color="red"> Bump</font></td>|;
}
print qq|
</td>
<TD>$rec{'Bump'}</TD><TD>$rec{'Collected_date'}</TD><TD>$rec{'Week'}</TD><TD>$rec{'Memorabilia'}</TD><TD>$rec{'Payment'}</TD><TD>$rec{'Tap'}</TD><TD><a HREF="$db_script_www/cgi-bin/master/db.cgi?db=default&uid=$in{'uid'}&ID2=&Date=&Company=$rec{'Company'}&keyword=&mh=10&sb=---&so=ascend&view_records=1" target="_blank">$rec{'Company'}</a></TD><TD>$rec{'Special_Inst'}</TD> |;

$total_field = $rec{'Amount'};

$total_field =~ s/\$//./,/gi;

$Pagetotal += $total_field;
}

////////Code/////////

The question I have is. How can I have it sort by "Userid" (Sales Rep) and give the totals for each Userid?
I'm looking for something like this:

Softball 2016 bgoldman $200.00 02/12/2016 03 Pick Up Tap Lewis Animal Hospital
Softball 2016 bgoldman $200.00 02/12/2016 03 Pick Up Tap James W Smith & Sons
Softball 2016 bgoldman $100.00 02/12/2016 03 Pick Up Tap Gumbo's Lawn & Landscape
Softball 2016 bgoldman $100.00 02/12/2016 03 Pick Up New Friends of Charity

Total $600.00


Softball 2016 elevy $200.00 02/12/2016 03 Credit Card Tap Driving School
Softball 2016 elevy $100.00 02/12/2016 03 Pick Up Tap Premiere Electric
Softball 2016 elevy $100.00 02/12/2016 03 Pick Up Tap Superbowl Bellewood
Softball 2016 elevy $200.00 02/12/2016 03 Pick Up Tap G.F. Frank & Sons
Softball 2016 elevy $600.00 02/12/2016 03 Credit Card Tap Louiso Trucking

Total $1200.00


I found this code that totals hours for each person, and it has a layout like I need, but I could not get it to work right.
I changed 'Name' to 'Userid' and 'Hours' to 'Amount'. Then I inserted this in the code above.

/////code/////
In sub html_record, before you print out your results, add code: if ($rec{'Name'} eq $PreviousName) { $subtotal += $rec{'Hours'}; } else { if ($subtotal) { print qq|-----------------&lt;BR&gt;$subtotal|; } $subtotal = $rec{'Hours'}; $PreviousName = $rec{'Name'}; }

/////code/////

The two codes looked like this:

////////Code/////////

sub html_sales_report {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_;


print qq|
<TD>$rec{'Promotion'}</TD><TD>$rec{'Pdate'}</TD><TD>$rec{'Userid'}</TD><td>$rec{'Amount'}|;
if ($rec{'Bump'} =~ "Yes") {
print qq| &nbsp;<font color="red"> Bump</font></td>|;
}
print qq|
</td>
<TD>$rec{'Bump'}</TD><TD>$rec{'Collected_date'}</TD><TD>$rec{'Week'}</TD><TD>$rec{'Memorabilia'}</TD><TD>$rec{'Payment'}</TD><TD>$rec{'Tap'}</TD><TD><a HREF="$db_script_www/cgi-bin/master/db.cgi?db=default&uid=$in{'uid'}&ID2=&Date=&Company=$rec{'Company'}&keyword=&mh=10&sb=---&so=ascend&view_records=1" target="_blank">$rec{'Company'}</a></TD><TD>$rec{'Special_Inst'}</TD> |;


if ($rec{'Userid'} eq $PreviousName) { $subtotal += $rec{'Amount'}; } else { if ($subtotal) { print qq|-----------------&lt;BR&gt;$subtotal|; } $subtotal = $rec{'Amount'}; $PreviousName = $rec{'Userid'}; }




$total_field = $rec{'Amount'};

$total_field =~ s/\$//./,/gi;

$Pagetotal += $total_field;
}

////////Code/////////


The layout I'm ok with, its getting it to sort then the totals for each Sales Rep I'm having trouble with.
Any ideals?

Thank you,
Ed-
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
how are you calling this sub? the sort order should be established when you do the query.
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
Hello Delicia,

The sort order is not a problem, your right that will be set in the search. What I need to do is once the call for the report is made it will sort all the sales rep in order, then at the bottom of each sales rep's list it will put the total of there sales. Here is the code for the sales report, search and success.

/////code/////

##########################################################
## View Sales Report ##
##########################################################

sub html_view_sales_report_search {
# --------------------------------------------------------
# This page is displayed when a user requests to search the
# database for viewing.
# Note: all searches must use GET method.
#
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search the Database.</title>
</head>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=300,width=400,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>

<body bgcolor="#e0e0d6">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search the Database</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Search the Database
</b></font></center><br>
|; &html_record_form(); print qq|
<center>|; &html_search_options; print qq|</center>
<p><center> <INPUT TYPE="SUBMIT" NAME="view_sales_report" VALUE="Sales Report"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|;
if ($per_admin) {
print qq|
<p><center><INPUT TYPE="SUBMIT" NAME="export_records" VALUE="Export Results"></center></p>|; print qq| |;
}
else {
print qq|<input type="hidden" NAME="export_records">|;
}
print qq|
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}

sub html_view_sales_report_success {
# --------------------------------------------------------
# This page displays the results of a successful search.
# in a spreadsheet format.
# You can use the following variables when displaying your
# results:
#
# $numhits - the number of hits in this batch of results.
# $maxhits - the max number of hits displayed.
# $db_total_hits - the total number of hits.
# $db_next_hits - html for displaying the next set of results.
#
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search Results.</title>

</head>

<body bgcolor="#FFFFFF">
<blockquote>
<center><table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td colspan=2 bgcolor="navy"><FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search Results</b>
</font></td></tr>
</table>
<p><$font>
Your search returned <b>$db_total_hits</b> matches.</font></center>
|;
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
# Go through each hit and convert the array to hash and send to
# html_record for printing.
$new_url = $ENV{'QUERY_STRING'};
$new_url =~ s/\&sb=\d+//;
$new_url =~ s/\&so=\w+//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb'} == $col) {
if ($in{'so'} eq 'descend') { $sb[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}

# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places within each line.
print qq|
<TABLE cellpadding=1 cellspacing=8 width=1700>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[3]">Promotion</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[4]">Promo Date</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[1]">Sales Rep</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[35]">Amount</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[52]">Bump</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[34]">Collected Date</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[15]">Week</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[42]">Memorabilia</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[33]">Payment</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[14]">Tap</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[5]">Company</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[23]">Special_Inst</a></TD> |;

for (0 .. $numhits - 1) {
print "<TR>";
&html_sales_report (&array_to_hash($_, @hits));

print "</TR>\n";
}
print "</TABLE>";

if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

print "<BR> Total of the Subtotals = \$$Pagetotal\.00<BR>";
print qq|
<p>
<center><table border=0 bgcolor="#ffffff" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td>|; &html_footer; print qq|</td></tr>
</table></center>
</blockquote>
</body>
</html>
|;
}

/////code/////

Thank you,
Ed-
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
in the search form you need to set the sort field:

<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">

change to:
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="sb" value="Userid">


note: if you don't need the search form, you could just put a link somewhere, perhaps the home page:

<a href="$db_script_link_url&amp;sb=Userid&amp;Userid=*&amp;view_sales_report=1">View Sales Report</a>

i've revised the sales report:

Code:

sub html_sales_report {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_;

my ($colspan) = '11'; #number of columns in the report minus one

print qq|<TD>|;

### this section needs to precede the record
if ($rec{'Userid'} ne $PreviousName) {
if ($PreviousName) {
print qq|-----------------&lt;BR&gt;$subtotal</td><td colspan=$colspan></td></tr>
<tr><td>|; # this prints the subtotal and starts new table row for the record
}
$PreviousName = $rec{'Userid'}; $subtotal = 0;
}
###

$subtotal += $rec{'Amount'};


print qq|
$rec{'Promotion'}</TD><TD>$rec{'Pdate'}</TD><TD>$rec{'Userid'}</TD><td>$rec{'Amount'}|;
if ($rec{'Bump'} =~ "Yes") {
print qq| &nbsp;<font color="red"> Bump</font>|;
}
print qq|</td>
<TD>$rec{'Bump'}</TD><TD>$rec{'Collected_date'}</TD><TD>$rec{'Week'}</TD>
<TD>$rec{'Memorabilia'}</TD><TD>$rec{'Payment'}</TD><TD>$rec{'Tap'}</TD><TD>
<a HREF="$db_script_www/cgi-bin/master/db.cgi?db=default&uid=$in{'uid'}&ID2=&Date=&Company=$rec{'Company'}&keyword=&mh=10&sb=---&so=ascend&view_records=1" target="_blank">$rec{'Company'}</a>
</TD><TD>$rec{'Special_Inst'}</TD> |;


# i don't know what's happening below???

$total_field = $rec{'Amount'};

$total_field =~ s/\$//./,/gi;

$Pagetotal += $total_field;
}

let me know if this is working better!
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
Ok this is what we have so far.

1st. I renamed the subroutine from sub html_sales_report to sub html_rep_report, below is a copy.

/////code/////

sub html_rep_report {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_;

my ($colspan) = '11'; #number of columns in the report minus one

print qq|<TD>|;

### this section needs to precede the record
if ($rec{'Userid'} ne $PreviousName) {
if ($PreviousName) {
print qq|-----------------$subtotal</td><td colspan=$colspan></td></tr>
<tr><td>|; # this prints the subtotal and starts new table row for the record
}
$PreviousName = $rec{'Userid'}; $subtotal = 0;
}

$subtotal = $rec{'Amount'};

# Replace FieldName below with the names of the fields you want to display. Create as many table cells as you wish, one for each field.

print qq|
$rec{'Promotion'}</TD><TD>$rec{'Pdate'}</TD><TD>$rec{'Userid'}</TD><td>$rec{'Amount'}|;
if ($rec{'Bump'} =~ "Yes") {
print qq| &nbsp;<font color="red"> Bump</font>|;
}
print qq|</td>
<TD>$rec{'Bump'}</TD><TD>$rec{'Collected_date'}</TD><TD>$rec{'Week'}</TD><TD>$rec{'Memorabilia'}</TD><TD>$rec{'Payment'}</TD><TD>$rec{'Tap'}</TD><TD>$rec{'Company'}</TD><TD>$rec{'Special_Inst'}</TD> |;

# I removed the 3 green line of code below.

$total_field = $rec{'Amount'};

$total_field =~ s/\$//./,/gi;

$Pagetotal += $total_field;

}

/////end of code/////

When the report is generated this is what it looks likes:

/////report/////

see the attached file. I could not get the report to paste correctly.

/////end report/////

If you'll notice it dose not group each sale rep's (bgoldman, elevy, njones) together and it only totals the last amount.

One other thing, this code " $subtotal = $rec{'Amount'}; " had a plus sign (+) in it " $subtotal += $rec{'Amount'}; "
when the + was there instead of a total of $100.00 I would get .00.

I removed the green code because I did not need it in this report.

Thanks
Ed--
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
oops. the line:

$subtotal = $rec{'Amount'};

should be

$subtotal = $subtotal + $rec{'Amount'};

it may work with += ; i've just never used that. now i'm going to take a look at your report.

did you make my changes to add the sort field (sb) in the search form? no way this will ever work without establishing that!
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
did you make my changes to add the sort field (sb) in the search form? no way this will ever work without establishing that!

Yes I did.
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
i can see from your attached report that it is not sorting by userid. are you using the multiple sort fields hack? if so, change sb to sb1.

try setting the sort field on the search form for the report.
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
turn on debug and look at the form variables. see if you have sb, sb1, etc
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
I turned on the debug.
The only thing you can do in the report program is view, view reports of different types.

I sent you a PM with your login information so you can go and see what is going on.

Below is the code for each part of the subroutine with the changes made. Your changes are in red.

///// Code /////

sub html_rep_report {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_;

my ($colspan) = '11'; #number of columns in the report minus one

print qq|<TD>|;

### this section needs to precede the record
if ($rec{'Userid'} ne $PreviousName) {
if ($PreviousName) {
print qq|-----------------$subtotal</td><td colspan=$colspan></td></tr>
<tr><td>|; # this prints the subtotal and starts new table row for the record
}
$PreviousName = $rec{'Userid'}; $subtotal = 0;
}

$subtotal = $subtotal + $rec{'Amount'};



# Replace FieldName below with the names of the fields you want to display. Create as many table cells as you wish, one for each field.

print qq|
$rec{'Promotion'}</TD><TD>$rec{'Pdate'}</TD><TD>$rec{'Userid'}</TD><td>$rec{'Amount'}|;
if ($rec{'Bump'} =~ "Yes") {
print qq| &nbsp;<font color="red"> Bump</font>|;
}
print qq|</td>
<TD>$rec{'Bump'}</TD><TD>$rec{'Collected_date'}</TD><TD>$rec{'Week'}</TD><TD>$rec{'Memorabilia'}</TD><TD>$rec{'Payment'}</TD><TD>$rec{'Tap'}</TD><TD><a HREF="$db_script_www/cgi-bin/master/db.cgi?db=default&uid=$in{'uid'}&ID2=&Date=&Company=$rec{'Company'}&keyword=&mh=10&sb=---&so=ascend&view_records=1" target="_blank">$rec{'Company'}</a></TD><TD>$rec{'Special_Inst'}</TD> |;


}




##########################################################
## View Rep Report ##
##########################################################

sub html_view_rep_report_search {
# --------------------------------------------------------
# This page is displayed when a user requests to search the
# database for viewing.
# Note: all searches must use GET method.
#
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search the Database.</title>
</head>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=300,width=400,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>

<body bgcolor="#e0e0d6">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="sb" value="Userid">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search the Database</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Search the Database
</b></font></center><br>
|; &html_record_form(); print qq|
<center>|; &html_search_options; print qq|</center>
<p><center> <INPUT TYPE="SUBMIT" NAME="view_rep_report" VALUE="Sales Rep Report"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|;
if ($per_admin) {
print qq|
<p><center><INPUT TYPE="SUBMIT" NAME="export_records" VALUE="Export Results"></center></p>|; print qq| |;
}
else {
print qq|<input type="hidden" NAME="export_records">|;
}
print qq|
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}

sub html_view_rep_report_success {
# --------------------------------------------------------
# This page displays the results of a successful search.
# in a spreadsheet format.
# You can use the following variables when displaying your
# results:
#
# $numhits - the number of hits in this batch of results.
# $maxhits - the max number of hits displayed.
# $db_total_hits - the total number of hits.
# $db_next_hits - html for displaying the next set of results.
#
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search Results.</title>

</head>

<body bgcolor="#FFFFFF">
<blockquote>
<center><table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td colspan=2 bgcolor="navy"><FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search Results</b>
</font></td></tr>
</table>
<p><$font>
Your search returned <b>$db_total_hits</b> matches.</font></center>
|;
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
# Go through each hit and convert the array to hash and send to
# html_record for printing.
$new_url = $ENV{'QUERY_STRING'};
$new_url =~ s/\&sb=\d+//;
$new_url =~ s/\&so=\w+//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb'} == $col) {
if ($in{'so'} eq 'descend') { $sb[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}

# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places within each line.
print qq|
<TABLE cellpadding=1 cellspacing=8 width=1700>
|;

for (0 .. $numhits - 1) {
print "<TR>";
&html_rep_report (&array_to_hash($_, @hits));

print "</TR>\n";
}
print "</TABLE>";

if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

print "";
print qq|
<p>
<center><table border=0 bgcolor="#ffffff" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td>|; &html_footer; print qq|</td></tr>
</table></center>
</blockquote>
</body>
</html>
|;
}

sub html_view_rep_report_failure {
# --------------------------------------------------------
# The search for viewing failed. The reason is stored in $message
# and a new search form is printed out.

my ($message) = $_[0];
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search Failed.</title>
</head>

<body bgcolor="#e0e0d6">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="sb" value="Userid">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search Failed</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Search Failed
</b></font></center><br>
<P>There were problems with the search. Reason: <FONT COLOR="red"><B>$message</B></FONT>
<BR>Please fix any errors and submit the record again.</p>
|; &html_record_form(%in); print qq|
<center>|; &html_search_options; print qq|</center>
</p></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="view_rep_report" VALUE="Sales Rep Report"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}



///// Ende ofCode /////


Thank you,
Ed-
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
in the search form, you should remove my hidden sb field or remove the html_search_options which also contains select field for sb. don't want the same field twice.

why do you have the following in success sub:

# Go through each hit and convert the array to hash and send to
# html_record for printing.
$new_url = $ENV{'QUERY_STRING'};
$new_url =~ s/\&sb=\d+//;
$new_url =~ s/\&so=\w+//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb'} == $col) {
if ($in{'so'} eq 'descend') { $sb[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}


try commenting that out and see if it makes a difference. if not, upload your db.cgi file so i can see your complete query and sort routines.

when i went to View records the sorting worked fine so it must be something in the Report section causing problem.
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
Good news! I removed the hidden field, now the sort is working as it should. I'm not sure what the other code is for, but I tried it with and without and had the same results so I removed them as well.

The only thing now is the totals.

Thanks,

Ed

ps: how was the golf game?
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
if you have the following line, i don't see why the subtotals don't work:

$subtotal = $subtotal + $rec{'Amount'};

p.s. golf is bad! i think i've lost my swing.


Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
Sorry about the golf gameFrown.

I do have that line.

/////Code/////

my (%rec) = @_;

my ($colspan) = '11'; #number of columns in the report minus one

print qq|<TD>|;

### this section needs to precede the record
if ($rec{'Userid'} ne $PreviousName) {
if ($PreviousName) {
print qq|-----------------<br>Sales Rep $rec{'Userid'}: $subtotal</td><td colspan="5"></td></tr>
<tr><td>|; # this prints the subtotal and starts new table row for the record
}
$PreviousName = $rec{'Userid'}; $subtotal = 0;
}

$subtotal = $subtotal + $rec{'Amount'};


# Replace FieldName below with the names of the fields you want to display. Create as many table cells as you wish, one for each field.

print qq|
$rec{'Promotion'}</TD><TD>$rec{'Pdate'}</TD><TD>$rec{'Userid'}</TD><td>$rec{'Amount'}|;
if ($rec{'Bump'} =~ "Yes") {
print qq| &nbsp;<font color="red"> Bump</font>|;
}
print qq|</td>
<TD>$rec{'Bump'}</TD><TD>$rec{'Collected_date'}</TD><TD>$rec{'Week'}</TD><TD>$rec{'Memorabilia'}</TD><TD>$rec{'Payment'}</TD><TD>$rec{'Tap'}</TD><TD><a HREF="$db_script_www/cgi-bin/master/db.cgi?db=default&uid=$in{'uid'}&ID2=&Date=&Company=$rec{'Company'}&keyword=&mh=10&sb=---&so=ascend&view_records=1" target="_blank">$rec{'Company'}</a></TD><TD>$rec{'Special_Inst'}</TD> |;


}

///// End of Code /////
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
ok, add $subtotal in one of the TD cells so we can see it on each line, perhaps after $rec{'Promotion'}
Quote Reply
Re: [delicia] Totals and sub totals for sales report. In reply to
I added "$subtotal" after $rec{'Promotion'}. it put a "0" after softball. " Softball0 ".
Quote Reply
Re: [knue] Totals and sub totals for sales report. In reply to
please upload your code again. i looked at one of my other installations and this is exactly how i had it. instead of just the report routine, please upload the whole file. maybe save it as a txt file and upload as an attachment.