Add button to attach customer to sale (close #5)

This commit is contained in:
Skylar Ittner 2018-05-25 19:27:00 -06:00
parent 855dbca1e1
commit e46d89de7b
7 changed files with 152 additions and 9 deletions

View File

@ -99,7 +99,7 @@ switch ($VARS['action']) {
]);
$binstack->update('items', [
'qty[-]' => $i['qty']
], [
], [
'itemid' => $i['id']
]);
}
@ -135,7 +135,10 @@ switch ($VARS['action']) {
$type = $tx['type'];
$cashier = getUserByID($tx['cashier'])['name'];
$customerid = $tx['customerid'];
$customerline = (is_null($customerid) ? "" : "<br />Customer: $customerid");
$customerline = "";
if (!is_null($customerid) && !empty($customerid)) {
$customerline = "<br />Customer: " . $database->get('customers', 'name', ['customerid' => $customerid]);
}
$itemhtml = "";
$items = $database->select('lines', ['amount', 'name', 'itemid', 'qty'], ['txid' => $txid]);
@ -200,11 +203,12 @@ $customerline
$itemhtml
</div>
<hr />
<b class="flexrow"><span>Total: </span><span>$$totalstr</span></b>
<hr />
<div id="payments">
$paymenthtml
</div>
<hr />
<b class="flexrow"><span>Total: </span><span>$$totalstr</span></b>
<b class="flexrow"><span>Paid: </span><span>$$paidstr</span></b>
<b class="flexrow"><span>Change: </span><span>$$changestr</span></b>
END;
@ -232,6 +236,31 @@ END;
], $where);
$items = (count($items) > 0 ? $items : false);
exit(json_encode(["status" => "OK", "items" => $items]));
case "customersearch":
header("Content-Type: application/json");
if (!is_empty($VARS['q'])) {
$where["AND"]["OR"] = [
"customerid" => $VARS['q'],
"name[~]" => $VARS['q'],
"email[~]" => $VARS['q'],
"phone[~]" => $VARS['q']
];
} else {
exit(json_encode(["status" => "ERROR", "customers" => false]));
}
$where["LIMIT"] = 10;
$customers = $database->select('customers', [
'customerid (id)',
'name',
'email',
'phone',
'address',
'notes'
], $where);
$customers = (count($customers) > 0 ? $customers : false);
exit(json_encode(["status" => "OK", "customers" => $customers]));
case "giftcard_lookup":
header("Content-Type: application/json");
$code = $VARS['code'];

Binary file not shown.

View File

@ -45,4 +45,6 @@ define("STRINGS", [
"receipt" => "Receipt",
"close" => "Close",
"print" => "Print",
"customer" => "Customer",
"customer search" => "Search customers",
]);

View File

@ -21,6 +21,7 @@ define("PAGES", [
"scripts" => [
"static/js/bsalert.js",
"static/js/pos_items.js",
"static/js/pos_customer.js",
"static/js/pos_payment.js",
"static/js/pos_finish.js",
"static/js/pos.js",

View File

@ -5,17 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
?>
<div class="modal" tabindex="-1" role="dialog" id="receiptmodal">
<div class="modal fade" tabindex="-1" role="dialog" id="receiptmodal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php lang("receipt"); ?></h5>
<h5 class="modal-title"><i class="fas fa-receipt"></i> <?php lang("receipt"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="display-4"><?php lang("change"); ?>: $<span id="receiptchange">0.00</span></div>
<div class="display-4 text-center"><?php lang("change"); ?>: $<span id="receiptchange">0.00</span></div>
<iframe class="w-100" id="receiptframe"></iframe>
</div>
<div class="modal-footer">
@ -26,6 +26,32 @@
</div>
</div>
<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">
<h5 class="modal-title"><i class="fas fa-user"></i> <?php lang("customer"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="input-group">
<input type="text" class="form-control" id="customersearch" placeholder="<?php lang("customer search"); ?>" />
<div class="input-group-append">
<button class="btn btn-link" type="button" id="customersearchbtn"><i class="fas fa-search"></i></button>
</div>
</div>
<div class="list-group mt-2" id="customerselection">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php lang("close"); ?></button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6 order-1 order-md-0">
<div class="card d-flex">
@ -51,6 +77,17 @@
<div class="col-12 col-md-6 order-0 order-md-1">
<div class="card mb-3 mb-md-0">
<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">
<i class="fas fa-user-circle"></i>
<span id="customerbtnlabel"></span>
<span class="sr-only"><?php lang("customer"); ?></span>
</div>
<div class="btn m-1">
<i class="fas fa-percent"></i>
<span class="sr-only"><?php lang("transaction discount"); ?></span>
</div>
</div>
<div class="card-body">
<span class="btn btn-green btn-lg btn-block" id="paymentbtn"><i class="fas fa-money-bill-wave"></i> <?php lang("enter payment"); ?></span>
</div>

74
static/js/pos_customer.js Normal file
View File

@ -0,0 +1,74 @@
/*
* 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 customerid = "";
var customername = "";
var customeremail = "";
var customerphone = "";
function showCustomerList(search) {
if (search == "") {
return;
}
$.get('action.php', {
action: 'customersearch',
q: search
}, function (data) {
var html = "";
if (data['customers'].length > 0) {
for (var i = 0; i < data['customers'].length; i++) {
var id = data['customers'][i]['id'];
var name = data['customers'][i]['name'];
var email = "";
if (typeof data['customers'][i]['email'] == 'string' && data['customers'][i]['email'].includes("@")) {
email = data['customers'][i]['email'];
}
var phone = "";
if (typeof data['customers'][i]['phone'] == 'string') {
phone = data['customers'][i]['phone'];
}
html += '<div class="list-group-item customer d-flex justify-content-between flex-wrap" data-id="' + id + '" data-name="' + name + '" data-email="' + email + '" data-phone="' + phone + '">'
+ '<div>' + name + '</div>'
+ '<div>' + email + '</div>'
+ '<div>' + phone + '</div>'
+ '</div>';
}
} else {
html = '<div class="list-group-item"><i class="fas fa-search-minus"></i> No results.</div>';
}
$("#customerselection").html(html);
});
}
$("#addcustomerbtn").click(function () {
$("#customermodal").modal();
});
$("#customersearch").on('keypress', function (e) {
if (e.which === 13) {
showCustomerList($("#customersearch").val());
$("#customersearch").val("");
}
});
$("#customersearchbtn").on("click", function () {
showCustomerList($("#customersearch").val());
$("#customersearch").val("");
});
$("#customermodal").on("shown.bs.modal", function () {
$("#customersearch").focus();
})
$("#customerselection").on("click", ".list-group-item.customer", function () {
customerid = $(this).data("id");
customername = $(this).data("name");
customeremail = $(this).data("email");
customerphone = $(this).data("phone");
$("#customerbtnlabel").text(customername);
console.log(customername);
$("#customermodal").modal('hide');
});

View File

@ -7,7 +7,7 @@
function sendTransactionToServer(callback) {
var items = [];
var payments = [];
var customer = '';
var customer = customerid;
var register = '';
$("#pos-lines-box .list-group-item").each(function () {
var each = $(".item-price", this).val() * 1.0;