From ccb89358bfce63d7b2c2af94f78ecf362e9976b3 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 15 Sep 2013 15:28:27 +0200 Subject: [PATCH] List of bills working on index page --- TODO | 7 +++++-- inc/Storage.class.php | 26 ++++++++++++++++---------- index.php | 16 +++++++++++++--- tpl/default_en/header.html | 1 - tpl/default_en/index.html | 8 +++++++- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/TODO b/TODO index 0e9e95c..682a3bb 100755 --- a/TODO +++ b/TODO @@ -2,11 +2,14 @@ * JSON output => do index view * API * Reattribute all invoices / paybacks to unknown user when deleting a user ? -* User groups * cf TODO in files * French template * Favicon -* Dépenses du dernier mois + +Improvements : +============== +* User groups +* Search invoice Manage paybacks : ================= diff --git a/inc/Storage.class.php b/inc/Storage.class.php index 78eab6c..6e68714 100644 --- a/inc/Storage.class.php +++ b/inc/Storage.class.php @@ -124,18 +124,22 @@ class Storage { $value = array($value); } - foreach($value as $value_array) { + foreach($value as $key=>$value_array) { if($value_array == 'AND' || $value_array == 'OR') { $query .= ' '.$value_array.' '; continue; } - if(substr($value_array, 0, 1) == "<") - $query .= $field.'<:'.$field; + if(substr($value_array, 0, 2) == "<=") + $query .= $field.'<=:'.$field.$key; + elseif(substr($value_array, 0, 1) == "<") + $query .= $field.'<:'.$field.$key; + elseif(substr($value_array, 0, 2) == ">=") + $query .= $field.'>=:'.$field.$key; elseif(substr($value_array, 0, 1) == ">") - $query .= $field.'>:'.$field; + $query .= $field.'>:'.$field.$key; else - $query .= $field.'=:'.$field; + $query .= $field.'=:'.$field.$key; } } } @@ -150,14 +154,16 @@ class Storage { if($fields[$field] == 'date') $value = $value->format('Y-m-d H:i:s'); - foreach($value as $value_array) { + foreach($value as $key=>$value_array) { if($value_array == 'AND' || $value_array == 'OR') continue; - if(substr($value_array, 0, 1) == ">" || substr($value_array, 0, 1) == "<") - $query->bindValue(':'.$field, substr($value_array, 0, 1)); - else - $query->bindValue(':'.$field, $value_array); + if(substr($value_array, 0, 2) == ">=" || substr($value_array, 0, 2) == "<=") + $value_array = substr($value_array, 2); + elseif(substr($value_array, 0, 1) == ">" || substr($value_array, 0, 1) == "<") + $value_array = substr($value_array, 1); + + $query->bindValue(':'.$field.$key, $value_array); } } } diff --git a/index.php b/index.php index db1ef6e..831f766 100644 --- a/index.php +++ b/index.php @@ -606,8 +606,11 @@ default: + if(empty($_GET['all'])) + $_GET['all'] = 0; + // Display cached page in priority - if($cache = $tpl->cache('index', $expire_time = 600, $cache_id = $current_user->getLogin())) { + if($cache = $tpl->cache('index', $expire_time = 600, $cache_id = $current_user->getLogin().$_GET['all'])) { echo $cache; } else { @@ -615,7 +618,14 @@ $users_list = $users_list->load(); $invoices_list = new Invoice(); - $invoices_list = $invoices_list->load(); + if(empty($_GET['all'])) { + $invoices_list = $invoices_list->load(array('date'=>array('>='.date('Y-m').'-01 00:00:00', 'AND', '<='.date('Y-m').'-31 23:59:59'))); + $tpl->assign('all', 0); + } + else { + $invoices_list = $invoices_list->load(); + $tpl->assign('all', 1); + } if($invoices_list === false) $invoices_list = array(); @@ -678,7 +688,7 @@ $tpl->assign('balances', secureDisplay($balances)); // Cache the page (1 month to make it almost permanent and only regenerate it upon new invoice) - $tpl->cache('index', 108000, $current_user->getLogin()); + $tpl->cache('index', 108000, $current_user->getLogin().$_GET['all']); $tpl->draw('index'); break; diff --git a/tpl/default_en/header.html b/tpl/default_en/header.html index 81fc213..18fc71b 100755 --- a/tpl/default_en/header.html +++ b/tpl/default_en/header.html @@ -4,7 +4,6 @@ {$instance_title} - diff --git a/tpl/default_en/index.html b/tpl/default_en/index.html index 209ddb6..8fdeab4 100755 --- a/tpl/default_en/index.html +++ b/tpl/default_en/index.html @@ -29,7 +29,13 @@
-

Detailed list of bills for last month

+

Detailed list of bills{if condition="$all == 0"} for last month{/if}

+ + {if condition="$all == 0"} +

Display all bills

+ {else} +

Only display bills for last month

+ {/if} {if condition="$invoices !== false && count($invoices)>=1"}