Fix issue #9 + global payback
TODO : * Finish to fix globals paybacks * Bad handling of cents when paying back… :/
This commit is contained in:
parent
500befcae8
commit
185a3f831c
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
// Get the amount to pay by person
|
// Get the amount to pay by person
|
||||||
// ===============================
|
// ===============================
|
||||||
public function getAmountPerPerson($id) {
|
public function getAmountPerPerson($id, $round = true) {
|
||||||
$users_in = $this->users_in->get();
|
$users_in = $this->users_in->get();
|
||||||
$guests = 0;
|
$guests = 0;
|
||||||
|
|
||||||
@ -97,8 +97,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Amount is stored in cents
|
// Amount is stored in cents
|
||||||
|
if($round) {
|
||||||
return (isset($users_in[(int) $id])) ? round($this->amount / 100 / (count($users_in) + $guests) * (1 + $users_in[(int) $id]), 2) : 0; // Note : $users_in[(int) $id] is the number of guests for user $id
|
return (isset($users_in[(int) $id])) ? round($this->amount / 100 / (count($users_in) + $guests) * (1 + $users_in[(int) $id]), 2) : 0; // Note : $users_in[(int) $id] is the number of guests for user $id
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return (isset($users_in[(int) $id])) ? $this->amount / 100 / (count($users_in) + $guests) * (1 + $users_in[(int) $id]) : 0; // Note : $users_in[(int) $id] is the number of guests for user $id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Maps htmlspecialchars on the class before display
|
// Maps htmlspecialchars on the class before display
|
||||||
// =================================================
|
// =================================================
|
||||||
|
37
index.php
37
index.php
@ -7,6 +7,7 @@
|
|||||||
'user_already_exists'=>array('fr'=>'Un utilisateur avec le même login ou nom d\'affichage existe déjà. Choisissez un login ou un nom d\'affichage différent.', 'en'=>'A user with the same login or display name already exists. Choose a different login or display name.'),
|
'user_already_exists'=>array('fr'=>'Un utilisateur avec le même login ou nom d\'affichage existe déjà. Choisissez un login ou un nom d\'affichage différent.', 'en'=>'A user with the same login or display name already exists. Choose a different login or display name.'),
|
||||||
'write_error_data'=>array('fr'=>'Le script ne peut pas écrire dans le dossier data/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in data/ dir, check permissions set on this folder.'),
|
'write_error_data'=>array('fr'=>'Le script ne peut pas écrire dans le dossier data/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in data/ dir, check permissions set on this folder.'),
|
||||||
'write_error_db_backups'=>array('fr'=>'Le script ne peut pas écrire dans le dossier db_backups/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in db_backup/ dir, check permissions set on this folder.'),
|
'write_error_db_backups'=>array('fr'=>'Le script ne peut pas écrire dans le dossier db_backups/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in db_backup/ dir, check permissions set on this folder.'),
|
||||||
|
'db_dump_failed'=>array('fr'=>'Échec de la sauvegarde de la base de données. Aucune modification n\'a eu lieu.', 'en'=>'Unable to dump the database. No changes were made.'),
|
||||||
'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.'),
|
||||||
@ -527,7 +528,10 @@
|
|||||||
|
|
||||||
$invoice->setWhat($_POST['what']);
|
$invoice->setWhat($_POST['what']);
|
||||||
$invoice->setAmount($_POST['amount']);
|
$invoice->setAmount($_POST['amount']);
|
||||||
|
|
||||||
|
if(empty($_POST['id']))
|
||||||
$invoice->setBuyer($current_user->getId());
|
$invoice->setBuyer($current_user->getId());
|
||||||
|
|
||||||
$invoice->setDate(0, int2ampm($_POST['date_hour']), $_POST['date_day'], $_POST['date_month'], $_POST['date_year']);
|
$invoice->setDate(0, int2ampm($_POST['date_hour']), $_POST['date_day'], $_POST['date_month'], $_POST['date_year']);
|
||||||
|
|
||||||
|
|
||||||
@ -903,8 +907,13 @@
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
system("mysqldump -q -h \"".MYSQL_HOST."\" -u \"".MYSQL_LOGIN."\" -p\"".MYSQL_PASSWORD."\" \"".MYSQL_DB."\" > db_backups/".date('d-m-Y_H:i'));
|
if(system(escapeshellcmd("mysqldump -q -h \"".MYSQL_HOST."\" -u \"".MYSQL_LOGIN."\" -p\"".MYSQL_PASSWORD."\" \"".MYSQL_DB."\" > db_backups/".date('d-m-Y_H:i'))) === FALSE) {
|
||||||
|
$tpl->assign('error', $errors['db_dump_failed'][LANG]);
|
||||||
|
$tpl->assign('block_error', true);
|
||||||
|
$tpl->draw('index');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
$users_in = array();
|
$users_in = array();
|
||||||
foreach($_POST['users_in'] as $user1_id) {
|
foreach($_POST['users_in'] as $user1_id) {
|
||||||
$user1_id = intval($user1_id);
|
$user1_id = intval($user1_id);
|
||||||
@ -1051,6 +1060,7 @@
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', $errors['token_error'][LANG]);
|
$tpl->assign('error', $errors['token_error'][LANG]);
|
||||||
$tpl->assign('block_error', true);
|
$tpl->assign('block_error', true);
|
||||||
@ -1130,7 +1140,7 @@
|
|||||||
$balances[$user1->getId()][$user2->getId()] = '-';
|
$balances[$user1->getId()][$user2->getId()] = '-';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$balances[$user1->getId()][$user2->getId()] = -round($balances[$user2->getId()][$user1->getId()], 2);
|
$balances[$user1->getId()][$user2->getId()] = -$balances[$user2->getId()][$user1->getId()];
|
||||||
$balances[$user2->getId()][$user1->getId()] = '-';
|
$balances[$user2->getId()][$user1->getId()] = '-';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1145,12 +1155,12 @@
|
|||||||
if($invoices_list_balances !== false) {
|
if($invoices_list_balances !== false) {
|
||||||
foreach($invoices_list_balances as $invoice) {
|
foreach($invoices_list_balances as $invoice) {
|
||||||
if($invoice->getUsersIn()->inUsersIn($user1->getId())) {
|
if($invoice->getUsersIn()->inUsersIn($user1->getId())) {
|
||||||
$balances[$user1->getId()][$user2->getId()] = round($balances[$user1->getId()][$user2->getId()] + $invoice->getAmountPerPerson($user1->getId()), 2);
|
$balances[$user1->getId()][$user2->getId()] = $balances[$user1->getId()][$user2->getId()] + $invoice->getAmountPerPerson($user1->getId(), false);
|
||||||
|
|
||||||
$payback_balance = new Payback();
|
$payback_balance = new Payback();
|
||||||
$payback_balance = $payback_balance->load(array('invoice_id'=>$invoice->getId(), 'from_user'=>$user1->getId(), 'to_user'=>$user2->getId()), true);
|
$payback_balance = $payback_balance->load(array('invoice_id'=>$invoice->getId(), 'from_user'=>$user1->getId(), 'to_user'=>$user2->getId()), true);
|
||||||
if($payback_balance !== false)
|
if($payback_balance !== false)
|
||||||
$balances[$user1->getId()][$user2->getId()] = round($balances[$user1->getId()][$user2->getId()] - $payback_balance->getAmount(), 2);
|
$balances[$user1->getId()][$user2->getId()] = $balances[$user1->getId()][$user2->getId()] - $payback_balance->getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1161,12 +1171,12 @@
|
|||||||
if($invoices_list_balances !== false) {
|
if($invoices_list_balances !== false) {
|
||||||
foreach($invoices_list_balances as $invoice) {
|
foreach($invoices_list_balances as $invoice) {
|
||||||
if($invoice->getUsersIn()->inUsersIn($user2->getId())) {
|
if($invoice->getUsersIn()->inUsersIn($user2->getId())) {
|
||||||
$balances[$user1->getId()][$user2->getId()] = round($balances[$user1->getId()][$user2->getId()] - $invoice->getAmountPerPerson($user2->getId()), 2);
|
$balances[$user1->getId()][$user2->getId()] = $balances[$user1->getId()][$user2->getId()] - $invoice->getAmountPerPerson($user2->getId(), false);
|
||||||
|
|
||||||
$payback_balance = new Payback();
|
$payback_balance = new Payback();
|
||||||
$payback_balance = $payback_balance->load(array('invoice_id'=>$invoice->getId(), 'from_user'=>$user2->getId(), 'to_user'=>$user1->getId()), true);
|
$payback_balance = $payback_balance->load(array('invoice_id'=>$invoice->getId(), 'from_user'=>$user2->getId(), 'to_user'=>$user1->getId()), true);
|
||||||
if($payback_balance !== false)
|
if($payback_balance !== false)
|
||||||
$balances[$user1->getId()][$user2->getId()] = round($balances[$user1->getId()][$user2->getId()] + $payback_balance->getAmount(), 2);
|
$balances[$user1->getId()][$user2->getId()] = $balances[$user1->getId()][$user2->getId()] + $payback_balance->getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1178,14 +1188,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach($users_list as $user1) {
|
||||||
|
foreach($users_list as $user2) {
|
||||||
|
if($balances[$user1->getId()][$user2->getId()] != '-' && $balances[$user1->getId()][$user2->getId()] != 'X')
|
||||||
|
$balances[$user1->getId()][$user2->getId()] = round($balances[$user1->getId()][$user2->getId()], 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!$current_user->getAdmin()) {
|
if(!$current_user->getAdmin()) {
|
||||||
$user_balance = 0;
|
$user_balance = 0;
|
||||||
foreach($users_list as $user1) {
|
foreach($users_list as $user1) {
|
||||||
$user_balance = round($user_balance - $balances[$current_user->getId()][$user1->getId()], 2);
|
$user_balance = $user_balance - $balances[$current_user->getId()][$user1->getId()];
|
||||||
$user_balance = round($user_balance + $balances[$user1->getId()][$current_user->getId()], 2);
|
$user_balance = $user_balance + $balances[$user1->getId()][$current_user->getId()];
|
||||||
}
|
}
|
||||||
$tpl->assign('user_balance', $user_balance);
|
|
||||||
|
$tpl->assign('user_balance', round($user_balance,2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl->assign('users', secureDisplay($users_list));
|
$tpl->assign('users', secureDisplay($users_list));
|
||||||
|
Loading…
Reference in New Issue
Block a user