Add cash drawer/register balance tracking (close #1)
parent
96046aadbf
commit
172e611a45
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
<?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/.
|
||||
*/
|
||||
?>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 col-sm-8 col-md-6 col-lg-4">
|
||||
<form class="card border-green" action="action.php" method="POST">
|
||||
<h3 class="card-header text-green">
|
||||
<?php lang("point of sale"); ?>
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?php lang("choose register"); ?></h5>
|
||||
<div class="list-group">
|
||||
<?php
|
||||
$registers = $database->select("registers", ['registers.registerid (id)', 'registername (name)']);
|
||||
foreach ($registers as $r) {
|
||||
?>
|
||||
<button class="list-group-item" name="register" value="<?php echo $r['id']; ?>">
|
||||
<?php echo $r['name']; ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
</div>
|
||||
<input type="hidden" name="action" value="set_register" />
|
||||
<input type="hidden" name="source" value="pos" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,117 @@
|
||||
<?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 lang("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 lang('actions'); ?></th>
|
||||
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php lang('name'); ?></th>
|
||||
<th data-priority="2"><i class="fas fa-fw fa-balance-scale d-none d-md-inline"></i> <?php lang('balance'); ?></th>
|
||||
<th data-priority="3"><i class="fas fa-fw fa-play d-none d-md-inline"></i> <?php lang('last opened'); ?></th>
|
||||
<th data-priority="3"><i class="fas fa-fw fa-stop d-none d-md-inline"></i> <?php lang('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 = lang("never", false);
|
||||
$close = lang("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(DATETIME_FORMAT, strtotime($cash['open']));
|
||||
$close = is_null($cash['close']) ? lang("still open", false) : date(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 lang("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 lang("close"); ?></button>
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<form action="action.php" method="POST" class="d-inline">
|
||||
<input type="hidden" name="action" value="opencash" />
|
||||
<input type="hidden" name="source" value="registers" />
|
||||
<input type="hidden" name="register" value="<?php echo $r['id']; ?>" />
|
||||
<button class="btn btn-success btn-sm" type="submit"><i class="fas fa-play"></i> <?php lang("open"); ?></button>
|
||||
</form>
|
||||
<?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 lang('actions'); ?></th>
|
||||
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php lang('name'); ?></th>
|
||||
<th data-priority="2"><i class="fas fa-fw fa-balance-scale d-none d-md-inline"></i> <?php lang('balance'); ?></th>
|
||||
<th data-priority="3"><i class="fas fa-fw fa-play d-none d-md-inline"></i> <?php lang('last opened'); ?></th>
|
||||
<th data-priority="3"><i class="fas fa-fw fa-stop d-none d-md-inline"></i> <?php lang('closed'); ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
@ -0,0 +1,34 @@
|
||||
/* 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/. */
|
||||
|
||||
var registertable = $('#registertable').DataTable({
|
||||
responsive: {
|
||||
details: {
|
||||
display: $.fn.dataTable.Responsive.display.modal({
|
||||
header: function (row) {
|
||||
var data = row.data();
|
||||
return "<i class=\"far fa-money-bill-alt fa-fw\"></i> " + data[2];
|
||||
}
|
||||
}),
|
||||
renderer: $.fn.dataTable.Responsive.renderer.tableAll({
|
||||
tableClass: 'table'
|
||||
}),
|
||||
type: "column"
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
targets: 0,
|
||||
className: 'control',
|
||||
orderable: false
|
||||
},
|
||||
{
|
||||
targets: 1,
|
||||
orderable: false
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[2, 'asc']
|
||||
]
|
||||
});
|
Loading…
Reference in New Issue