Index page almost done. TODO : balance table

This commit is contained in:
Phyks 2013-09-12 18:44:04 +02:00
parent 4824b05219
commit 3696a6566a
4 changed files with 25 additions and 8 deletions

4
TODO
View File

@ -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

View File

@ -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() {

View File

@ -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());

View File

@ -18,7 +18,7 @@
<tr>
<th>{$value->getDisplayName()}</th>
{loop="users"}
<td><a href="">{$value->getDisplayName()}</a></td>
<td>{$balances[$value1->getId()][$value2->getId()]}</td>
{/loop}
</tr>
{/loop}
@ -55,13 +55,12 @@
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
<a href="?do=confirm_payback&amp;from={$key2}&amp;to={$value1->getBuyer()}&amp;invoice_id={$value1->getId()}" title="Confirm payback">
{/if}
Remains {$value1->getAmount()} {$currency}
Remains {$value1->getAmountPerPerson()} {$currency}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
</a>
{/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()"}
<a href="?do=delete_payback&amp;from={$key2}&amp;to={$value1->getBuyer()}&amp;invoice_id={$value1->getId()}" title="Delete payback">
{/if}
@ -73,7 +72,7 @@
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
<a href="?do=confirm_payback&amp;from={$key2}&amp;to={$value1->getBuyer()}&amp;invoice_id={$value1->getId()}&amp;payback_id={$paybacks[$value1->getId()][$key2]->getId()}" title="Confirm payback">
{/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()"}
</a>
{/if}