diff --git a/TODO b/TODO index 28997a5..6ffacc9 100755 --- a/TODO +++ b/TODO @@ -2,12 +2,10 @@ * JSON output => do index view * API * Reattribute all invoices / paybacks to unknown user when deleting a user ? -* Check that all is ok when deleting an invoice -* Use PHP constant in tpl instead of variables * User groups * cf TODO in files Manage paybacks : ================= -* TODO : Payback system (class should be ok) +* TODO : Index balance table * TODO : Global payback diff --git a/inc/Invoices.class.php b/inc/Invoices.class.php index 3e37472..b7fe77e 100644 --- a/inc/Invoices.class.php +++ b/inc/Invoices.class.php @@ -85,6 +85,12 @@ $this->users_in->set($users_in); } + // Get the amount to pay by person + // =============================== + public function getAmountPerPerson() { + return round($this->amount / count($this->users_in->get()), 2); + } + // Maps htmlspecialchars on the class before display // ================================================= public function secureDisplay() { diff --git a/index.php b/index.php index 929b32f..a3db930 100644 --- a/index.php +++ b/index.php @@ -569,9 +569,23 @@ $paybacks[$invoice->getId()] = $paybacks[$invoice->getId()]->load(array('invoice_id'=>$invoice->getId()), false, 'from_user'); } + $balances = array(); + foreach($users_list as $user1) { + foreach($users_list as $user2) { + if($user1->getId() == $user2->getId()) { + $balances[$user1->getId()][$user2->getId()] = 'X'; + } + else { + // TODO : Balances between users + $balances[$user1->getId()][$user2->getId()] = ''; + } + } + } + $tpl->assign('users', secureDisplay($users_list)); $tpl->assign('invoices', secureDisplay($invoices_list)); $tpl->assign('paybacks', secureDisplay($paybacks)); + $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()); diff --git a/tpl/default_en/index.html b/tpl/default_en/index.html index c9e98c3..5d1c96b 100755 --- a/tpl/default_en/index.html +++ b/tpl/default_en/index.html @@ -18,7 +18,7 @@ {$value->getDisplayName()} {loop="users"} - {$value->getDisplayName()} + {$balances[$value1->getId()][$value2->getId()]} {/loop} {/loop} @@ -55,13 +55,12 @@ {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {/if} - Remains {$value1->getAmount()} {$currency} + Remains {$value1->getAmountPerPerson()} {$currency} {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {/if} {else} - {* TODO : partial payback *} - {if condition="$paybacks[$value1->getId()][$key2]->getAmount() == $value1->getAmount()"} + {if condition="$paybacks[$value1->getId()][$key2]->getAmount() == $value1->getAmountPerPerson()"} {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {/if} @@ -73,7 +72,7 @@ {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {/if} - Remains {$value1->getAmount() - $paybacks[$value1->getId()][$key2]->getAmount()}{$currency} + Remains {$value1->getAmountPerPerson() - $paybacks[$value1->getId()][$key2]->getAmount()}{$currency} {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {/if}