feat: add batch name input and enhance voucher management UI, and also you can now generate and print vouchers in group: batch name or Date.

This commit is contained in:
Focuslinkstech 2025-04-18 15:20:09 +01:00
parent e50d7f901d
commit 230a9ddecd
4 changed files with 233 additions and 242 deletions

View file

@ -280,7 +280,7 @@ switch ($action) {
$ui->assign('hlogo', $height);
}
$ui->assign('public_url', getUrl("voucher/invoice/$id/".md5($id. $db_pass)));
$ui->assign('public_url', getUrl("voucher/invoice/$id/" . md5($id . $db_pass)));
$ui->assign('logo', $logo);
$ui->assign('_title', 'View Invoice');
$ui->display('admin/plan/invoice.tpl');
@ -501,7 +501,7 @@ switch ($action) {
$query->where_in('generated_by', $sales);
}
}
$d = Paginator::findMany($query, ["search" => $search], 10, $append_url);
$d = $query->find_many();
// extract admin
$admins = [];
foreach ($d as $k) {
@ -525,6 +525,7 @@ switch ($action) {
}
}
$ui->assign('xheader', '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">');
$ui->assign('admins', $admins);
$ui->assign('d', $d);
$ui->assign('search', $search);
@ -572,120 +573,78 @@ switch ($action) {
$pagebreak = _post('pagebreak');
$limit = _post('limit');
$vpl = _post('vpl');
$batch = _post('batch');
$group = _post('group');
$selected_datetime = _post('selected_datetime');
if (empty($vpl)) {
if (empty($vpl))
$vpl = 3;
}
if ($pagebreak < 1)
$pagebreak = 12;
if ($limit < 1)
$limit = $pagebreak * 2;
if (empty($from_id)) {
if (empty($from_id))
$from_id = 0;
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0');
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0');
if ($planid > 0) {
$v = $v->where('tbl_plans.id', $planid);
$vc = $vc->where('tbl_plans.id', $planid);
}
if ($from_id > 0 && $planid > 0) {
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_plans.id', $planid)
->where_gt('tbl_voucher.id', $from_id)
->limit($limit);
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_plans.id', $planid)
->where_gt('tbl_voucher.id', $from_id);
} else if ($from_id == 0 && $planid > 0) {
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_plans.id', $planid)
->limit($limit);
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_plans.id', $planid);
} else if ($from_id > 0 && $planid == 0) {
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where_gt('tbl_voucher.id', $from_id)
->limit($limit);
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where_gt('tbl_voucher.id', $from_id);
} else if ($from_id > 0 && $planid == 0 && $selected_datetime != '') {
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where_raw("DATE(created_at) = ?", [$selected_datetime])
->where_gt('tbl_voucher.id', $from_id)
->limit($limit);
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where_gt('tbl_voucher.id', $from_id);
} else {
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->limit($limit);
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0');
if ($from_id > 0) {
$v = $v->where_gt('tbl_voucher.id', $from_id);
$vc = $vc->where_gt('tbl_voucher.id', $from_id);
}
if (!empty($selected_datetime)) {
$v = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_voucher.created_at', $selected_datetime)
->limit($limit);
$vc = ORM::for_table('tbl_plans')
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0');
// Group filters (date or batch)
if (!empty($group)) {
if ($group == 'datetime' && !empty($selected_datetime)) {
$dateFilter = date('Y-m-d', strtotime($selected_datetime));
$v = $v->where_raw("DATE(tbl_voucher.created_at) = ?", [$dateFilter]);
$vc = $vc->where_raw("DATE(tbl_voucher.created_at) = ?", [$dateFilter]);
} elseif ($group == 'batch' && !empty($batch)) {
switch ($batch) {
case 'all':
$v = $v->where_not_equal('tbl_voucher.batch_name', '');
$vc = $vc->where_not_equal('tbl_voucher.batch_name', '');
break;
default:
$v = $v->where('tbl_voucher.batch_name', $batch);
$vc = $vc->where('tbl_voucher.batch_name', $batch);
break;
}
}
}
// Limit only to main query
$v = $v->limit($limit);
// Admin vs non-admin check
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
$v = $v->find_many();
$vc = $vc->count();
} else {
$sales = [];
$sales = [$admin['id']];
$sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray();
foreach ($sls as $s) {
$sales[] = $s['id'];
}
$sales[] = $admin['id'];
$v = $v->where_in('generated_by', $sales)->find_many();
$vc = $vc->where_in('generated_by', $sales)->count();
}
// Voucher template and data
$template = file_get_contents("pages/Voucher.html");
$template = str_replace('[[company_name]]', $config['CompanyName'], $template);
$ui->assign('_title', Lang::T('Hotspot Voucher'));
$ui->assign('from_id', $from_id);
$ui->assign('vpl', $vpl);
$ui->assign('pagebreak', $pagebreak);
$plans = ORM::for_table('tbl_plans')->find_many();
$ui->assign('plans', $plans);
$ui->assign('limit', $limit);
$ui->assign('planid', $planid);
$createdate = ORM::for_table('tbl_voucher')
->select_expr(
"CASE WHEN DATE(created_at) = CURDATE() THEN 'Today' ELSE DATE(created_at) END",
'created_datetime'
)
->where_not_equal('created_at', '0')
->select_expr('COUNT(*)', 'voucher_count')
->group_by('created_datetime')
->order_by_desc('created_datetime')
->find_array();
$ui->assign('createdate', $createdate);
$voucher = [];
$n = 1;
foreach ($v as $vs) {
@ -699,12 +658,43 @@ switch ($action) {
$n++;
}
// Additional data for the view
$plans = ORM::for_table('tbl_plans')->find_many();
$createdate = ORM::for_table('tbl_voucher')
->select_expr(
"CASE WHEN DATE(created_at) = CURDATE() THEN 'Today' ELSE DATE(created_at) END",
'created_datetime'
)
->where_not_equal('created_at', '0')
->select_expr('COUNT(*)', 'voucher_count')
->group_by('created_datetime')
->order_by_desc('created_datetime')
->find_array();
$batches = ORM::for_table('tbl_voucher')
->select('batch_name')
->distinct()
->where_not_equal('batch_name', '')
->order_by_desc('created_at')
->find_many();
$ui->assign('_title', Lang::T('Hotspot Voucher'));
$ui->assign('from_id', $from_id);
$ui->assign('vpl', $vpl);
$ui->assign('pagebreak', $pagebreak);
$ui->assign('plans', $plans);
$ui->assign('limit', $limit);
$ui->assign('planid', $planid);
$ui->assign('createdate', $createdate);
$ui->assign('voucher', $voucher);
$ui->assign('vc', $vc);
$ui->assign('selected_datetime', $selected_datetime);
//for counting pagebreak
$ui->assign('batches', $batches);
$ui->assign('selected_batch', $batch);
$ui->assign('group', $group);
$ui->assign('jml', 0);
run_hook('view_print_voucher'); #HOOK
$ui->display('admin/print/voucher.tpl');
break;
@ -725,6 +715,7 @@ switch ($action) {
$lengthcode = _post('lengthcode');
$printNow = _post('print_now', 'no');
$voucherPerPage = _post('voucher_per_page', '36');
$batch_name = _post('batch_name', '');
$msg = '';
if (empty($type) || empty($plan) || empty($server) || empty($numbervoucher) || empty($lengthcode)) {
@ -734,7 +725,7 @@ switch ($action) {
$msg .= 'The Number of Vouchers must be a number' . '<br>';
}
if (!Validator::UnsignedNumber($lengthcode)) {
$msg .= 'The Length Code must be a number' . '<br>';
$msg .= "The Length Code must be a number<br>";
}
if ($msg == '') {
@ -758,7 +749,7 @@ switch ($action) {
if ($voucher_format == 'numbers') {
if ($lengthcode < 6) {
$msg .= 'The Length Code must be more than 6 for numbers' . '<br>';
$msg .= "The Length Code must be more than 6 for numbers<br>";
}
$vouchers = generateUniqueNumericVouchers($numbervoucher, $lengthcode);
} else {
@ -782,6 +773,7 @@ switch ($action) {
$d->user = '0';
$d->status = '0';
$d->generated_by = $admin['id'];
$d->batch_name = $batch_name;
$d->save();
$newVoucherIds[] = $d->id();
}

View file

@ -66,69 +66,105 @@
<td>From ID &gt; <input type="text" name="from_id" style="width:40px" value="{$from_id}"> limit
<input type="text" name="limit" style="width:40px" value="{$limit}">
</td>
<td>Voucher PerLine <input type="text" style="width:40px" name="vpl" value="{$vpl}"> vouchers
<td>Voucher PerLine <input type="text" style="width:40px" name="vpl" value="{$vpl}">
</td>
<td>PageBreak after <input type="text" style="width:40px" name="pagebreak" value="{$pagebreak}">
vouchers
</td>
<td>Plans <select id="plan_id" name="planid" style="width:50px">
<option value="0">--all--</option>
{foreach $plans as $plan}
<option value="{$plan['id']}" {if $plan['id']==$planid}selected{/if}>{$plan['name_plan']}
</option>
<option value="{$plan['id']}" {if $plan['id']==$planid}selected{/if}>{$plan['name_plan']}
</option>
{/foreach}
</select></td>
<td>Date <select id="selected_datetime" name="selected_datetime" style="width:50px">
<td>Group
<select id="group" name="group" style="width:50px" onchange="toggleOptions()">
<option value="datetime" {if $group eq 'datetime' }selected{/if}> Date
</option>
<option value="batch" {if $group eq 'batch' }selected{/if}> Batch
</option>
</select>
</td>
<td style="display: none;" id="td-batch">Batch
<select id="batch" name="batch" style="width:50px;">
<option value="all">--all--</option>
{foreach $batches as $batch}
<option value="{$batch.batch_name}" {if $batch.batch_name eq $selected_batch}selected{/if}>
{$batch.batch_name}
</option>
{/foreach}
</select>
</td>
<td style="display: none;" id="td-datetime">Date
<select id="selected_datetime" name="selected_datetime" style="width:50px;">
<option value="">--all--</option>
{foreach $createdate as $date}
<option value="{$date.created_datetime}"
{if $date.created_datetime eq $selected_datetime}selected{/if}>
{$date.created_datetime} ({$date.voucher_count})
</option>
<option value="{$date.created_datetime}" {if $date.created_datetime eq
$selected_datetime}selected{/if}>
{$date.created_datetime} ({$date.voucher_count})
</option>
{/foreach}
</select></td>
</select>
</td>
<td><button type="submit">submit</button></td>
</tr>
</table>
<hr>
<center><button type="button" onclick="window.print()"
class="btn btn-default btn-sm no-print">{Lang::T('Click Here to Print')}</button><br>
class="btn btn-default btn-sm no-print">{Lang::T('Click
Here to Print')}</button><br>
{Lang::T('Print side by side, it will easy to cut')}<br> show {$v|@count} vouchers from {$vc}
vouchers<br> from ID {$v[0]['id']} limit {$limit} vouchers
</center>
</form>
<div id="printable" align="center">
<hr> {$n = 1} {foreach $voucher as $vs} {$jml = $jml + 1}
{if $n == 1}
<table>
<tr>
{/if}
<td>{$vs}</td>
{if $n == $vpl}
</table>
{$n = 1} {else} {$n = $n + 1} {/if} {if $jml == $pagebreak} {$jml = 0}
<!-- pageBreak -->
<div class="page-break">
<div class="no-print" style="background-color: #E91E63; color:#FFF;" align="center">-- pageBreak --
<hr>
</div>
</div>
{/if}
{if $n == 1}
<table>
<tr>
{/if}
<td>{$vs}</td>
{if $n == $vpl}
</table>
{$n = 1} {else} {$n = $n + 1} {/if} {if $jml == $pagebreak} {$jml = 0}
<!-- pageBreak -->
<div class="page-break">
<div class="no-print" style="background-color: #E91E63; color:#FFF;" align="center">-- pageBreak --
<hr>
</div>
</div>
{/if}
{/foreach}
</div>
</page>
<script src="{$app_url}/ui/ui/scripts/jquery.min.js"></script>
{if isset($xfooter)} {$xfooter} {/if}
<script>
jQuery(document).ready(function() {
jQuery(document).ready(function () {
// initiate layout and plugins
$("#actprint").click(function() {
$("#actprint").click(function () {
window.print();
return false;
});
});
</script>
<script>
function toggleOptions() {
const group = document.getElementById('group').value;
const tdBatch = document.getElementById('td-batch');
const tdDatetime = document.getElementById('td-datetime');
if (group === 'batch') {
tdBatch.style.display = 'block';
tdDatetime.style.display = 'none';
} else if (group === 'datetime') {
tdDatetime.style.display = 'block';
tdBatch.style.display = 'none';
}
}
toggleOptions();
</script>
</body>
</html>

View file

@ -31,6 +31,12 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Batch Name')}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="batch_name" value="" placeholder="{Lang::T('Batch 1')}">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Number of Vouchers')}</label>
<div class="col-md-6">

View file

@ -17,75 +17,16 @@
<div class="panel panel-hovered mb20 panel-primary">
<div class="panel-heading">
{if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
<div class="btn-group pull-right">
<a class="btn btn-danger btn-xs" title="Remove used Voucher" href="{Text::url('')}plan/remove-voucher"
onclick="return ask(this, 'Delete all used voucher code more than 3 months?')"><span
class="glyphicon glyphicon-trash" aria-hidden="true"></span> {Lang::T('Delete')} &gt; {Lang::T('3
<div class="btn-group pull-right">
<a class="btn btn-danger btn-xs" title="Remove used Voucher" href="{Text::url('')}plan/remove-voucher"
onclick="return ask(this, 'Delete all used voucher code more than 3 months?')"><span
class="glyphicon glyphicon-trash" aria-hidden="true"></span> {Lang::T('Delete')} &gt; {Lang::T('3
Months')}</a>
</div>
</div>
{/if}
&nbsp;
</div>
<div class="panel-body">
<form id="site-search" method="post" action="{Text::url('')}plan/voucher/">
<div class="row" style="padding: 5px">
<div class="col-lg-2">
<div class="input-group">
<div class="input-group-addon">
<span class="fa fa-search"></span>
</div>
<input type="text" name="search" class="form-control" placeholder="{Lang::T('Code Voucher')}"
value="{$search}">
</div>
</div>
<div class="col-lg-2">
<select class="form-control" id="router" name="router">
<option value="">{Lang::T('Location')}</option>
{foreach $routers as $r}
<option value="{$r}" {if $router eq $r }selected{/if}>{$r}
</option>
{/foreach}
</select>
</div>
<div class="col-lg-2">
<select class="form-control" id="plan" name="plan">
<option value="">{Lang::T('Plan Name')}</option>
{foreach $plans as $p}
<option value="{$p['id']}" {if $plan eq $p['id'] }selected{/if}>{$p['name_plan']}</option>
{/foreach}
</select>
</div>
<div class="col-lg-2">
<select class="form-control" id="status" name="status">
<option value="-">{Lang::T('Status')}</option>
<option value="1" {if $status eq 1 }selected{/if}>Used</option>
<option value="0" {if $status eq 0 }selected{/if}>Not Use</option>
</select>
</div>
<div class="col-lg-2">
<select class="form-control" id="customer" name="customer">
<option value="">{Lang::T('Customer')}</option>
{foreach $customers as $c}
<option value="{$c['user']}" {if $customer eq $c['user'] }selected{/if}>{$c['user']}</option>
{/foreach}
</select>
</div>
<div class="col-lg-2">
<div class="btn-group btn-group-justified" role="group">
<div class="btn-group" role="group">
<button class="btn btn-success btn-block" type="submit"><span
class="fa fa-search"></span></button>
</div>
<div class="btn-group" role="group">
<a class="btn btn-warning btn-block" title="Clear Search Query"
href="{Text::url('')}plan/voucher/"><span
class="glyphicon glyphicon-remove-circle"></span></a>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="table-responsive">
<div style="margin-left: 5px; margin-right: 5px;">&nbsp;
<table id="datatable" class="table table-bordered table-striped table-condensed">
@ -93,6 +34,7 @@
<tr>
<th><input type="checkbox" id="select-all"></th>
<th>ID</th>
<th>{Lang::T('Batch Name ')}</th>
<th>{Lang::T('Type')}</th>
<th>{Lang::T('Routers')}</th>
<th>{Lang::T('Plan Name')}</th>
@ -107,62 +49,72 @@
</thead>
<tbody>
{foreach $d as $ds}
<tr {if $ds['status'] eq '1' }class="danger" {/if}>
<td><input type="checkbox" name="voucher_ids[]" value="{$ds['id']}"></td>
<td>{$ds['id']}</td>
<td>{$ds['type']}</td>
<td>{$ds['routers']}</td>
<td>{$ds['name_plan']}</td>
<td style="background-color: black; color: black;"
onmouseleave="this.style.backgroundColor = 'black';"
onmouseenter="this.style.backgroundColor = 'white';">
{$ds['code']}</td>
<td>{if $ds['status'] eq '0'} <label class="btn-tag btn-tag-success"> Not Use
</label> {else} <label class="btn-tag btn-tag-danger">Used</label>
{/if}</td>
<td>{if $ds['user'] eq '0'} -
{else}<a href="{Text::url('')}customers/viewu/{$ds['user']}">{$ds['user']}</a>
{/if}</td>
<td>{if $ds['created_at']}{Lang::dateTimeFormat($ds['created_at'])}{/if}</td>
<td>{if $ds['used_date']}{Lang::dateTimeFormat($ds['used_date'])}{/if}</td>
<td>{if $ds['generated_by']}
<a
href="{Text::url('')}settings/users-view/{$ds['generated_by']}">{$admins[$ds['generated_by']]}</a>
{else} -
{/if}
</td>
<td>
{if $ds['status'] neq '1'}
<a href="{Text::url('')}plan/voucher-view/{$ds['id']}" id="{$ds['id']}" style="margin: 0px;"
class="btn btn-success btn-xs">&nbsp;&nbsp;{Lang::T('View')}&nbsp;&nbsp;</a>
{/if}
{if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
<a href="{Text::url('')}plan/voucher-delete/{$ds['id']}" id="{$ds['id']}"
class="btn btn-danger btn-xs" onclick="return ask(this, '{Lang::T('Delete')}?')"><i
class="glyphicon glyphicon-trash"></i></a>
{/if}
</td>
</tr>
<tr {if $ds['status'] eq '1' }class="danger" {/if}>
<td><input type="checkbox" name="voucher_ids[]" value="{$ds['id']}"></td>
<td>{$ds['id']}</td>
<td>{if empty($ds['batch_name'])}
{Lang::T('None')}
{else}
{$ds['batch_name']}
{/if}
</td>
<td>{$ds['type']}</td>
<td>{$ds['routers']}</td>
<td>{$ds['name_plan']}</td>
<td style="background-color: black; color: black;"
onmouseleave="this.style.backgroundColor = 'black';"
onmouseenter="this.style.backgroundColor = 'white';">
{$ds['code']}</td>
<td>{if $ds['status'] eq '0'} <label class="btn-tag btn-tag-success"> Not Use
</label> {else} <label class="btn-tag btn-tag-danger">Used</label>
{/if}</td>
<td>{if $ds['user'] eq '0'} -
{else}<a href="{Text::url('')}customers/viewu/{$ds['user']}">{$ds['user']}</a>
{/if}</td>
<td>{if $ds['created_at']}{Lang::dateTimeFormat($ds['created_at'])}{/if}</td>
<td>{if $ds['used_date']}{Lang::dateTimeFormat($ds['used_date'])}{/if}</td>
<td>{if $ds['generated_by']}
<a
href="{Text::url('')}settings/users-view/{$ds['generated_by']}">{$admins[$ds['generated_by']]}</a>
{else} -
{/if}
</td>
<td>
{if $ds['status'] neq '1'}
<a href="{Text::url('')}plan/voucher-view/{$ds['id']}" id="{$ds['id']}" style="margin: 0px;"
class="btn btn-success btn-xs">&nbsp;&nbsp;{Lang::T('View')}&nbsp;&nbsp;</a>
{/if}
{if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
<a href="{Text::url('')}plan/voucher-delete/{$ds['id']}" id="{$ds['id']}"
class="btn btn-danger btn-xs" onclick="return ask(this, '{Lang::T('Delete')}?')"><i
class="glyphicon glyphicon-trash"></i></a>
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
</div>
</div>
<div class="row" style="padding: 5px">
<div class="col-lg-3 col-lg-offset-9">
<div class="btn-group btn-group-justified" role="group">
<div class="btn-group" role="group">
{if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
<button id="deleteSelectedVouchers" class="btn btn-danger">{Lang::T('Delete
Selected')}</button>
{/if}
<br>
<div class="row" style="padding: 5px">
<div class="col-lg-3 col-lg-offset-9">
<div class="btn-group btn-group-justified" role="group">
<div class="btn-group" role="group">
{if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
<button id="deleteSelectedVouchers" class="btn btn-danger">{Lang::T('Delete
Selected')}</button>
{/if}
</div>
</div>
</div>
</div>
<br>
</div>
</div>
</div>
{include file="pagination.tpl"}
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script type="text/javascript" charset="utf8"
src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script>
function deleteVouchers(voucherIds) {
if (voucherIds.length > 0) {
@ -178,7 +130,7 @@
var xhr = new XMLHttpRequest();
xhr.open('POST', '{Text::url('')}plan/voucher-delete-many', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
xhr.onload = function () {
if (xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
@ -222,9 +174,9 @@
}
// Example usage for selected vouchers
document.getElementById('deleteSelectedVouchers').addEventListener('click', function() {
document.getElementById('deleteSelectedVouchers').addEventListener('click', function () {
var selectedVouchers = [];
document.querySelectorAll('input[name="voucher_ids[]"]:checked').forEach(function(checkbox) {
document.querySelectorAll('input[name="voucher_ids[]"]:checked').forEach(function (checkbox) {
selectedVouchers.push(checkbox.value);
});
@ -240,8 +192,8 @@
}
});
document.querySelectorAll('.delete-voucher').forEach(function(button) {
button.addEventListener('click', function() {
document.querySelectorAll('.delete-voucher').forEach(function (button) {
button.addEventListener('click', function () {
var voucherId = this.getAttribute('data-id');
deleteVouchers([voucherId]);
});
@ -249,11 +201,16 @@
// Select or deselect all checkboxes
document.getElementById('select-all').addEventListener('change', function() {
document.getElementById('select-all').addEventListener('change', function () {
var checkboxes = document.querySelectorAll('input[name="voucher_ids[]"]');
for (var checkbox of checkboxes) {
checkbox.checked = this.checked;
}
});
</script>
<script>
new DataTable('#datatable');
</script>
{include file="sections/footer.tpl"}