commit
86407f731b
@ -172,12 +172,12 @@ switch ($action) {
|
|||||||
$server = _post('server');
|
$server = _post('server');
|
||||||
$planId = _post('plan');
|
$planId = _post('plan');
|
||||||
$using = _post('using');
|
$using = _post('using');
|
||||||
$stoken = _post('stoken');
|
$svoucher = _post('svoucher');
|
||||||
|
|
||||||
$plan = ORM::for_table('tbl_plans')->find_one($planId);
|
$plan = ORM::for_table('tbl_plans')->find_one($planId);
|
||||||
|
|
||||||
if (!empty(App::getTokenValue($stoken))) {
|
if (!empty(App::getVoucherValue($svoucher))) {
|
||||||
$username = App::getTokenValue($stoken);
|
$username = App::getVoucherValue($svoucher);
|
||||||
$in = ORM::for_table('tbl_transactions')->where('username', $username)->order_by_desc('id')->find_one();
|
$in = ORM::for_table('tbl_transactions')->where('username', $username)->order_by_desc('id')->find_one();
|
||||||
Package::createInvoice($in);
|
Package::createInvoice($in);
|
||||||
$ui->display('invoice.tpl');
|
$ui->display('invoice.tpl');
|
||||||
@ -238,7 +238,7 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
$in = ORM::for_table('tbl_transactions')->where('username', $cust['username'])->order_by_desc('id')->find_one();
|
$in = ORM::for_table('tbl_transactions')->where('username', $cust['username'])->order_by_desc('id')->find_one();
|
||||||
Package::createInvoice($in);
|
Package::createInvoice($in);
|
||||||
App::setToken($stoken, $cust['username']);
|
App::setVoucher($svoucher, $cust['username']);
|
||||||
$ui->display('invoice.tpl');
|
$ui->display('invoice.tpl');
|
||||||
_log('[' . $admin['username'] . ']: ' . 'Recharge ' . $cust['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
|
_log('[' . $admin['username'] . ']: ' . 'Recharge ' . $cust['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
|
||||||
} else {
|
} else {
|
||||||
@ -425,7 +425,7 @@ switch ($action) {
|
|||||||
$ui->assign('_system_menu', 'cards');
|
$ui->assign('_system_menu', 'cards');
|
||||||
|
|
||||||
$query = ORM::for_table('tbl_plans')
|
$query = ORM::for_table('tbl_plans')
|
||||||
->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'));
|
->inner_join('tbl_voucher', ['tbl_plans.id', '=', 'tbl_voucher.id_plan']);
|
||||||
|
|
||||||
if (!empty($router)) {
|
if (!empty($router)) {
|
||||||
$query->where('tbl_voucher.routers', $router);
|
$query->where('tbl_voucher.routers', $router);
|
||||||
@ -669,6 +669,7 @@ switch ($action) {
|
|||||||
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) {
|
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) {
|
||||||
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
|
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = _post('type');
|
$type = _post('type');
|
||||||
$plan = _post('plan');
|
$plan = _post('plan');
|
||||||
$voucher_format = _post('voucher_format');
|
$voucher_format = _post('voucher_format');
|
||||||
@ -676,18 +677,21 @@ switch ($action) {
|
|||||||
$server = _post('server');
|
$server = _post('server');
|
||||||
$numbervoucher = _post('numbervoucher');
|
$numbervoucher = _post('numbervoucher');
|
||||||
$lengthcode = _post('lengthcode');
|
$lengthcode = _post('lengthcode');
|
||||||
|
$printNow = _post('print_now', 'no');
|
||||||
|
|
||||||
$msg = '';
|
$msg = '';
|
||||||
if ($type == '' or $plan == '' or $server == '' or $numbervoucher == '' or $lengthcode == '') {
|
if (empty($type) || empty($plan) || empty($server) || empty($numbervoucher) || empty($lengthcode)) {
|
||||||
$msg .= Lang::T('All field is required') . '<br>';
|
$msg .= Lang::T('All fields are required') . '<br>';
|
||||||
}
|
}
|
||||||
if (Validator::UnsignedNumber($numbervoucher) == false) {
|
if (!Validator::UnsignedNumber($numbervoucher)) {
|
||||||
$msg .= 'The Number of Vouchers must be a number' . '<br>';
|
$msg .= 'The Number of Vouchers must be a number' . '<br>';
|
||||||
}
|
}
|
||||||
if (Validator::UnsignedNumber($lengthcode) == false) {
|
if (!Validator::UnsignedNumber($lengthcode)) {
|
||||||
$msg .= 'The Length Code must be a number' . '<br>';
|
$msg .= 'The Length Code must be a number' . '<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($msg == '') {
|
if ($msg == '') {
|
||||||
|
// Update or create voucher prefix
|
||||||
if (!empty($prefix)) {
|
if (!empty($prefix)) {
|
||||||
$d = ORM::for_table('tbl_appconfig')->where('setting', 'voucher_prefix')->find_one();
|
$d = ORM::for_table('tbl_appconfig')->where('setting', 'voucher_prefix')->find_one();
|
||||||
if ($d) {
|
if ($d) {
|
||||||
@ -700,11 +704,14 @@ switch ($action) {
|
|||||||
$d->save();
|
$d->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
run_hook('create_voucher'); #HOOK
|
|
||||||
|
run_hook('create_voucher'); // HOOK
|
||||||
$vouchers = [];
|
$vouchers = [];
|
||||||
|
$newVoucherIds = [];
|
||||||
|
|
||||||
if ($voucher_format == 'numbers') {
|
if ($voucher_format == 'numbers') {
|
||||||
if (strlen($lengthcode) < 6) {
|
if ($lengthcode < 6) {
|
||||||
$msg .= 'The Length Code must be a more than 6 for numbers' . '<br>';
|
$msg .= 'The Length Code must be more than 6 for numbers' . '<br>';
|
||||||
}
|
}
|
||||||
$vouchers = generateUniqueNumericVouchers($numbervoucher, $lengthcode);
|
$vouchers = generateUniqueNumericVouchers($numbervoucher, $lengthcode);
|
||||||
} else {
|
} else {
|
||||||
@ -724,12 +731,47 @@ switch ($action) {
|
|||||||
$d->type = $type;
|
$d->type = $type;
|
||||||
$d->routers = $server;
|
$d->routers = $server;
|
||||||
$d->id_plan = $plan;
|
$d->id_plan = $plan;
|
||||||
$d->code = $prefix . $code;
|
$d->code = "$prefix$code";
|
||||||
$d->user = '0';
|
$d->user = '0';
|
||||||
$d->status = '0';
|
$d->status = '0';
|
||||||
$d->generated_by = $admin['id'];
|
$d->generated_by = $admin['id'];
|
||||||
$d->save();
|
$d->save();
|
||||||
|
$newVoucherIds[] = $d->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($printNow == 'yes' && count($newVoucherIds) > 0) {
|
||||||
|
$template = file_get_contents("pages/Voucher.html");
|
||||||
|
$template = str_replace('[[company_name]]', $config['CompanyName'], $template);
|
||||||
|
|
||||||
|
$vouchersToPrint = ORM::for_table('tbl_voucher')
|
||||||
|
->left_outer_join('tbl_plans', ['tbl_plans.id', '=', 'tbl_voucher.id_plan'])
|
||||||
|
->where_in('tbl_voucher.id', $newVoucherIds)
|
||||||
|
->find_many();
|
||||||
|
|
||||||
|
$voucherHtmls = [];
|
||||||
|
$n = 1;
|
||||||
|
|
||||||
|
foreach ($vouchersToPrint as $vs) {
|
||||||
|
$temp = $template;
|
||||||
|
$temp = str_replace('[[qrcode]]', '<img src="qrcode/?data=' . $vs['code'] . '">', $temp);
|
||||||
|
$temp = str_replace('[[price]]', Lang::moneyFormat($vs['price']), $temp);
|
||||||
|
$temp = str_replace('[[voucher_code]]', $vs['code'], $temp);
|
||||||
|
$temp = str_replace('[[plan]]', $vs['name_plan'], $temp);
|
||||||
|
$temp = str_replace('[[counter]]', $n, $temp);
|
||||||
|
$voucherHtmls[] = $temp;
|
||||||
|
$n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$vc = count($voucherHtmls);
|
||||||
|
$ui->assign('voucher', $voucherHtmls);
|
||||||
|
$ui->assign('vc', $vc);
|
||||||
|
$ui->assign('jml', 0);
|
||||||
|
$ui->assign('from_id', 0);
|
||||||
|
$ui->assign('vpl', '3');
|
||||||
|
$ui->assign('pagebreak', '12');
|
||||||
|
$ui->display('print-voucher.tpl');
|
||||||
|
}
|
||||||
|
|
||||||
if ($numbervoucher == 1) {
|
if ($numbervoucher == 1) {
|
||||||
r2(U . 'plan/voucher-view/' . $d->id(), 's', Lang::T('Create Vouchers Successfully'));
|
r2(U . 'plan/voucher-view/' . $d->id(), 's', Lang::T('Create Vouchers Successfully'));
|
||||||
}
|
}
|
||||||
@ -740,6 +782,43 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'voucher-delete-many':
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$admin = Admin::_info();
|
||||||
|
|
||||||
|
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => Lang::T('You do not have permission to access this page')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$voucherIds = json_decode($_POST['voucherIds'], true);
|
||||||
|
|
||||||
|
if (is_array($voucherIds) && !empty($voucherIds)) {
|
||||||
|
$voucherIds = array_map('intval', $voucherIds);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ORM::for_table('tbl_voucher')
|
||||||
|
->where_in('id', $voucherIds)
|
||||||
|
->delete_many();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => Lang::T('Failed to delete vouchers.')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return success response
|
||||||
|
echo json_encode(['status' => 'success', 'message' => Lang::T("Vouchers Deleted Successfully.")]);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => Lang::T("Invalid or missing voucher IDs.")]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => Lang::T("Invalid request method.")]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'voucher-view':
|
case 'voucher-view':
|
||||||
$id = $routes[2];
|
$id = $routes[2];
|
||||||
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
|
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
|
||||||
@ -865,10 +944,10 @@ switch ($action) {
|
|||||||
$amount = _post('amount');
|
$amount = _post('amount');
|
||||||
$plan = _post('id_plan');
|
$plan = _post('id_plan');
|
||||||
$note = _post('note');
|
$note = _post('note');
|
||||||
$stoken = _req('stoken');
|
$svoucher = _req('svoucher');
|
||||||
$c = ORM::for_table('tbl_customers')->find_one($user);
|
$c = ORM::for_table('tbl_customers')->find_one($user);
|
||||||
if (App::getTokenValue($stoken)) {
|
if (App::getVoucherValue($svoucher)) {
|
||||||
$in = ORM::for_table('tbl_transactions')->find_one(App::getTokenValue($stoken));
|
$in = ORM::for_table('tbl_transactions')->find_one(App::getVoucherValue($svoucher));
|
||||||
Package::createInvoice($in);
|
Package::createInvoice($in);
|
||||||
$ui->display('invoice.tpl');
|
$ui->display('invoice.tpl');
|
||||||
die();
|
die();
|
||||||
@ -883,8 +962,8 @@ switch ($action) {
|
|||||||
if ($trxId > 0) {
|
if ($trxId > 0) {
|
||||||
$in = ORM::for_table('tbl_transactions')->find_one($trxId);
|
$in = ORM::for_table('tbl_transactions')->find_one($trxId);
|
||||||
Package::createInvoice($in);
|
Package::createInvoice($in);
|
||||||
if (!empty($stoken)) {
|
if (!empty($svoucher)) {
|
||||||
App::setToken($stoken, $trxId);
|
App::setVoucher($svoucher, $trxId);
|
||||||
}
|
}
|
||||||
$ui->display('invoice.tpl');
|
$ui->display('invoice.tpl');
|
||||||
} else {
|
} else {
|
||||||
@ -896,8 +975,8 @@ switch ($action) {
|
|||||||
if ($trxId > 0) {
|
if ($trxId > 0) {
|
||||||
$in = ORM::for_table('tbl_transactions')->find_one($trxId);
|
$in = ORM::for_table('tbl_transactions')->find_one($trxId);
|
||||||
Package::createInvoice($in);
|
Package::createInvoice($in);
|
||||||
if (!empty($stoken)) {
|
if (!empty($svoucher)) {
|
||||||
App::setToken($stoken, $trxId);
|
App::setVoucher($svoucher, $trxId);
|
||||||
}
|
}
|
||||||
$ui->display('invoice.tpl');
|
$ui->display('invoice.tpl');
|
||||||
} else {
|
} else {
|
||||||
@ -910,8 +989,8 @@ switch ($action) {
|
|||||||
case 'extend':
|
case 'extend':
|
||||||
$id = $routes[2];
|
$id = $routes[2];
|
||||||
$days = $routes[3];
|
$days = $routes[3];
|
||||||
$stoken = $_GET['stoken'];
|
$svoucher = $_GET['svoucher'];
|
||||||
if (App::getTokenValue($stoken)) {
|
if (App::getVoucherValue($svoucher)) {
|
||||||
r2(U . 'plan', 's', "Extend already done");
|
r2(U . 'plan', 's', "Extend already done");
|
||||||
}
|
}
|
||||||
$tur = ORM::for_table('tbl_user_recharges')->find_one($id);
|
$tur = ORM::for_table('tbl_user_recharges')->find_one($id);
|
||||||
@ -924,7 +1003,7 @@ switch ($action) {
|
|||||||
//expired
|
//expired
|
||||||
$expiration = date('Y-m-d', strtotime(" +$days day"));
|
$expiration = date('Y-m-d', strtotime(" +$days day"));
|
||||||
}
|
}
|
||||||
App::setToken($stoken, $id);
|
App::setVoucher($svoucher, $id);
|
||||||
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
|
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
|
||||||
if ($c) {
|
if ($c) {
|
||||||
$p = ORM::for_table('tbl_plans')->find_one($tur['plan_id']);
|
$p = ORM::for_table('tbl_plans')->find_one($tur['plan_id']);
|
||||||
|
@ -71,6 +71,14 @@
|
|||||||
<input type="text" class="form-control" name="lengthcode" value="12">
|
<input type="text" class="form-control" name="lengthcode" value="12">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="inputSkills" class="col-sm-2 control-label">{Lang::T('Print Now')}</label>
|
||||||
|
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="checkbox" id="print_now" name="print_now" class="iCheck" value="yes">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-lg-offset-2 col-lg-10">
|
<div class="col-lg-offset-2 col-lg-10">
|
||||||
<button class="btn btn-success" onclick="return ask(this, 'Continue the Voucher creation process?')" type="submit">{Lang::T('Generate')}</button>
|
<button class="btn btn-success" onclick="return ask(this, 'Continue the Voucher creation process?')" type="submit">{Lang::T('Generate')}</button>
|
||||||
|
@ -90,6 +90,7 @@
|
|||||||
<table id="datatable" class="table table-bordered table-striped table-condensed">
|
<table id="datatable" class="table table-bordered table-striped table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th><input type="checkbox" id="select-all"></th>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>{Lang::T('Type')}</th>
|
<th>{Lang::T('Type')}</th>
|
||||||
<th>{Lang::T('Routers')}</th>
|
<th>{Lang::T('Routers')}</th>
|
||||||
@ -106,6 +107,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{foreach $d as $ds}
|
{foreach $d as $ds}
|
||||||
<tr {if $ds['status'] eq '1' }class="danger" {/if}>
|
<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['id']}</td>
|
||||||
<td>{$ds['type']}</td>
|
<td>{$ds['type']}</td>
|
||||||
<td>{$ds['routers']}</td>
|
<td>{$ds['routers']}</td>
|
||||||
@ -145,6 +147,112 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{include file="pagination.tpl"}
|
|
||||||
</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}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{include file="pagination.tpl"}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function deleteVouchers(voucherIds) {
|
||||||
|
if (voucherIds.length > 0) {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Are you sure?',
|
||||||
|
text: 'You won\'t be able to revert this!',
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'Yes, delete it!',
|
||||||
|
cancelButtonText: 'Cancel'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', '{$_url}plan/voucher-delete-many', true);
|
||||||
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
|
xhr.onload = function () {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
var response = JSON.parse(xhr.responseText);
|
||||||
|
|
||||||
|
if (response.status === 'success') {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Deleted!',
|
||||||
|
text: response.message,
|
||||||
|
icon: 'success',
|
||||||
|
confirmButtonText: 'OK'
|
||||||
|
}).then(() => {
|
||||||
|
location.reload(); // Reload the page after confirmation
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error!',
|
||||||
|
text: response.message,
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'OK'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error!',
|
||||||
|
text: 'Failed to delete vouchers. Please try again.',
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'OK'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send('voucherIds=' + JSON.stringify(voucherIds));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error!',
|
||||||
|
text: 'No vouchers selected to delete.',
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'OK'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example usage for selected vouchers
|
||||||
|
document.getElementById('deleteSelectedVouchers').addEventListener('click', function () {
|
||||||
|
var selectedVouchers = [];
|
||||||
|
document.querySelectorAll('input[name="voucher_ids[]"]:checked').forEach(function (checkbox) {
|
||||||
|
selectedVouchers.push(checkbox.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selectedVouchers.length > 0) {
|
||||||
|
deleteVouchers(selectedVouchers);
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error!',
|
||||||
|
text: 'Please select at least one voucher to delete.',
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'OK'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('.delete-voucher').forEach(function (button) {
|
||||||
|
button.addEventListener('click', function () {
|
||||||
|
var voucherId = this.getAttribute('data-id');
|
||||||
|
deleteVouchers([voucherId]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Select or deselect all checkboxes
|
||||||
|
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>
|
||||||
{include file="sections/footer.tpl"}
|
{include file="sections/footer.tpl"}
|
Loading…
x
Reference in New Issue
Block a user