From: Iain Patterson Date: Sun, 2 Sep 2018 22:05:02 +0000 (-0400) Subject: Show unique beneficiary report. X-Git-Tag: live-2018-09-09~1 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=0b94585002cca126b1e0734763bda47a0b71f3ac;p=readifood.git Show unique beneficiary report. Count unique recipients of at least one parcel of each size during the report period. For example if a beneficiary received three "Couple" sized parcels we would count two individuals. Family units are averaged at four individuals since we do not record their actual size anywhere. --- 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(" \n", $row->getCount(), htmlspecialchars($parcel_sizes[$row->getSize() >> 1])); + if ($row->getSize() > 1) { + echo "\n"; + printf(" \n", $count, $row->getSize() > 2 ? ' (estimated)' : ''); + echo "\n"; + } + $total += $count; + echo "\n"; + } + echo "\n"; + echo " \n"; + echo "\n"; + echo "
%d%s
%dindividuals%s
$totalTotal individuals (estimated)
\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); }