diff --git a/action.php b/action.php index e34f1b1..6f589ef 100644 --- a/action.php +++ b/action.php @@ -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'])) { diff --git a/lang/en_us.php b/lang/en_us.php index 76db4ac..1dd1ebe 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -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)", ]); diff --git a/pages/pos.php b/pages/pos.php index 9174b35..ddc2ace 100644 --- a/pages/pos.php +++ b/pages/pos.php @@ -89,7 +89,14 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {