Add gift certificate management, close #15
This commit is contained in:
parent
a07820c666
commit
89adf1c3ac
41
action.php
41
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"]));
|
||||
|
@ -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.",
|
||||
]);
|
||||
|
@ -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"
|
||||
],
|
||||
]);
|
||||
|
22
pages.php
22
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,
|
||||
|
60
pages/certificates.php
Normal file
60
pages/certificates.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . "/../required.php";
|
||||
|
||||
use Medoo\Medoo;
|
||||
|
||||
redirectIfNotLoggedIn();
|
||||
|
||||
$cards = $database->select('certificates', ['certid (id)', 'certcode (code)', 'amount', 'start_amount (start)', 'issued'], ['deleted[!]' => 1]);
|
||||
?>
|
||||
|
||||
<div class="btn-toolbar">
|
||||
<a href="app.php?page=editcertificate" class="btn btn-success"><i class="fas fa-plus"></i> <?php lang("add card"); ?></a>
|
||||
</div>
|
||||
|
||||
<table id="certificatetable" class="table table-bordered table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-priority="0"></th>
|
||||
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||
<th data-priority="1"><i class="fas fa-fw fa-hashtag d-none d-md-inline"></i> <?php lang('card number'); ?></th>
|
||||
<th data-priority="2"><i class="fas fa-fw fa-balance-scale d-none d-md-inline"></i> <?php lang('balance'); ?></th>
|
||||
<th data-priority="3"><i class="fas fa-fw fa-play d-none d-md-inline"></i> <?php lang('start balance'); ?></th>
|
||||
<th data-priority="4"><i class="fas fa-fw fa-calendar d-none d-md-inline"></i> <?php lang('issued'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($cards as $c) {
|
||||
?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<a class="btn btn-primary btn-sm" href="app.php?page=editcertificate&id=<?php echo $c['id']; ?>"><i class="fas fa-edit"></i> <?php lang("edit"); ?></a>
|
||||
</td>
|
||||
<td><?php echo $c['code']; ?></td>
|
||||
<td>$<?php echo number_format($c['amount'], 2); ?></td>
|
||||
<td>$<?php echo number_format($c['start'], 2); ?></td>
|
||||
<td><?php echo date(DATETIME_FORMAT, strtotime($c['issued'])); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th data-priority="0"></th>
|
||||
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||
<th data-priority="1"><i class="fas fa-fw fa-hashtag d-none d-md-inline"></i> <?php lang('card number'); ?></th>
|
||||
<th data-priority="2"><i class="fas fa-fw fa-balance-scale d-none d-md-inline"></i> <?php lang('balance'); ?></th>
|
||||
<th data-priority="3"><i class="fas fa-fw fa-play d-none d-md-inline"></i> <?php lang('start balance'); ?></th>
|
||||
<th data-priority="4"><i class="fas fa-fw fa-calendar d-none d-md-inline"></i> <?php lang('issued'); ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
82
pages/editcertificate.php
Normal file
82
pages/editcertificate.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/* 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/. */
|
||||
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
|
||||
$carddata = [
|
||||
'id' => '',
|
||||
'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']]));
|
||||
}
|
||||
?>
|
||||
|
||||
<form role="form" action="action.php" method="POST">
|
||||
<div class="card border-green">
|
||||
<h3 class="card-header text-green">
|
||||
<?php
|
||||
if ($editing) {
|
||||
?>
|
||||
<i class="fas fa-edit"></i> <?php lang2("editing card x", ['code' => htmlspecialchars($carddata['code'])]); ?>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<i class="fas fa-edit"></i> <?php lang("adding card"); ?>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</h3>
|
||||
<div class="card-body row">
|
||||
<div class="form-group col-sm-6">
|
||||
<label for="code"><i class="fas fa-hashtag"></i> <?php lang("card number"); ?></label>
|
||||
<input type="text" class="form-control disabled" id="code" value="<?php echo $carddata['code']; ?>" disabled />
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label for="balance"><i class="fas fa-balance-scale"></i> <?php lang("balance"); ?></label>
|
||||
<input type="money" class="form-control" id="balance" name="balance" value="<?php echo number_format($carddata['amount'], 2); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="id" value="<?php echo $carddata['id']; ?>" />
|
||||
<input type="hidden" name="code" value="<?php echo $carddata['code']; ?>" />
|
||||
<input type="hidden" name="action" value="editcertificate" />
|
||||
<input type="hidden" name="source" value="certificates" />
|
||||
|
||||
<div class="card-footer d-flex">
|
||||
<button type="submit" class="btn btn-success mr-auto"><i class="fas fa-save"></i> <?php lang("save"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
34
static/js/certificates.js
Normal file
34
static/js/certificates.js
Normal file
@ -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 "<i class=\"fas fa-hashtag fa-fw\"></i> " + 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']
|
||||
]
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user