Browse Source

Add transaction search, close #18

master
Skylar Ittner 1 year ago
parent
commit
d1a5b57934
4 changed files with 113 additions and 1 deletions
  1. 52
    0
      action.php
  2. 1
    0
      lang/en_us.php
  3. 8
    1
      pages/pos.php
  4. 52
    0
      static/js/pos_management.js

+ 52
- 0
action.php View File

@@ -225,6 +225,58 @@ switch ($VARS['action']) {

exit(GenerateReceipt::outputReceipt($receipt, $format, $width, "Tx. #" . $VARS['txid']));
break;
case "transactionsearch":
header("Content-Type: application/json");
if (!is_empty($VARS['q'])) {
$where["AND"]["OR"] = [
"txid" => $VARS['q'],
"name[~]" => $VARS['q'],
"email[~]" => $VARS['q'],
"phone[~]" => $VARS['q']
];
} else {
exit(json_encode(["status" => "ERROR", "transactions" => false]));
}
$where["LIMIT"] = 50;

$transactions = $database->select('transactions', [
'[>]customers' => 'customerid',
'[>]cash_drawer' => 'cashid',
'[>]registers' => ['cash_drawer.registerid' => 'registerid'],
], [
'txid',
'txdate',
'type',
'cashier (cashierid)',
'transactions.cashid',
'cash_drawer.registerid',
'registers.registername',
'cash_drawer.open',
'cash_drawer.close',
'customerid',
'customer' => [
'name',
'email',
'phone',
'address'
]], $where);

for ($i = 0; $i < count($transactions); $i++) {
if (is_null($transactions[$i]['close']) && !is_null($transactions[$i]['open'])) {
$transactions[$i]['editable'] = true;
} else {
$transactions[$i]['editable'] = false;
}
if (!is_null($transactions[$i]['cashierid'])) {
$cashier = getUserByID($transactions[$i]['cashierid']);
$transactions[$i]['cashier'] = [
"name" => $cashier['name'],
"username" => $cashier['username']
];
}
}
$transactions = (count($transactions) > 0 ? $transactions : false);
exit(json_encode(["status" => "OK", "transactions" => $transactions]));
case "itemsearch":
header("Content-Type: application/json");
if (!is_empty($VARS['q'])) {

+ 1
- 0
lang/en_us.php View File

@@ -120,4 +120,5 @@ define("STRINGS", [
"pick cash" => "Choose",
"cash already closed" => "Cash already closed, cannot edit this transaction. Process a return instead.",
"update" => "Update",
"transaction search" => "Search transactions (by Tx ID or customer)",
]);

+ 8
- 1
pages/pos.php View File

@@ -89,7 +89,14 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
<div class="modal-body">
<div class="row">
<div class="col-12 col-md-6">

<div class="input-group">
<input type="text" class="form-control" id="transactionsearch" placeholder="<?php lang("transaction search"); ?>" />
<div class="input-group-append">
<button class="btn btn-link" type="button" id="transactionsearchbtn"><i class="fas fa-search"></i></button>
</div>
</div>
<div class="list-group mt-2" id="transactionselection">
</div>
</div>
<div class="col-12 col-md-6">
<button type="button" class="btn btn-primary" id="xprintbtn"><i class="fas fa-print"></i> <?php lang("print"); ?></button>

+ 52
- 0
static/js/pos_management.js View File

@@ -12,4 +12,56 @@ $("#openmanagement").click(function () {

$("#xprintbtn").click(function () {
document.getElementById("xframe").contentWindow.print();
});

function showTransactionList(search) {
if (search == "") {
return;
}
$.get('action.php', {
action: 'transactionsearch',
q: search
}, function (data) {
var html = "";
if (data['transactions'].length > 0) {
for (var i = 0; i < data['transactions'].length; i++) {
var txid = '<i class="fas fa-hashtag"></i> ' + data['transactions'][i]['txid'];
var date = '<i class="fas fa-calendar"></i> ' + data['transactions'][i]['txdate'];
var customername = "";
var cashiername = "";
var buttons = "";
if (typeof data['transactions'][i]['customer']['name'] == 'string') {
customername = '<i class="fas fa-user-circle"></i> ' + data['transactions'][i]['customer']['name'];
}
if (data['transactions'][i]['cashier']['name'] != "") {
cashiername = '<i class="fas fa-id-card-alt"></i> ' + data['transactions'][i]['cashier']['name'];
}
if (data['transactions'][i]['editable'] === true) {
buttons += '<a href="app.php?page=pos&txid=' + data['transactions'][i]['txid'] + '" class="btn btn-sm btn-primary"><i class="fas fa-edit"></i> Edit</a>';
}
html += '<div class="list-group-item transaction d-flex justify-content-between flex-wrap">'
+ '<div>' + buttons + '</div>'
+ '<div>' + txid + '</div>'
+ '<div>' + date + '</div>'
+ '<div>' + cashiername + '</div>'
+ '<div>' + customername + '</div>'
+ '</div>';
}
} else {
html = '<div class="list-group-item"><i class="fas fa-search-minus"></i> No results.</div>';
}
$("#transactionselection").html(html);
});
}

$("#transactionsearch").on('keypress', function (e) {
if (e.which === 13) {
showTransactionList($("#transactionsearch").val());
$("#transactionsearch").val("");
}
});

$("#transactionsearchbtn").on("click", function () {
showCustomerList($("#transactionsearch").val());
$("#transactionsearch").val("");
});

Loading…
Cancel
Save