+ function show_order_report(&$order_state_ids) {
+ echo "<h3>Orders by week</h3>\n";
+
+ $q = new OrderStateQuery;
+ $q->filterById($order_state_ids);
+ $q->withColumn('yearweek(updated)', 'week');
+ $q->withColumn('count(*)', 'count');
+ $q->addGroupByColumn('week')->orderByUpdated();
+ $rows = $q->find();
+ $week_offset = 0;
+ $week = 1;
+ $last_week = 0;
+ $total = 0;
+ echo "<table class=\"report\">\n";
+ foreach ($rows as $row) {
+ /* Convert week of year to date range. */
+ if (! $week_offset) $week_offset = $row->getWeek() - 1;
+ else $week = $row->getWeek() - $week_offset;
+ $total += $row->getCount();
+ /* Fill in missing weeks. XXX */
+ for ($missing_week = $last_week + 1; $missing_week < $week; $missing_week++) {
+ echo "<tr>\n";
+ printf(" <td>0</td><td>Week %d</td>\n", $missing_week);
+ echo "</tr>\n";
+ }
+ echo "<tr>\n";
+ printf(" <td>%d</td><td>Week %d</td>\n", $row->getCount(), $week);
+ echo "</tr>\n";
+ $last_week = $week;
+ }
+ echo "<tr>\n";
+ echo " <td class=\"strong\">$total</td><td class=\"strong\">Total</td>\n";
+ echo "</tr>\n";
+ echo "</table>\n";
+ }
+