Add cash drawer/register balance tracking (close #1)
This commit is contained in:
parent
96046aadbf
commit
172e611a45
81
action.php
81
action.php
@ -52,6 +52,7 @@ switch ($VARS['action']) {
|
||||
|
||||
$totalcharge = 0.00;
|
||||
$totalpaid = 0.00;
|
||||
$change = 0.0;
|
||||
foreach ($items as $i) {
|
||||
$totalcharge += $i['each'] * $i['qty'];
|
||||
if (!$binstack->has('items', ['itemid' => $i['id']])) {
|
||||
@ -128,6 +129,17 @@ switch ($VARS['action']) {
|
||||
]);
|
||||
}
|
||||
|
||||
if ($totalcharge < $totalpaid) {
|
||||
$change = $totalpaid - $totalcharge;
|
||||
$database->insert('payments', [
|
||||
'amount' => $change * -1.0,
|
||||
'data' => '',
|
||||
'type' => 1,
|
||||
'txid' => $txid,
|
||||
'certid' => null
|
||||
]);
|
||||
}
|
||||
|
||||
exit(json_encode(["status" => "OK", "txid" => $txid]));
|
||||
|
||||
break;
|
||||
@ -175,6 +187,9 @@ switch ($VARS['action']) {
|
||||
'txid' => $txid
|
||||
]);
|
||||
foreach ($payments as $p) {
|
||||
if ($p['amount'] < 0) {
|
||||
continue;
|
||||
}
|
||||
$paymenthtml .= "\n";
|
||||
$paymenthtml .= '<div class="flexrow">';
|
||||
$paymenthtml .= '<div>' . lang($p['text'], false) . '</div>';
|
||||
@ -364,6 +379,72 @@ END;
|
||||
}
|
||||
|
||||
returnToSender("customer_saved");
|
||||
case "set_register":
|
||||
$regid = $VARS['register'];
|
||||
if (!$database->has('registers', ['registerid' => $regid])) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (!$database->has('cash_drawer', ['AND' => ['registerid' => $regid, 'close' => null]])) {
|
||||
returnToSender("cash_not_open");
|
||||
}
|
||||
$cashid = $database->get('cash_drawer', 'cashid', ['AND' => ['registerid' => $regid, 'close' => null]]);
|
||||
$_SESSION['register'] = (int) $regid;
|
||||
returnToSender("register_set");
|
||||
break;
|
||||
case "opencash":
|
||||
$regid = $VARS['register'];
|
||||
$start = $VARS['startamount'];
|
||||
if (!$database->has('registers', ['registerid' => $regid])) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if ($database->has('cash_drawer', ['AND' => ['registerid' => $regid, 'close' => null]])) {
|
||||
returnToSender("cash_already_open");
|
||||
}
|
||||
if (!is_numeric($start) || (float) $start < 0) {
|
||||
$start = 0.0;
|
||||
}
|
||||
$database->insert('cash_drawer', [
|
||||
'registerid' => $regid,
|
||||
'open' => date('Y-m-d H:i:s'),
|
||||
'close' => null,
|
||||
'start_amount' => $start,
|
||||
'end_amount' => null
|
||||
]);
|
||||
returnToSender("cash_opened");
|
||||
break;
|
||||
case "closecash":
|
||||
$regid = $VARS['register'];
|
||||
if (!$database->has('registers', ['registerid' => $regid])) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (!$database->has('cash_drawer', ['AND' => ['registerid' => $regid, 'close' => null]])) {
|
||||
returnToSender("cash_not_open");
|
||||
}
|
||||
|
||||
$cash = $database->get('cash_drawer', ['cashid', 'start_amount'], ['AND' => ['registerid' => $regid, 'close' => null]]);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$database->update('cash_drawer', [
|
||||
'close' => date('Y-m-d H:i:s'),
|
||||
'end_amount' => $balance
|
||||
], [
|
||||
'cashid' => $cash['cashid']
|
||||
]);
|
||||
|
||||
returnToSender("cash_closed");
|
||||
break;
|
||||
case "session_keepalive":
|
||||
header("Content-Type: application/json");
|
||||
exit(json_encode(["status" => "OK"]));
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -72,5 +72,21 @@ define("STRINGS", [
|
||||
"delete" => "Delete",
|
||||
"cancel" => "Cancel",
|
||||
"price" => "Price",
|
||||
"finish" => "Finish"
|
||||
"finish" => "Finish",
|
||||
"registers" => "Registers",
|
||||
"add register" => "Add Register",
|
||||
"balance" => "Balance",
|
||||
"opened" => "Opened",
|
||||
"closed" => "Closed",
|
||||
"never" => "Never",
|
||||
"last opened" => "Last Opened",
|
||||
"still open" => "Still Open",
|
||||
"open" => "Open",
|
||||
"no cash" => "No cash",
|
||||
"choose register" => "Choose a cash register",
|
||||
"cash not open" => "Cash not open. Go to Registers to open it.",
|
||||
"cash opened" => "Cash opened.",
|
||||
"cash closed" => "Cash closed.",
|
||||
"register set" => "Register set.",
|
||||
"change register" => "Change register",
|
||||
]);
|
@ -25,4 +25,20 @@ define("MESSAGES", [
|
||||
"string" => "invalid customer id",
|
||||
"type" => "danger"
|
||||
],
|
||||
"cash_not_open" => [
|
||||
"string" => "cash not open",
|
||||
"type" => "danger"
|
||||
],
|
||||
"cash_already_open" => [
|
||||
"string" => "cash already open",
|
||||
"type" => "danger"
|
||||
],
|
||||
"register_set" => [
|
||||
"string" => "register set",
|
||||
"type" => "success"
|
||||
],
|
||||
"cash_opened" => [
|
||||
"string" => "cash opened",
|
||||
"type" => "success"
|
||||
],
|
||||
]);
|
||||
|
36
lib/chooseregister.php
Normal file
36
lib/chooseregister.php
Normal file
@ -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>
|
15
pages.php
15
pages.php
@ -14,7 +14,7 @@ define("PAGES", [
|
||||
"pos" => [
|
||||
"title" => "point of sale",
|
||||
"navbar" => true,
|
||||
"icon" => "far fa-money-bill-alt",
|
||||
"icon" => "fas fa-store-alt",
|
||||
"styles" => [
|
||||
"static/css/pos.css",
|
||||
],
|
||||
@ -55,6 +55,19 @@ define("PAGES", [
|
||||
"static/js/editcustomer.js"
|
||||
]
|
||||
],
|
||||
"registers" => [
|
||||
"title" => "registers",
|
||||
"navbar" => true,
|
||||
"icon" => "far fa-money-bill-alt",
|
||||
"styles" => [
|
||||
"static/css/datatables.min.css",
|
||||
"static/css/tables.css"
|
||||
],
|
||||
"scripts" => [
|
||||
"static/js/datatables.min.js",
|
||||
"static/js/registers.js"
|
||||
],
|
||||
],
|
||||
"404" => [
|
||||
"title" => "404 error"
|
||||
]
|
||||
|
@ -4,8 +4,17 @@
|
||||
* 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="modal fade" tabindex="-1" role="dialog" id="receiptmodal">
|
||||
$register = [
|
||||
"name" => lang("no cash", false),
|
||||
"id" => ""
|
||||
];
|
||||
|
||||
if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$database->has('registers', ['registerid' => $_SESSION['register']])) {
|
||||
require_once __DIR__ . "/../lib/chooseregister.php";
|
||||
} else {
|
||||
$register = $database->get('registers', ['registerid (id)', 'registername (name)'], ['registerid' => $_SESSION['register']]);
|
||||
?>
|
||||
<div class="modal fade" tabindex="-1" role="dialog" id="receiptmodal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@ -24,9 +33,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" tabindex="-1" role="dialog" id="customermodal">
|
||||
<div class="modal fade" tabindex="-1" role="dialog" id="customermodal">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@ -50,9 +59,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 order-1 order-md-0">
|
||||
<div class="card d-flex">
|
||||
<div class="card-header p-1">
|
||||
@ -76,6 +85,9 @@
|
||||
|
||||
<div class="col-12 col-md-6 order-0 order-md-1">
|
||||
<div class="card mb-3 mb-md-0">
|
||||
<div class="w-100 position-absolute d-flex align-items-start pr-3 pt-2">
|
||||
<a href="app.php?page=pos&switch" class="ml-auto text-body" id="register" data-id="<?php echo $register['id']; ?>" data-toggle="tooltip" title="<?php lang("change register") ?>"><i class="fas fa-exchange-alt"></i> <?php echo $register['name']; ?></a>
|
||||
</div>
|
||||
<div class="display-4 p-1 p-md-3 text-center">$<span id="grand-total">0.00</span></div>
|
||||
<div class="card-body d-flex justify-content-center flex-wrap py-0 my-0">
|
||||
<div class="btn m-1" id="addcustomerbtn">
|
||||
@ -130,4 +142,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
117
pages/registers.php
Normal file
117
pages/registers.php
Normal file
@ -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>
|
@ -8,7 +8,7 @@ function sendTransactionToServer(callback) {
|
||||
var items = [];
|
||||
var payments = [];
|
||||
var customer = customerid;
|
||||
var register = '';
|
||||
var register = $("#register").data('id');
|
||||
var discountpercent = $("#discountpercentbtn").data("percent");
|
||||
if (discountpercent <= 0) {
|
||||
discountpercent = 0.0;
|
||||
|
@ -120,6 +120,7 @@ $("#discountpercentbtn").click(function () {
|
||||
if (result <= 0 || result >= 100) {
|
||||
$("#discountpercentbtn").data("percent", 0.0);
|
||||
$("#discountpercentbtnlabel").text("");
|
||||
recalculate();
|
||||
return;
|
||||
}
|
||||
$("#discountpercentbtn").data("percent", result);
|
||||
|
34
static/js/registers.js
Normal file
34
static/js/registers.js
Normal file
@ -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…
x
Reference in New Issue
Block a user