Skip to content
Snippets Groups Projects
Commit 79b62ae9 authored by Theodoros Theodoropoulos's avatar Theodoros Theodoropoulos Committed by Demian Katz
Browse files

Add fine date column to MyResearch/Fines (#1251)

- Also restructures display to better adapt to missing data fields and for easier customization/extensibility.
parent 6dbf2a4c
No related merge requests found
...@@ -393,6 +393,7 @@ Find More = "Find More" ...@@ -393,6 +393,7 @@ Find More = "Find More"
Find New Items = "Find New Items" Find New Items = "Find New Items"
Finding Aid = "Finding Aid" Finding Aid = "Finding Aid"
Fine = "Fine" Fine = "Fine"
Fine Date = "Fine Date"
fine_limit_patron = "You have reached your fines limit and cannot renew items" fine_limit_patron = "You have reached your fines limit and cannot renew items"
Fines = "Fines" Fines = "Fines"
First = "First" First = "First"
......
...@@ -14,37 +14,70 @@ ...@@ -14,37 +14,70 @@
<?php if (empty($this->fines)): ?> <?php if (empty($this->fines)): ?>
<?=$this->transEsc('You do not have any fines')?> <?=$this->transEsc('You do not have any fines')?>
<?php else: ?> <?php else: ?>
<?php
// Collect the data to build the table; we process this in advance so we
// can omit empty columns and simplify customization by separating data
// processing from rendering.
$tableData = [];
$totalDue = 0;
foreach ($this->fines as $record) {
if (empty($record['title'])) {
$title = $this->transEsc('not_applicable');
} elseif (!is_object($record['driver'] ?? null)) {
$title = $this->escapeHtml(trim($record['title'], '/:'));
} else {
$title = '<a href="'
. $this->recordLink()->getUrl($record['driver'])
. '">' . $this->escapeHtml(trim($record['title'], '/:')) . '</a>';
}
$tableData['Title'][] = $title;
$tableData['Checked Out'][] = $this->escapeHtml($record['checkout'] ?? '');
$tableData['Due Date'][] = $this->escapeHtml($record['duedate'] ?? '');
$tableData['Fine'][] = $this->escapeHtml($record['fine'] ?? '');
$tableData['Fine Date'][] = $this->escapeHtml($record['createdate'] ?? '');
$tableData['Fee'][] = isset($record['amount'])
? $this->safeMoneyFormat($record['amount'] / 100.00) : '';
$tableData['Balance'][] = isset($record['balance'])
? $this->safeMoneyFormat($record['balance'] / 100.00) : '';
$totalDue += $record['balance'] ?? 0;
}
// Now empty out any unused columns:
foreach ($tableData as $column => $values) {
$empty = true;
foreach ($values as $value) {
if (strlen($value) > 0) {
$empty = false;
break;
}
}
if ($empty) {
unset($tableData[$column]);
}
}
// Create the final list of columns and count of rows:
$columns = array_keys($tableData);
$rowCount = count($this->fines);
?>
<table class="table table-striped"> <table class="table table-striped">
<caption class="sr-only"><?=$this->transEsc('Your Fines')?></caption> <caption class="sr-only"><?=$this->transEsc('Your Fines')?></caption>
<tr>
<th><?=$this->transEsc('Title')?></th>
<th><?=$this->transEsc('Checked Out')?></th>
<th><?=$this->transEsc('Due Date')?></th>
<th><?=$this->transEsc('Fine')?></th>
<th><?=$this->transEsc('Fee')?></th>
<th><?=$this->transEsc('Balance')?></th>
</tr>
<?php $totalDue = 0; ?>
<?php foreach ($this->fines as $record): ?>
<tr> <tr>
<td> <?php foreach ($columns as $header): ?>
<?php if (empty($record['title'])): ?> <th><?=$this->transEsc($header)?></th>
<?=$this->transEsc('not_applicable')?> <?php endforeach; ?>
<?php elseif (!isset($record['driver']) || !is_object($record['driver'])): ?> </tr>
<?=$this->escapeHtml(trim($record['title'], '/:'))?> <?php for ($row = 0; $row < $rowCount; $row++): ?>
<?php else: ?> <tr>
<a href="<?=$this->recordLink()->getUrl($record['driver'])?>"><?=$this->escapeHtml(trim($record['title'], '/:'))?></a> <?php foreach ($columns as $column): ?>
<?php endif; ?> <td><?=$tableData[$column][$row]?></td>
</td> <?php endforeach; ?>
<td><?=isset($record['checkout']) ? $this->escapeHtml($record['checkout']) : ''?></td> </tr>
<td><?=isset($record['duedate']) ? $this->escapeHtml($record['duedate']) : ''?></td> <?php endfor; ?>
<td><?=isset($record['fine']) ? $this->escapeHtml($record['fine']) : ''?></td> <tr style="font-weight:bold">
<td><?=isset($record['amount']) ? $this->safeMoneyFormat($record['amount'] / 100.00) : ''?></td> <td colspan="<?=count($columns) - 1?>"><?=$this->transEsc('Total Balance Due')?></td>
<td><?=isset($record['balance']) ? $this->safeMoneyFormat($record['balance'] / 100.00) : ''?></td> <td><?=$this->safeMoneyFormat($totalDue / 100.00) ?></td>
</tr> </tr>
<?php $totalDue += $record['balance']; ?>
<?php endforeach; ?>
<tr style="font-weight:bold"><td colspan="5"><?=$this->transEsc('Total Balance Due')?></td><td><?=$this->safeMoneyFormat($totalDue / 100.00) ?></td></tr>
</table> </table>
<?php endif; ?> <?php endif; ?>
</div> </div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment