X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;ds=inline;f=lib%2Freport.php;h=b2bc16d2d4aa759974569439a498687c5b2f3797;hb=a1bc70f4ac65ec18d45b80c5c71b62d55dc363d3;hp=d8699d22691eedb88e5e6feac975652d3e34155d;hpb=6212910a5be1d531a46de21d04da4449a7145b32;p=readifood.git
diff --git a/lib/report.php b/lib/report.php
index d8699d2..b2bc16d 100644
--- a/lib/report.php
+++ b/lib/report.php
@@ -29,15 +29,9 @@
$oldest = date('Y-m-d', $date);
$then = $date;
- echo " to \n";
+ datepicker("from", $from, true, null, false, "to");
+ echo " to ";
+ datepicker("to", $to, true, "from", false);
submit("show_reports", "Show");
end_form();
@@ -75,15 +69,27 @@
$q->withColumn('count(*)', 'count');
$q->addGroupByColumn('week')->orderByUpdated();
$rows = $q->find();
+ $year_offset = 0;
$week_offset = 0;
$week = 1;
$last_week = 0;
$total = 0;
echo "
\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;
+ /*
+ Convert week of year to date range.
+ Beware that week 201401 comes after 201352.
+ */
+ $yearweek = $row->getWeek();
+ if (! $week_offset) {
+ $year_offset = substr($yearweek, 0, 4);
+ $week_offset = substr($yearweek, 4, 2) - 1;
+ }
+ else {
+ $y = substr($yearweek, 0, 4);
+ $w = substr($yearweek, 4, 2);
+ $week = (($y - $year_offset) * 52) + ($w - $week_offset);
+ }
$total += $row->getCount();
/* Fill in missing weeks. XXX */
for ($missing_week = $last_week + 1; $missing_week < $week; $missing_week++) {