From: Iain Patterson Date: Wed, 11 Sep 2013 14:45:11 +0000 (+0100) Subject: Additionally report orders by parcel contents. X-Git-Tag: 2013-09-11^0 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=6c0392caed936af1c4f3fba0c49beda59011f7d5;p=readifood.git Additionally report orders by parcel contents. Break down sizes of parcel into parcel contents. --- diff --git a/lib/report.php b/lib/report.php index 05ca904..2209d52 100644 --- a/lib/report.php +++ b/lib/report.php @@ -88,23 +88,45 @@ /* Fill in missing weeks. XXX */ for ($missing_week = $last_week + 1; $missing_week < $week; $missing_week++) { echo "\n"; - printf(" 0Week %d\n", $missing_week); + printf(" 0Week %d\n", $missing_week); echo "\n"; } echo "\n"; - printf(" %dWeek %d\n", $row->getCount(), $week); + printf(" %dWeek %d\n", $row->getCount(), $week); echo "\n"; $last_week = $week; } echo "\n"; - echo " $totalTotal\n"; + echo " $totalTotal\n"; echo "\n"; echo "\n"; } - function show_size_report(&$order_ids) { + function show_contents_report(&$order_ids, $parcel_size, $grand_total) { + global $parcel_sizes, $parcel_contents; + + $total = 0; + for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) { + $q = new OrderQuery; + $q->filterById($order_ids); + $q->where(sprintf("parcel & %d", $parcel_size)); + $q->where(sprintf("parcel & %d", (1 << $i))); + $contents = $q->find(); + $total += count($contents); + echo "\n"; + printf(" %d%s\n", count($contents), htmlspecialchars($parcel_contents[$i])); + echo "\n"; + } + + /* No special contents. */ + echo "\n"; + printf(" %d%s no special contents\n", $grand_total - $total, htmlspecialchars($parcel_sizes[$parcel_size >> 1])); + echo "\n"; + } + + function show_parcel_report(&$order_ids) { global $parcel_sizes; - echo "

Orders by parcel size

\n"; + echo "

Orders by parcel type

\n"; $q = new OrderQuery; $q->filterById($order_ids); @@ -117,12 +139,13 @@ foreach ($rows as $row) { echo "\n"; $requester = get_contact_by_id($row->getRequesterId()); - printf(" %d%s\n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1])); + printf(" %d%s\n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1])); $total += $row->getCount(); echo "\n"; + show_contents_report($order_ids, $row->getSize(), $row->getCount()); } echo "\n"; - echo " $totalTotal\n"; + echo " $totalTotal\n"; echo "\n"; echo "\n"; } @@ -141,12 +164,12 @@ foreach ($rows as $row) { echo "\n"; $requester = get_contact_by_id($row->getRequesterId()); - printf(" %d%s\n", $row->getCount(), htmlspecialchars($requester->getDisplayname())); + printf(" %d%s\n", $row->getCount(), htmlspecialchars($requester->getDisplayname())); $total += $row->getCount(); echo "\n"; } echo "\n"; - echo " $totalTotal\n"; + echo " $totalTotal\n"; echo "\n"; echo "\n"; } @@ -177,7 +200,7 @@ } show_order_report($order_state_ids); - show_size_report($order_ids); + show_parcel_report($order_ids); show_requester_report($order_ids); }