<?php
/**
* Output Coupon Reports
*/
function uc_coupon_reports($start = null, $end = null) {
drupal_add_css(drupal_get_path('module', 'uc_coupon') .'/reports.css', 'uc_coupon');
$output .= drupal_get_form('uc_coupon_reports_form', $start, $end);
// gather all the coupon data from the time period specified
if (isset($start) && isset($end)) {
$query = db_query("SELECT co.cid, co.oid, co.value, co.code, o.order_total, o.created FROM {uc_coupons_orders} AS co LEFT JOIN {uc_orders} AS o ON (co.oid = o.order_id) WHERE o.order_status > 0 AND o.created > %d AND o.created < %d ORDER BY co.cid, o.created ASC",$start, $end);
$row_header = array('Order #', 'Date Purchased', 'Order Value', 'Coupon Value');
$last_cid = 0;
while ($row = db_fetch_object($query)) {
// Display the table of coupons if this is the next set of coupons
if ($row->cid != $last_cid AND $last_cid != 0) {
$td[] = array('', '<b>Uses: '. $num_uses .'</b>', '<b>$'. number_format($coupon_sale_amount,2) .'</b>', '<b>$'. number_format($coupon_amount,2) .'</b>');
$data .= theme('table', $row_header, $td, array('width' => '100%'));
$td = array();
$num_uses = 0;
$coupon_amount = 0;
$coupon_sale_amount = 0;
}
// if this is the first coupon of the set display the header first
if ($row->cid != $last_cid || $last_cid = 0) {
$data .= '<div class="totals"> Coupon Code: '.l($row->code,'admin/store/customers/coupon/'. $row->cid . '/edit') .'</div>';
}
$td[] = array(l('#'. $row->oid, 'admin/store/orders/'. $row->oid), date('m/d/Y', $row->created), '$'. number_format($row->order_total, 2), '$'. number_format($row->value,2));
$num_uses++;
$coupon_amount += $row->value;
$coupon_sale_amount += $row->order_total;
$last_cid = $row->cid;
$orders_total += $row->order_total;
$coupons_total += $row->value;
}
$td[] = array('', '<b>Uses: '. $num_uses .'</b>', '<b>$'. number_format($coupon_sale_amount,2) .'</b>', '<b>$'. number_format($coupon_amount,2) .'</b>');
$data .= theme('table', $row_header, $td, array('width' => '100%'));
$output .= '<h2>Coupon Usage report</h2>';
$output .= $data;
$output .= '<br><table width="100%"><tr><td></td><td><b>Coupons Used: '. db_num_rows($query) .'</td><td>Orders Value: $'. $orders_total .'</td><td>Coupons Value: $'. $coupons_total .'</tr></tr></table>';
}
return $output;
}
?>Full Texts cuid cid oid value user role code
Edit Delete 1 18 27 85.00 0 0 code1
Edit Delete 2 56 75 44.00 0 0 code2
Edit Delete 3 61 76 29.70 0 0 code3
Edit Delete 4 63 82 49.00 0 0 code4
Edit Delete 5 63 83 49.00 0 0 code5
Edit Delete 6 64 85 49.00 0 0 code6
Edit Delete 7 64 88 49.00 0 0 code7
Edit Delete 8 63 90 49.00 0 0 code8
Edit Delete 9 63 91 49.00 0 0 code9this is my table of coupons used in orders and i also get a blnak page!!
Ok, we should get this done though without having to pay cash 
#1 start it with fixed dates
#2 alter the sql to basically just show them all to see where the error is, meaning a simple sql code to just show something from the one table
#3 then check if it still counts correct ...
Post your results here!



Joined: 09/06/2007