You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
5.6 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
require_once __DIR__ . "/../required.php";
use Medoo\Medoo;
redirectIfNotLoggedIn();
$registers = $database->select('registers', ['registerid (id)', 'registername (name)']);
?>
<div class="btn-toolbar">
<a href="app.php?page=editregister" class="btn btn-success"><i class="fas fa-plus"></i> <?php $Strings->get("add register"); ?></a>
</div>
<table id="registertable" class="table table-bordered table-hover table-sm">
<thead>
<tr>
<th data-priority="0"></th>
<th data-priority="1"><?php $Strings->get('actions'); ?></th>
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php $Strings->get('name'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-balance-scale d-none d-md-inline"></i> <?php $Strings->get('balance'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-play d-none d-md-inline"></i> <?php $Strings->get('last opened'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-stop d-none d-md-inline"></i> <?php $Strings->get('closed'); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($registers as $r) {
$cashwhere = [
'registerid' => $r['id'],
'ORDER' => ['close' => "DESC"]
];
if ($database->has('cash_drawer', ['AND' => ['registerid' => $r['id'], 'close' => null]])) {
$cashwhere = ['AND' => ['registerid' => $r['id'], 'close' => null]];
}
$cash = $database->get('cash_drawer', [
'cashid', 'open', 'close', 'start_amount', 'end_amount'
], $cashwhere);
$balance = 0.0;
$open = "";
$close = "";
if ($cash === false) {
$open = $Strings->get("never", false);
$close = $Strings->get("never", false);
} else {
if (!is_null($cash['end_amount']) && !is_null($cash['close'])) {
$balance = (float) $cash['end_amount'];
} else {
$balance = (float) $cash['start_amount'];
$rows = $database->select("payments", [
"[>]transactions" => ['txid' => 'txid']
], 'amount', [
'AND' => [
'transactions.cashid' => $cash['cashid'],
'payments.type' => 1
]
]);
foreach ($rows as $row) {
$balance += $row;
}
}
$open = date($SETTINGS['datetime_format'], strtotime($cash['open']));
$close = is_null($cash['close']) ? $Strings->get("still open", false) : date($SETTINGS['datetime_format'], strtotime($cash['close']));
}
?>
<tr>
<td></td>
<td>
<a class="btn btn-primary btn-sm" href="app.php?page=editregister&id=<?php echo $r['id']; ?>"><i class="fas fa-edit"></i> <?php $Strings->get("edit"); ?></a>
<?php
if (is_null($cash['close']) && !is_null($cash['open'])) {
?>
<form action="action.php" method="POST" class="d-inline">
<input type="hidden" name="action" value="closecash" />
<input type="hidden" name="source" value="registers" />
<input type="hidden" name="register" value="<?php echo $r['id']; ?>" />
<button class="btn btn-danger btn-sm" type="submit"><i class="fas fa-stop"></i> <?php $Strings->get("close"); ?></button>
</form>
<?php
} else {
?>
<button class="btn btn-success btn-sm btn-opencash" data-register="<?php echo $r['id']; ?>"><i class="fas fa-play"></i> <?php $Strings->get("open"); ?></button>
<?php
}
?>
</td>
<td><?php echo $r['name']; ?></td>
<td>$<?php echo number_format($balance, 2); ?></td>
<td><?php echo $open; ?></td>
<td><?php echo $close; ?></td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th data-priority="0"></th>
<th data-priority="1"><?php $Strings->get('actions'); ?></th>
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php $Strings->get('name'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-balance-scale d-none d-md-inline"></i> <?php $Strings->get('balance'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-play d-none d-md-inline"></i> <?php $Strings->get('last opened'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-stop d-none d-md-inline"></i> <?php $Strings->get('closed'); ?></th>
</tr>
</tfoot>
</table>
<form action="action.php" method="POST" class="d-none" id="opencashform">
<input type="hidden" name="action" value="opencash" />
<input type="hidden" name="source" value="registers" />
<input type="hidden" name="startamount" value="" id="opencashstart" />
<input type="hidden" name="register" value="" id="opencashregid" />
</form>