\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 "
\n";
printf("
0
Week %d
\n", $missing_week);
echo "
\n";
}
echo "
\n";
printf("
%d
Week %d
\n", $row->getCount(), $week);
echo "
\n";
$last_week = $week;
}
echo "
\n";
echo "
$total
Total
\n";
echo "
\n";
echo "
\n";
}
function show_postcode_report(&$order_ids) {
echo "
Orders by postcode
\n";
/*
No regex replace support in MySQL so we'll have to retrieve all records
and group the postcodes ourselves.
*/
$q = new OrderQuery;
$q->filterById($order_ids);
$q->join("Beneficiary");
/* No foreign key so we need to list the two tables. */
$q->join("Beneficiary.Address");
/* Not a FoodOrder column so we need to ask for it explicitly. */
$q->withColumn('upper(postcode)', 'postcode');
$rows = $q->find();
$total = 0;
$postcodes = array();
foreach ($rows as $row) {
$postcode = preg_replace('/\s*[0-9][A-Z]+$/', '', trim($row->getPostcode()));
if (! $postcode) $postcode = "Unknown";
$postcodes[$postcode]++;
$total++;
}
ksort($postcodes);
echo "
\n";
foreach ($postcodes as $postcode => $count) {
echo "
\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();
$order_state_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();
$order_state_ids[] = $order_state->getId();
}
$q = new OrderQuery;
$q->filterById($order_ids);
if (! count($order_ids)) {
echo "