Bug correction in global payback

Bug correction in global paybacks, should now work fine.
This commit is contained in:
Phyks 2013-11-04 21:12:22 +01:00
parent 523daa3f00
commit 7a3d414536
4 changed files with 47 additions and 26 deletions

1
TODO
View File

@ -1,4 +1,5 @@
* Notifications by e-mail for users * Notifications by e-mail for users
* Simplify matrix
Improvements : Improvements :
============== ==============

20
inc/UsersInGlobalPayback.class.php Normal file → Executable file
View File

@ -26,7 +26,15 @@
} }
public function get() { public function get() {
return $this->users_list; // Note : store amounts as int in database
$display = array();
foreach($this->users_list as $key1=>$temp) {
foreach($temp as $key2=>$amount) {
$display[$key1][$key2] = (float) ($amount / 100);
}
}
return $display;
} }
// Setters // Setters
@ -36,7 +44,15 @@
} }
public function set($users_in) { public function set($users_in) {
$this->users_list = $users_in; // Note : store amounts as int in database
$store = array();
foreach($users_in as $key1=>$temp) {
foreach($temp as $key2=>$amount) {
$store[$key1][$key2] = (int) ($amount * 100);
}
}
$this->users_list = $store;
} }
// Maps htmlspecialchars on the class before display // Maps htmlspecialchars on the class before display

52
index.php Normal file → Executable file
View File

@ -903,20 +903,22 @@
if($invoices !== false) { if($invoices !== false) {
foreach($invoices as $invoice) { foreach($invoices as $invoice) {
$paybacks = new Payback(); if($invoice->getAmountPerPerson($user1_id) !== false) {
$paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user2_id, 'from_user'=>$user1_id)); $paybacks = new Payback();
$paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user2_id, 'from_user'=>$user1_id));
if($paybacks === false) { if($paybacks === false) {
$payback = new Payback(); $payback = new Payback();
$payback->setTo($user2_id); $payback->setTo($user2_id);
$payback->setFrom($user1_id); $payback->setFrom($user1_id);
$payback->setAmount($invoice->getAmountPerPerson($user1_id)); $payback->setAmount($invoice->getAmountPerPerson($user1_id));
$payback->setInvoice($invoice->getId()); $payback->setInvoice($invoice->getId());
$payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
$payback->save(); $payback->save();
// Add the amount to what user1 owes to user2 // Add the amount to what user1 owes to user2
$users_in[$user1_id][$user2_id] += $payback->getAmount(); $users_in[$user1_id][$user2_id] += $payback->getAmount();
}
} }
} }
} }
@ -927,20 +929,22 @@
if($invoices !== false) { if($invoices !== false) {
foreach($invoices as $invoice) { foreach($invoices as $invoice) {
$paybacks = new Payback(); if($invoice->getAmountPerPerson($user2_id) !== false) {
$paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user1_id, 'from_user'=>$user2_id)); $paybacks = new Payback();
$paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user1_id, 'from_user'=>$user2_id));
if($paybacks === false) { if($paybacks === false) {
$payback = new Payback(); $payback = new Payback();
$payback->setTo($user1_id); $payback->setTo($user1_id);
$payback->setFrom($user2_id); $payback->setFrom($user2_id);
$payback->setAmount($invoice->getAmountPerPerson($user2_id)); $payback->setAmount($invoice->getAmountPerPerson($user2_id));
$payback->setInvoice($invoice->getId()); $payback->setInvoice($invoice->getId());
$payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
$payback->save(); $payback->save();
// Substract the amount to what user1 owes to user2 // Substract the amount to what user1 owes to user2
$users_in[$user1_id][$user2_id] -= $payback->getAmount(); $users_in[$user1_id][$user2_id] -= $payback->getAmount();
}
} }
} }
} }

0
install.php Normal file → Executable file
View File