No self bills

This commit is contained in:
Phyks 2013-09-15 16:28:44 +02:00
parent 1a9acc5ece
commit da0a51f997
3 changed files with 52 additions and 45 deletions

1
TODO
View File

@ -1,7 +1,6 @@
* Don't cache the username * Don't cache the username
* JSON output => do index view * JSON output => do index view
* API * API
* Reattribute all invoices / paybacks to unknown user when deleting a user ?
* cf TODO in files * cf TODO in files
* French template * French template
* Favicon * Favicon

View File

@ -9,7 +9,8 @@
'unable_write_config'=>array('fr'=>'Impossible d\'écrire le fichier data/config.php. Vérifiez les permissions.', 'en'=>'Unable to write data/config.php file. Check permissions.'), 'unable_write_config'=>array('fr'=>'Impossible d\'écrire le fichier data/config.php. Vérifiez les permissions.', 'en'=>'Unable to write data/config.php file. Check permissions.'),
'negative_amount'=>array('fr'=>'Montant négatif non autorisé.', 'en'=>'Negative amount not allowed.'), 'negative_amount'=>array('fr'=>'Montant négatif non autorisé.', 'en'=>'Negative amount not allowed.'),
'template_error'=>array('fr'=>'Template non disponible.', 'en'=>'Template not available.'), 'template_error'=>array('fr'=>'Template non disponible.', 'en'=>'Template not available.'),
'unauthorized'=>array('fr'=>'Vous n\'avez pas le droit de faire cette action.', 'en'=>'You are not authorized to do that.') 'unauthorized'=>array('fr'=>'Vous n\'avez pas le droit de faire cette action.', 'en'=>'You are not authorized to do that.'),
'no_users'=>array('fr'=>'Vous devez ajouter au moins un autre utilisateur.', 'en'=>'You must add at least one more user beside you.')
); );
$localized = array( $localized = array(
@ -284,7 +285,7 @@
$users_in = $invoice->getUsersIn()->get(); $users_in = $invoice->getUsersIn()->get();
unset($users_in[$_GET['user_id']]); unset($users_in[$_GET['user_id']]);
if(empty($users_in)) if(empty($users_in) || array_keys($users_in) == array($invoice->getBuyer()))
$invoice->delete(); $invoice->delete();
else { else {
$invoice->setUsersIn($users_in); $invoice->setUsersIn($users_in);
@ -438,29 +439,34 @@
$tpl->assign('error', $errors['negative_amount'][LANG]); $tpl->assign('error', $errors['negative_amount'][LANG]);
} }
else { else {
$invoice = new Invoice(); if(array_keys($users_in) == array($current_user->getId())) {
$tpl->assign('error', $errors['no_users'][LANG]);
if(!empty($_POST['id']))
$invoice->setId($_POST['id']);
$invoice->setWhat($_POST['what']);
$invoice->setAmount($_POST['amount']);
$invoice->setBuyer($current_user->getId());
$invoice->setDate(0, int2ampm($_POST['date_hour']), $_POST['date_day'], $_POST['date_month'], $_POST['date_year']);
$invoice->setUsersIn($users_in);
$invoice->save();
// Clear the cache
$tmp_files = glob(raintpl::$cache_dir."*.rtpl.php");
if(is_array($tmp_files)) {
array_map("unlink", $tmp_files);
} }
else {
$invoice = new Invoice();
header('location: index.php?'.$get_redir); if(!empty($_POST['id']))
exit(); $invoice->setId($_POST['id']);
$invoice->setWhat($_POST['what']);
$invoice->setAmount($_POST['amount']);
$invoice->setBuyer($current_user->getId());
$invoice->setDate(0, int2ampm($_POST['date_hour']), $_POST['date_day'], $_POST['date_month'], $_POST['date_year']);
$invoice->setUsersIn($users_in);
$invoice->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?'.$get_redir);
exit();
}
} }
} }
else { else {
@ -524,7 +530,7 @@
break; break;
case 'confirm_payback': case 'confirm_payback':
if(!empty($_GET['from']) && !empty($_GET['to']) && !empty($_GET['invoice_id'])) { if(!empty($_GET['from']) && !empty($_GET['to']) && !empty($_GET['invoice_id']) && $_GET['from'] != $_GET['to']) {
if($_GET['to'] == $current_user->getId() || $current_user->getAdmin()) { if($_GET['to'] == $current_user->getId() || $current_user->getAdmin()) {
$invoice = new Invoice(); $invoice = new Invoice();
$invoice = $invoice->load(array('id'=>(int) $_GET['invoice_id']), true); $invoice = $invoice->load(array('id'=>(int) $_GET['invoice_id']), true);

View File

@ -60,31 +60,33 @@
{elseif condition="$value2 == 1"} {elseif condition="$value2 == 1"}
({$value2} guest) ({$value2} guest)
{/if} {/if}
- {if condition="$value1->getBuyer() != $key2"}
{if condition="$paybacks[$value1->getId()] === false || !in_array($key2, array_keys($paybacks[$value1->getId()]))"} -
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {if condition="$paybacks[$value1->getId()] === false || !in_array($key2, array_keys($paybacks[$value1->getId()]))"}
<a href="?do=confirm_payback&amp;from={$key2}&amp;to={$value1->getBuyer()}&amp;invoice_id={$value1->getId()}" title="Confirm payback">
{/if}
Remains {$value1->getAmountPerPerson($key2)} {$currency}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
</a>
{/if}
{else}
{if condition="$paybacks[$value1->getId()][$key2]->getAmount() == $value1->getAmountPerPerson($key2)"}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {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"> <a href="?do=confirm_payback&amp;from={$key2}&amp;to={$value1->getBuyer()}&amp;invoice_id={$value1->getId()}" title="Confirm payback">
{/if} {/if}
Paid Remains {$value1->getAmountPerPerson($key2)} {$currency}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
</a> </a>
{/if} {/if}
{else} {else}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} {if condition="$paybacks[$value1->getId()][$key2]->getAmount() == $value1->getAmountPerPerson($key2)"}
<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 condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
{/if} <a href="?do=delete_payback&amp;from={$key2}&amp;to={$value1->getBuyer()}&amp;invoice_id={$value1->getId()}" title="Delete payback">
Remains {$value1->getAmountPerPerson($key2) - $paybacks[$value1->getId()][$key2]->getAmount()}{$currency} {/if}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"} Paid
</a> {if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
</a>
{/if}
{else}
{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->getAmountPerPerson($key2) - $paybacks[$value1->getId()][$key2]->getAmount()}{$currency}
{if condition="$current_user->getId() == $value1->getBuyer() || $current_user->getAdmin()"}
</a>
{/if}
{/if} {/if}
{/if} {/if}
{/if} {/if}