Add gift certificate management, close #15
parent
a07820c666
commit
89adf1c3ac
@ -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>
|
@ -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>
|
@ -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…
Reference in New Issue