Link to confirm all paybacks between two people

This commit is contained in:
Phyks 2013-09-15 16:55:22 +02:00
parent 1a9f2429b1
commit d9e9e32249
3 changed files with 72 additions and 5 deletions

2
TODO
View File

@ -4,8 +4,6 @@
* cf TODO in files * cf TODO in files
* French template * French template
* Favicon * Favicon
* Take account of paybacks in balance table
* Confirm all paybacks
Improvements : Improvements :
============== ==============

View File

@ -602,14 +602,81 @@
exit(); exit();
} }
else { else {
$tpl->assign('error', $errors['unauthorized']); header('location: index.php');
$tpl->draw('index'); exit();
} }
} }
else { else {
header('location: index.php'); header('location: index.php');
exit(); exit();
} }
break;
case 'payall':
if(!empty($_GET['from']) && !empty($_GET['to'])) {
if($_GET['to'] == $current_user->getId() || $current_user->getAdmin()) {
// Confirm all paybacks when to is buyer
$invoices = new Invoice();
$invoices = $invoices->load(array('buyer'=>(int) $_GET['to']));
if($invoices !== false) {
foreach($invoices as $invoice) {
$paybacks = new Payback();
$paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>(int) $_GET['to'], 'from_user'=>(int) $_GET['from']));
if($paybacks === false) {
$payback = new Payback();
$payback->setTo($_GET['to']);
$payback->setFrom($_GET['from']);
$payback->setAmount($invoice->getAmountPerPerson($_GET['from']));
$payback->setInvoice($invoice->getId());
$payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
$payback->save();
}
}
}
// Confirm all paybacks when from is buyer
$invoices = new Invoice();
$invoices = $invoices->load(array('buyer'=>(int) $_GET['from']));
if($invoices !== false) {
foreach($invoices as $invoice) {
$paybacks = new Payback();
$paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>(int) $_GET['from'], 'from_user'=>(int) $_GET['to']));
if($paybacks === false) {
$payback = new Payback();
$payback->setTo($_GET['from']);
$payback->setFrom($_GET['to']);
$payback->setAmount($invoice->getAmountPerPerson($_GET['to']));
$payback->setInvoice($invoice->getId());
$payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
$payback->save();
}
}
}
// Clear the cache
$tmp_files = glob(raintpl::$cache_dir."*.rtpl.php");
if(is_array($tmp_files)) {
array_map("unlink", $tmp_files);
}
header('location: index.php');
exit();
}
else {
header('location: index.php');
exit();
}
}
else {
header('location: index.php');
exit();
}
break;
default: default:

View File

@ -20,8 +20,10 @@
{loop="users"} {loop="users"}
{if condition="$balances[$value1->getId()][$value2->getId()] === 'X'"} {if condition="$balances[$value1->getId()][$value2->getId()] === 'X'"}
<td class="cell-disabled"></td> <td class="cell-disabled"></td>
{else} {elseif condition="$balances[$value1->getId()][$value2->getId()] === '-' || ($value2->getId() != $current_user->getId() && !$current_user->getAdmin())"}
<td>{$balances[$value1->getId()][$value2->getId()]}</td> <td>{$balances[$value1->getId()][$value2->getId()]}</td>
{else}
<td><a href="?do=payall&amp;from={$value1->getId()}&amp;to={$value2->getId()}">{$balances[$value1->getId()][$value2->getId()]}</a></td>
{/if} {/if}
{/loop} {/loop}
</tr> </tr>