New Zenner
- Join Date:
- Dec 2005
- Location:
- Littleton, CO
- Posts:
- 26
- Plugin Contributions:
- 0
Customers Referral Report enhancement - Here's mine
I have a new customer who needs to pay commissions based on referrals each month, and rather than make him sit down with a calculator, I added totals to the Customers Referral Report.
(HOW to get referrals working based on Discount Coupons is not what I discuss here. There are already a million threads on this.)
WARNING: I am NOT a PHP programmer, so this is quick, sloppy, and dirty!
I hope others find this useful.
Backup then edit admin/stats_customers_referrals.php
Find this:
<?php
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
echo ' <tr>' . "\n" .
' <td align="left" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Text">' . $order->totals[$i]['title'] . '</td>' . "\n" .
' <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Amount">' . $order->totals[$i]['text'] . '</td>' . "\n" .
' </tr>' . "\n";
}
And add these lines before the final }:
if ($order->totals[$i]['title'] == 'Sub-Total:') {
$referral_subtotals += str_replace('$', '', $order->totals[$i]['text']);
}
if (eregi("Discount Coupon:*", $order->totals[$i]['title'])) {
$referral_discounts += str_replace('$', '', $order->totals[$i]['text']);
}
So now you have:
<?php
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
echo ' <tr>' . "\n" .
' <td align="left" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Text">' . $order->totals[$i]['title'] . '</td>' . "\n" .
' <td align="right" class="'. str_replace('_', '-', $order->totals[$i]['class']) . '-Amount">' . $order->totals[$i]['text'] . '</td>' . "\n" .
' </tr>' . "\n";
if ($order->totals[$i]['title'] == 'Sub-Total:') {
$referral_subtotals += str_replace('$', '', $order->totals[$i]['text']);
}
if (eregi("Discount Coupon:*", $order->totals[$i]['title'])) {
$referral_discounts += str_replace('$', '', $order->totals[$i]['text']);
}
}
So those are the computations. Now, to print the results.... Directly after:
<?php
$customers_orders->MoveNext();
}
?>
Add:
<?php
echo '<tr><td></td></tr> <tr><td></td></tr>' . "\n";
echo '<tr><td>Referral Subtotals: ' . $referral_subtotals . '</td></tr>' . "\n";
echo '<tr><td>Referral Discounts: ' . $referral_discounts . '</td></tr>' . "\n";
$referral_total = $referral_subtotals + $referral_discounts;
echo '<tr><td>Referral Subtotals minus Discounts: $' . $referral_total . '</td></tr>' . "\n";
?>
So now you have:
<?php
$customers_orders->MoveNext();
}
?>
<?php
echo '<tr><td></td></tr> <tr><td></td></tr>' . "\n";
echo '<tr><td>Referral Subtotals: ' . $referral_subtotals . '</td></tr>' . "\n";
echo '<tr><td>Referral Discounts: ' . $referral_discounts . '</td></tr>' . "\n";
$referral_total = $referral_subtotals + $referral_discounts;
echo '<tr><td>Referral Subtotals minus Discounts: $' . $referral_total . '</td></tr>' . "\n";
?>
Josh
185 Performance