From: Iain Patterson Date: Tue, 23 Jul 2013 21:33:25 +0000 (+0100) Subject: Report orders by requester. X-Git-Tag: 2013-09-11~5 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=fe9ea062f81d87aa972dfddcd70762108ead2cce;p=readifood.git Report orders by requester. --- diff --git a/lib/report.php b/lib/report.php index e74ac07..4a632f8 100644 --- a/lib/report.php +++ b/lib/report.php @@ -66,10 +66,47 @@ return true; } + function show_requester_report(&$order_ids) { + echo "

Orders by referrer

\n"; + + $q = new OrderQuery; + $q->filterById($order_ids); + $q->withColumn('count(*)', 'count'); + $q->groupByRequesterId()->addDescendingOrderByColumn('count'); + $rows = $q->find(); + echo "\n"; + /* XXX Join! */ + foreach ($rows as $row) { + echo "\n"; + $requester = get_contact_by_id($row->getRequesterId()); + printf(" \n", $row->getCount(), htmlspecialchars($requester->getDisplayname())); + echo "\n"; + } + echo "
%d %s
\n"; + } + function show_reports($from, $to) { if (! check_report_dates($from, $to)) return; echo "

Showing reports for the period $from to $to.

\n"; + + /* Get orders. */ + $order_ids = array(); + /* XXX: Order 51 changed to state delivered in May then updated in June. */ + $dbh = Propel::getConnection(); + $sth = $dbh->prepare("select * from OrderState o where updated=(select min(updated) from OrderState where order_id=o.order_id and state & " . $GLOBALS['STATE_DELIVERED'] . ") and updated between '$from' and '$to'"); + $sth->execute(); + $order_states = OrderStatePeer::populateObjects($sth); + foreach ($order_states as $order_state) $order_ids[] = $order_state->getOrderId(); + $q = new OrderQuery; + $q->filterById($order_ids); + + if (! count($order_ids)) { + echo "

No results!

\n"; + return; + } + + show_requester_report($order_ids); } if (count($parameters)) {