X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;ds=inline;f=lib%2Freport.php;fp=lib%2Freport.php;h=5ed0fae69aba30974005c206cb060df333faf324;hb=097fa2613bbc37d9573fda5095cc17e58fe19ed9;hp=aa9e6e53ca28ac0e1e0965eddb6aa3b7b5b00bcf;hpb=ae839ebaa4e1e0ae4cee28c16cc0bc7a0368f4af;p=readifood.git
diff --git a/lib/report.php b/lib/report.php
index aa9e6e5..5ed0fae 100644
--- a/lib/report.php
+++ b/lib/report.php
@@ -171,6 +171,37 @@
echo "\n";
}
+ function show_beneficiary_report(&$order_ids) {
+ global $parcel_sizes;
+ echo "
Unique beneficiaries
\n";
+
+ $q = new OrderQuery;
+ $q->filterById($order_ids);
+ $q->withColumn(sprintf("parcel & %d", (1 << count($parcel_sizes)) - 1), 'size');
+ $q->withColumn('count(distinct beneficiary_id)', 'count');
+ $q->addGroupByColumn('size')->addAscendingOrderByColumn('size');
+ $rows = $q->find();
+ $total = 0;
+ echo "\n";
+ foreach ($rows as $row) {
+ echo "\n";
+ /* This is only correct if we assume the sizes are 1 (single), 2 (couple) and 4 (family). */
+ $count = $row->getSize() * $row->getCount();
+ printf(" %d | %s | \n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1]));
+ if ($row->getSize() > 1) {
+ echo "
\n";
+ printf(" %d | individuals%s | \n", $count, $row->getSize() > 2 ? ' (estimated)' : '');
+ echo "
\n";
+ }
+ $total += $count;
+ echo "\n";
+ }
+ echo "\n";
+ echo " $total | Total individuals (estimated) | \n";
+ echo "
\n";
+ echo "
\n";
+ }
+
function show_requester_report(&$order_ids) {
echo "Orders by referrer
\n";
@@ -226,6 +257,7 @@
show_order_report($from, $order_state_ids);
show_postcode_report($order_ids);
show_parcel_report($order_ids);
+ show_beneficiary_report($order_ids);
show_requester_report($order_ids);
}