From 7a3d4145368ee95e53e77bfb27692190ab95ee27 Mon Sep 17 00:00:00 2001 From: Phyks Date: Mon, 4 Nov 2013 21:12:22 +0100 Subject: [PATCH] Bug correction in global payback Bug correction in global paybacks, should now work fine. --- TODO | 1 + inc/UsersInGlobalPayback.class.php | 20 ++++++++++-- index.php | 52 ++++++++++++++++-------------- install.php | 0 4 files changed, 47 insertions(+), 26 deletions(-) mode change 100644 => 100755 inc/UsersInGlobalPayback.class.php mode change 100644 => 100755 index.php mode change 100644 => 100755 install.php diff --git a/TODO b/TODO index 35e18d8..f7ed40a 100755 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ * Notifications by e-mail for users +* Simplify matrix Improvements : ============== diff --git a/inc/UsersInGlobalPayback.class.php b/inc/UsersInGlobalPayback.class.php old mode 100644 new mode 100755 index 35b4c42..478277b --- a/inc/UsersInGlobalPayback.class.php +++ b/inc/UsersInGlobalPayback.class.php @@ -26,7 +26,15 @@ } 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 @@ -36,7 +44,15 @@ } 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 diff --git a/index.php b/index.php old mode 100644 new mode 100755 index ec7c6e9..6168f2e --- a/index.php +++ b/index.php @@ -903,20 +903,22 @@ if($invoices !== false) { foreach($invoices as $invoice) { - $paybacks = new Payback(); - $paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user2_id, 'from_user'=>$user1_id)); + if($invoice->getAmountPerPerson($user1_id) !== false) { + $paybacks = new Payback(); + $paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user2_id, 'from_user'=>$user1_id)); - if($paybacks === false) { - $payback = new Payback(); - $payback->setTo($user2_id); - $payback->setFrom($user1_id); - $payback->setAmount($invoice->getAmountPerPerson($user1_id)); - $payback->setInvoice($invoice->getId()); - $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); - $payback->save(); + if($paybacks === false) { + $payback = new Payback(); + $payback->setTo($user2_id); + $payback->setFrom($user1_id); + $payback->setAmount($invoice->getAmountPerPerson($user1_id)); + $payback->setInvoice($invoice->getId()); + $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); + $payback->save(); - // Add the amount to what user1 owes to user2 - $users_in[$user1_id][$user2_id] += $payback->getAmount(); + // Add the amount to what user1 owes to user2 + $users_in[$user1_id][$user2_id] += $payback->getAmount(); + } } } } @@ -927,20 +929,22 @@ if($invoices !== false) { foreach($invoices as $invoice) { - $paybacks = new Payback(); - $paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user1_id, 'from_user'=>$user2_id)); + if($invoice->getAmountPerPerson($user2_id) !== false) { + $paybacks = new Payback(); + $paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>$user1_id, 'from_user'=>$user2_id)); - if($paybacks === false) { - $payback = new Payback(); - $payback->setTo($user1_id); - $payback->setFrom($user2_id); - $payback->setAmount($invoice->getAmountPerPerson($user2_id)); - $payback->setInvoice($invoice->getId()); - $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); - $payback->save(); + if($paybacks === false) { + $payback = new Payback(); + $payback->setTo($user1_id); + $payback->setFrom($user2_id); + $payback->setAmount($invoice->getAmountPerPerson($user2_id)); + $payback->setInvoice($invoice->getId()); + $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); + $payback->save(); - // Substract the amount to what user1 owes to user2 - $users_in[$user1_id][$user2_id] -= $payback->getAmount(); + // Substract the amount to what user1 owes to user2 + $users_in[$user1_id][$user2_id] -= $payback->getAmount(); + } } } } diff --git a/install.php b/install.php old mode 100644 new mode 100755