From 1a9f2429b17bfbb9e4bfb3ef421d6e1dd1504542 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 15 Sep 2013 16:39:16 +0200 Subject: [PATCH] Balance table fully functional --- index.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.php b/index.php index 8df6745..50cfd10 100644 --- a/index.php +++ b/index.php @@ -671,6 +671,11 @@ foreach($invoices_list_balances as $invoice) { if($invoice->getUsersIn()->inUsersIn($user1->getId())) { $balances[$user1->getId()][$user2->getId()] += $invoice->getAmountPerPerson($user1->getId()); + + $payback_balance = new Payback(); + $payback_balance = $payback_balance->load(array('invoice_id'=>$invoice->getId(), 'from_user'=>$user1->getId(), 'to_user'=>$user2->getId()), true); + if($payback_balance !== false) + $balances[$user1->getId()][$user2->getId()] -= $payback_balance->getAmount(); } } } @@ -682,9 +687,19 @@ foreach($invoices_list_balances as $invoice) { if($invoice->getUsersIn()->inUsersIn($user2->getId())) { $balances[$user1->getId()][$user2->getId()] -= $invoice->getAmountPerPerson($user2->getId()); + + $payback_balance = new Payback(); + $payback_balance = $payback_balance->load(array('invoice_id'=>$invoice->getId(), 'from_user'=>$user2->getId(), 'to_user'=>$user1->getId()), true); + if($payback_balance !== false) + $balances[$user1->getId()][$user2->getId()] += $payback_balance->getAmount(); } } } + + if($balances[$user1->getId()][$user2->getId()] == 0) { + $balances[$user1->getId()][$user2->getId()] = '-'; + $balances[$user2->getId()][$user1->getId()] = '-'; + } } } }