Index balance table working
This commit is contained in:
parent
3696a6566a
commit
f67a9a6e2f
@ -43,6 +43,12 @@
|
||||
$this->users_list = $users_in;
|
||||
}
|
||||
|
||||
// Check if a user is in a specified invoice
|
||||
// =========================================
|
||||
public function inUsersIn($id) {
|
||||
return in_array($id, array_keys($this->users_list));
|
||||
}
|
||||
|
||||
// Maps htmlspecialchars on the class before display
|
||||
// =================================================
|
||||
public function secureDisplay() {
|
||||
|
38
index.php
38
index.php
@ -575,9 +575,43 @@
|
||||
if($user1->getId() == $user2->getId()) {
|
||||
$balances[$user1->getId()][$user2->getId()] = 'X';
|
||||
}
|
||||
if(!empty($balances[$user2->getId()][$user1->getId()])) {
|
||||
// If the opposed element in the matrix exists
|
||||
if(is_float($balances[$user2->getId()][$user1->getId()])) {
|
||||
if($balances[$user2->getId()][$user1->getId()] >= 0) {
|
||||
$balances[$user1->getId()][$user2->getId()] = '-';
|
||||
}
|
||||
else {
|
||||
// TODO : Balances between users
|
||||
$balances[$user1->getId()][$user2->getId()] = '';
|
||||
$balances[$user1->getId()][$user2->getId()] = -$balances[$user2->getId()][$user1->getId()];
|
||||
$balances[$user2->getId()][$user1->getId()] = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO : Optimize ?
|
||||
$balances[$user1->getId()][$user2->getId()] = 0;
|
||||
|
||||
// First, get a list of all invoices paid by user2 and check if user1 was in
|
||||
$invoices_list_balances = new Invoice();
|
||||
$invoices_list_balances = $invoices_list_balances->load(array('buyer'=>$user2->getId()));
|
||||
if($invoices_list_balances !== false) {
|
||||
foreach($invoices_list_balances as $invoice) {
|
||||
if($invoice->getUsersIn()->inUsersIn($user1->getId())) {
|
||||
$balances[$user1->getId()][$user2->getId()] += $invoice->getAmountPerPerson();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then search for all invoices paid by 1 and check if user2 was in
|
||||
$invoices_list_balances = new Invoice();
|
||||
$invoices_list_balances = $invoices_list_balances->load(array('buyer'=>$user1->getId()));
|
||||
if($invoices_list_balances !== false) {
|
||||
foreach($invoices_list_balances as $invoice) {
|
||||
if($invoice->getUsersIn()->inUsersIn($user2->getId())) {
|
||||
$balances[$user1->getId()][$user2->getId()] -= $invoice->getAmountPerPerson();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,10 @@ input[type="checkbox"] {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.cell-disabled {
|
||||
background-color: rgb(221, 221, 221);
|
||||
}
|
||||
|
||||
input[type=submit] {
|
||||
background-color: green;
|
||||
color: white;
|
||||
|
@ -18,7 +18,12 @@
|
||||
<tr>
|
||||
<th>{$value->getDisplayName()}</th>
|
||||
{loop="users"}
|
||||
{if condition="$balances[$value1->getId()][$value2->getId()] == 'X'"}
|
||||
<td class="cell-disabled"></td>
|
||||
{else}
|
||||
|
||||
<td>{$balances[$value1->getId()][$value2->getId()]}</td>
|
||||
{/if}
|
||||
{/loop}
|
||||
</tr>
|
||||
{/loop}
|
||||
|
Loading…
Reference in New Issue
Block a user