| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- // Icons from https://icon-icons.com/fr/pack/BigMug-Line-icons/935
- global $account;
- $period = Period::LoadPendingPeriod();
- $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();
- ?><!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="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>
- <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>
- </body></html>
|