|
|
@@ -2,119 +2,50 @@
|
|
|
// Icons from https://icon-icons.com/fr/pack/BigMug-Line-icons/935
|
|
|
|
|
|
global $account;
|
|
|
-$period = Period::LoadPendingPeriod();
|
|
|
+$periods = Period::LoadPendingPeriods();
|
|
|
$events = [];
|
|
|
-if ($period)
|
|
|
- $events = Event::LoadForPeriod($period);
|
|
|
-
|
|
|
-class Total {
|
|
|
- public function Total() {
|
|
|
- }
|
|
|
-
|
|
|
- public function add($event) {
|
|
|
- $amount = $event->getAmount();
|
|
|
- $beneficiaryId = $event->getBeneficiary()->getId();
|
|
|
- if (!isset($this->beneficiaries[$beneficiaryId]))
|
|
|
- $this->beneficiaries[$beneficiaryId] = $amount;
|
|
|
- else
|
|
|
- $this->beneficiaries[$beneficiaryId] += $amount;
|
|
|
- foreach ($event->getContext() as $ctx) {
|
|
|
- if (!isset($this->contexts[$ctx->getId()]))
|
|
|
- $this->contexts[$ctx->getId()] = $amount;
|
|
|
- else
|
|
|
- $this->contexts[$ctx->getId()] += $amount;
|
|
|
- }
|
|
|
- $this->total += $amount;
|
|
|
- }
|
|
|
-
|
|
|
- public function getTotal() {
|
|
|
- return $this->total;
|
|
|
- }
|
|
|
-
|
|
|
- public function getBeneficiaries() {
|
|
|
- $result = array();
|
|
|
- foreach ($this->beneficiaries as $i => $amount)
|
|
|
- array_push($result, array(Beneficiary::Get($i), $amount));
|
|
|
- usort($result, function($a, $b) { return $b[1] -$a[1]; });
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- public function getContexts() {
|
|
|
- $result = array();
|
|
|
- foreach ($this->contexts as $i => $amount) {
|
|
|
- array_push($result, array(Context::Get($i), $amount));
|
|
|
- }
|
|
|
- usort($result, function($a, $b) { return $b[1] -$a[1]; });
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- private $beneficiaries = array();
|
|
|
- private $contexts = array();
|
|
|
- private $total = 0;
|
|
|
-}
|
|
|
-
|
|
|
-function printContext($ctx) {
|
|
|
- $result = "<ul style='padding: 0;'>";
|
|
|
- usort($ctx, function($a, $b) { return strcasecmp($a->getLabel(), $b->getLabel()); });
|
|
|
- foreach ($ctx as $i) {
|
|
|
- $label = $i->getLabel();
|
|
|
- $result .= "<li class='badge badge-info' style='margin-left: 5px;'>${label}</li>";
|
|
|
- }
|
|
|
- $result .= "</ul>";
|
|
|
- return $result;
|
|
|
-}
|
|
|
-
|
|
|
-function printEvent($e, $totalAmount) {
|
|
|
- $id = $e->getId();
|
|
|
- $amount = $e->getAmount();
|
|
|
- $date = $e->getPaymentDate()->format("d/m/Y");
|
|
|
- $label = $e->getLabel();
|
|
|
- $beneficiary = $e->getBeneficiary()->getLabel();
|
|
|
- $context = printContext($e->getContext());
|
|
|
-
|
|
|
- echo "<tr><td>${date}</td>";
|
|
|
- echo "<td>${label}</td>";
|
|
|
- echo "<td>${beneficiary}</td>";
|
|
|
- echo "<td>${context}</td>";
|
|
|
- echo "<td>${amount}</td>";
|
|
|
- echo "<td>
|
|
|
- <a href='event/edit?id=${id}'><img alt='Edit' class='icon' src='public/img/note-outlined-symbol_icon-icons.com_73198.svg'/></a>
|
|
|
- <a href='event/add?from=${id}'><img alt='Duplicate' class='icon' src='public/img/copy-two-paper-sheets-interface-symbol_icon-icons.com_73283.svg'/></a>
|
|
|
- <a href='event/delete?id=${id}'><img alt='Delete' class='icon' src='public/img/recycling-bin_icon-icons.com_73179.svg'/></a>
|
|
|
- </td></tr>";
|
|
|
- $totalAmount->add($e);
|
|
|
-}
|
|
|
-
|
|
|
-$totalAmount = new Total();
|
|
|
+$nbPeriods = count($periods);
|
|
|
+if ($nbPeriods)
|
|
|
+ $events = Event::LoadForPeriod($periods[$nbPeriods -1]);
|
|
|
|
|
|
?><!DOCTYPE html5><html><head>
|
|
|
<link rel="stylesheet" href="public/css/bootstrap.min.css" />
|
|
|
<link rel="stylesheet" href="public/css/style.css" />
|
|
|
</head><body>
|
|
|
+<div class="row">
|
|
|
+<div class="col-12 col-md-3 col-xl-2 bd-sidebar">
|
|
|
+<h3>Pending periods</h3>
|
|
|
+<ul class="container">
|
|
|
+<?php foreach ($periods as $i) echo '<a href="#" onclick="setPeriodStart(\'' .$i->getStart() .'\')"><li>' .$i->getLabel() .' (from ' .$i->getStart() .')</li></a>'; ?>
|
|
|
+</ul>
|
|
|
+<h3>Past periods</h3>
|
|
|
+<ul class="container">
|
|
|
+<?php
|
|
|
+$past = Period::LoadPastPeriods();
|
|
|
+foreach ($past as $i) echo '<a href="#" onclick="setPeriodId(\'' .$i->getId() .'\')"><li>' .$i->getLabel() .' (from ' .$i->getStart() .' to ' .$i->getEnd() .')</li></a>'; ?>
|
|
|
+</ul>
|
|
|
+<h3>Settings</h3>
|
|
|
<div class="container">
|
|
|
-<table class="table table-striped table-hover"><tr><th>Date</th><th>Label</th><th>Beneficiary</th><th>Context</th><th>Amount</th><th>Action</th></tr>
|
|
|
-<?php foreach ($events as $i) {
|
|
|
- printEvent($i, $totalAmount);
|
|
|
-} ?>
|
|
|
-<tr><td colspan=4>Total</td><td><?php echo $totalAmount->getTotal(); ?></td><td></td></tr>
|
|
|
-</table>
|
|
|
-<button onclick="javascript:document.location.href='event/add'" class="btn btn-primary">Add</button></div>
|
|
|
-<div class="container"><div class="row"><div class="col-sm">
|
|
|
-<table class="table table-striped table-hover"><tr><th>Beneficiary</th><th>Amount</th></tr>
|
|
|
-<?php
|
|
|
- foreach ($totalAmount->getBeneficiaries() as $i) {
|
|
|
- echo "<tr><td>" .$i[0]->getLabel() ."</td><td>" .$i[1] ."</td></tr>";
|
|
|
- }
|
|
|
-?>
|
|
|
-</table></div><div class="col-sm">
|
|
|
-<table class="table table-striped table-hover"><tr><th>Context</th><th>Amount</th></tr>
|
|
|
-<?php
|
|
|
- foreach ($totalAmount->getContexts() as $i) {
|
|
|
- echo "<tr><td>" .$i[0]->getLabel() ."</td><td>" .$i[1] ."</td></tr>";
|
|
|
- }
|
|
|
-?>
|
|
|
-</table></div></div></div>
|
|
|
+ <a href="periods"/>Periods</a>
|
|
|
+ <a href="logout"/>Logout</a>
|
|
|
+</div></div>
|
|
|
+<div class="col-12 col-md-9 col-xl-8 py-md-3 pl-md-5 bd-content">
|
|
|
+<table class="table table-striped table-hover"><thead><tr><th>Date</th><th>Label</th><th>Beneficiary</th><th>Context</th><th>Amount</th><th>Action</th></tr></thead><tbody id="events"></tbody></table>
|
|
|
+<button onclick="javascript:document.location.href='event/add'" class="btn btn-primary">Add</button>
|
|
|
+<div class="row"><div class="col-sm">
|
|
|
+<table class="table table-striped table-hover"><thead><tr><th>Beneficiary</th><th>Amount</th></tr></thead><tbody id="beneficiaries"></tbody></table></div><div class="col-sm">
|
|
|
+<table class="table table-striped table-hover"><thead><tr><th>Context</th><th>Amount</th></tr></thead><tbody id="contexts"></tbody></table></div></div>
|
|
|
+<script>window["PERIODS"] = [<?php $written = false;
|
|
|
+foreach ($periods as $i) {
|
|
|
+ echo ($written ? ',' : '') .'{start:"' .$i->getStart() .'"}';
|
|
|
+ $written = true;
|
|
|
+}; ?>];window["EVENTS"]= [<?php $written = false;
|
|
|
+foreach ($events as $i) {
|
|
|
+ echo ($written ? ',' : '') .json_encode($i->toArray());
|
|
|
+ $written = true;
|
|
|
+}?>];</script>
|
|
|
<script src="public/js/jquery-3.3.1.slim.min.js"></script>
|
|
|
<script src="public/js/popper.min.js"></script>
|
|
|
<script src="public/js/bootstrap.min.js"></script>
|
|
|
+<script src="public/js/script.min.js"></script>
|
|
|
</body></html>
|