diff --git a/action.php b/action.php index 4ef89d1..ac2d894 100644 --- a/action.php +++ b/action.php @@ -672,6 +672,47 @@ switch ($VARS['action']) { exit(GenerateReceipt::outputReceipt($receipt, $format, $width, "Z Report")); break; + case "editcertificate": + $insert = true; + $code = $VARS['code']; + $amount = $VARS['balance']; + if (empty($VARS['id'])) { + $insert = true; + } else { + if ($database->has('certificates', ['certid' => $VARS['id']])) { + $insert = false; + } else { + returnToSender("invalid_parameters"); + } + } + + if ($insert && (is_empty($code) || $database->has('certificates', ['certcode' => $code]))) { + do { + $code = random_int(100000000000, 999999999999); + } while ($database->has('certificates', ['certcode' => $code])); + } + + if (!is_numeric($amount)) { + returnToSender("invalid_parameters"); + } + + if ($insert) { + $database->insert('certificates', [ + 'certcode' => $code, + 'amount' => $amount, + 'start_amount' => $amount, + 'issued' => date('Y-m-d H:i:s'), + 'deleted' => 0]); + returnToSender("card_x_added", $code); + } else { + $database->update('certificates', [ + 'amount' => $amount + ], [ + 'certid' => $VARS['id'] + ]); + returnToSender("card_x_saved", $code); + } + break; case "session_keepalive": header("Content-Type: application/json"); exit(json_encode(["status" => "OK"])); diff --git a/lang/en_us.php b/lang/en_us.php index 274ad8a..32d1639 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -124,5 +124,16 @@ define("STRINGS", [ "return" => "Return", "enter refund" => "Enter Refund", "refund" => "Refund", - "cannot edit return transaction" => "Cannot edit a return transaction." + "cannot edit return transaction" => "Cannot edit a return transaction.", + "gift cards" => "Gift Cards", + "add card" => "Add Card", + "card number" => "Card Number", + "start balance" => "Starting Balance", + "issued" => "Issued", + "editing card x" => "Editing card {code}", + "adding card" => "Adding card", + "card added" => "Gift card added.", + "card saved" => "Gift card updated.", + "card x added" => "Gift card #{arg} added.", + "card x saved" => "Gift card #{arg} updated.", ]); diff --git a/lang/messages.php b/lang/messages.php index 7336b33..e78e17f 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -53,4 +53,12 @@ define("MESSAGES", [ "string" => "cannot edit return transaction", "type" => "danger" ], + "card_x_added" => [ + "string" => "card x added", + "type" => "success" + ], + "card_x_saved" => [ + "string" => "card x saved", + "type" => "success" + ], ]); diff --git a/pages.php b/pages.php index afcb399..43d48a0 100644 --- a/pages.php +++ b/pages.php @@ -81,6 +81,28 @@ define("PAGES", [ "static/js/editregister.js" ] ], + "certificates" => [ + "title" => "gift cards", + "navbar" => true, + "icon" => "fas fa-gift", + "styles" => [ + "static/css/datatables.min.css", + "static/css/tables.css" + ], + "scripts" => [ + "static/js/bsalert.js", + "static/js/datatables.min.js", + "static/js/certificates.js" + ], + ], + "editcertificate" => [ + "title" => "edit certificate", + "navbar" => false, + "scripts" => [ + "static/js/input_type_money.js", + "static/js/editcertificate.js" + ] + ], "reports" => [ "title" => "reports", "navbar" => true, diff --git a/pages/certificates.php b/pages/certificates.php new file mode 100644 index 0000000..2a1611c --- /dev/null +++ b/pages/certificates.php @@ -0,0 +1,60 @@ +select('certificates', ['certid (id)', 'certcode (code)', 'amount', 'start_amount (start)', 'issued'], ['deleted[!]' => 1]); +?> + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + $$
\ No newline at end of file diff --git a/pages/editcertificate.php b/pages/editcertificate.php new file mode 100644 index 0000000..5f7fe4d --- /dev/null +++ b/pages/editcertificate.php @@ -0,0 +1,82 @@ + '', + 'code' => '', + 'amount' => 0, + 'start' => 0 +]; + +$editing = false; + +if (!empty($VARS['id']) && !is_empty($VARS['id'])) { + if ($database->has('certificates', ['certid' => $VARS['id']])) { + $editing = true; + $carddata = $database->get( + 'certificates', [ + 'certid (id)', + 'certcode (code)', + 'amount', + 'start_amount (start)' + ], [ + 'certid' => $VARS['id'] + ]); + } else { + // customer id is invalid, redirect to a version of the page that won't + // cause an error when pressing Save + header('Location: app.php?page=editcertificate'); + die(); + } +} + +if (!$editing) { + // Generate gift certificate number + do { + $carddata['code'] = random_int(100000000000, 999999999999); + } while ($database->has('certificates', ['certcode' => $carddata['code']])); +} +?> + +
+
+

+ + htmlspecialchars($carddata['code'])]); ?> + + + +

+
+
+ + +
+
+ + +
+
+ + + + + + + +
+
\ No newline at end of file diff --git a/static/js/certificates.js b/static/js/certificates.js new file mode 100644 index 0000000..c098b18 --- /dev/null +++ b/static/js/certificates.js @@ -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 certificatetable = $('#certificatetable').DataTable({ + responsive: { + details: { + display: $.fn.dataTable.Responsive.display.modal({ + header: function (row) { + var data = row.data(); + return " " + data[2]; + } + }), + renderer: $.fn.dataTable.Responsive.renderer.tableAll({ + tableClass: 'table' + }), + type: "column" + } + }, + columnDefs: [ + { + targets: 0, + className: 'control', + orderable: false + }, + { + targets: 1, + orderable: false + } + ], + order: [ + [5, 'asc'] + ] +}); \ No newline at end of file