Hi,
I maintain a small hours registration database for a couple of freelancers. On the view_succes page I inserted a box with totals for a search action in the database. It works, but only when I'm not searching for either field 7 or field 1 in view_search. In these cases a value of 0 is returned, when it should be 'hours * fee = total fee'.
Basically, I want to calculate how many hours (stored in field 1) each freelancer (stored in field 7) has worked, and then multiply the totalled working hours by each freelancer's hour fee (hardcoded, not stored in the database). I only need it for printing, nothing needs to be stored in the db.
# begin totalen
# change the values below to match the field numbers of your name and amount fields
$Door = 7;
$Uren = 1;
for (0 .. $numhits - 1) {
$name = $hits[$_ * ($#db_cols+1) + $Door];
$amount = $hits[$_ * ($#db_cols+1) + $Uren];
if ($name eq "A") {
$amount2 = $amount * 20;
}
elsif ($name eq "B") {
$amount2 = $amount * 18;
}
elsif ($name eq 'C') {
$amount2 = $amount * 21;
}
elsif ($name eq 'D') {
$amount2 = $amount * 17;
}
$total{$name} += $amount;
$total_bedrag{$name} += $amount2;
$grand_total += $amount;
$grand_total_bedrag += $amount2;
}
foreach $key (sort keys %total) {
print qq|
<tr><td>
<$font><b>$key</b></font>
</td><td>
<$font>$total{$key}</font>
</td><td><$font>$total_bedrag{$key},-</font>
</td></tr>
|;
}
print qq|
<tr><td colspan=3>
======================
</td></tr>
<td><$font>
<b>Totaal</b></font>
</td>
<td>
<$font>$grand_total</font>
</td>
<td>
<$font>$grand_total_bedrag,-</font>
</td></tr>
</table>
|;
# einde totalen
T.i.a., peter
I maintain a small hours registration database for a couple of freelancers. On the view_succes page I inserted a box with totals for a search action in the database. It works, but only when I'm not searching for either field 7 or field 1 in view_search. In these cases a value of 0 is returned, when it should be 'hours * fee = total fee'.
Basically, I want to calculate how many hours (stored in field 1) each freelancer (stored in field 7) has worked, and then multiply the totalled working hours by each freelancer's hour fee (hardcoded, not stored in the database). I only need it for printing, nothing needs to be stored in the db.
Code:
# begin totalen
# change the values below to match the field numbers of your name and amount fields
$Door = 7;
$Uren = 1;
for (0 .. $numhits - 1) {
$name = $hits[$_ * ($#db_cols+1) + $Door];
$amount = $hits[$_ * ($#db_cols+1) + $Uren];
if ($name eq "A") {
$amount2 = $amount * 20;
}
elsif ($name eq "B") {
$amount2 = $amount * 18;
}
elsif ($name eq 'C') {
$amount2 = $amount * 21;
}
elsif ($name eq 'D') {
$amount2 = $amount * 17;
}
$total{$name} += $amount;
$total_bedrag{$name} += $amount2;
$grand_total += $amount;
$grand_total_bedrag += $amount2;
}
foreach $key (sort keys %total) {
print qq|
<tr><td>
<$font><b>$key</b></font>
</td><td>
<$font>$total{$key}</font>
</td><td><$font>$total_bedrag{$key},-</font>
</td></tr>
|;
}
print qq|
<tr><td colspan=3>
======================
</td></tr>
<td><$font>
<b>Totaal</b></font>
</td>
<td>
<$font>$grand_total</font>
</td>
<td>
<$font>$grand_total_bedrag,-</font>
</td></tr>
</table>
|;
# einde totalen
T.i.a., peter

