diff --git a/action.php b/action.php index 5487e49..346ca74 100644 --- a/action.php +++ b/action.php @@ -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) ? "" : "
Customer: $customerid"); + $customerline = ""; + if (!is_null($customerid) && !empty($customerid)) { + $customerline = "
Customer: " . $database->get('customers', 'name', ['customerid' => $customerid]); + } $itemhtml = ""; $items = $database->select('lines', ['amount', 'name', 'itemid', 'qty'], ['txid' => $txid]); @@ -173,11 +176,11 @@ switch ($VARS['action']) { if ($change <= 0) { $change = 0.0; } - + $totalstr = number_format($total, 2); $paidstr = number_format($paid, 2); $changestr = number_format($change, 2); - + $html = << @@ -200,11 +203,12 @@ $customerline $itemhtml
+Total: $$totalstr +
$paymenthtml

-Total: $$totalstr Paid: $$paidstr Change: $$changestr 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']; diff --git a/database.mwb b/database.mwb index 985c57c..5e13297 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lang/en_us.php b/lang/en_us.php index 2ef708f..2baf03f 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -45,4 +45,6 @@ define("STRINGS", [ "receipt" => "Receipt", "close" => "Close", "print" => "Print", + "customer" => "Customer", + "customer search" => "Search customers", ]); \ No newline at end of file diff --git a/pages.php b/pages.php index 8cfa00d..2323e1a 100644 --- a/pages.php +++ b/pages.php @@ -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", diff --git a/pages/pos.php b/pages/pos.php index 85fc950..4d1f8d6 100644 --- a/pages/pos.php +++ b/pages/pos.php @@ -5,17 +5,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ ?> -