phpnuxbill/system/controllers/prepaid.php

494 lines
20 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2023-10-18 18:24:00 +08:00
2017-03-11 03:51:06 +08:00
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2021-08-19 14:38:29 +08:00
**/
2023-10-12 16:55:42 +08:00
2017-03-11 03:51:06 +08:00
_admin();
2022-10-13 15:00:54 +08:00
$ui->assign('_title', $_L['Recharge_Account']);
2017-03-11 03:51:06 +08:00
$ui->assign('_system_menu', 'prepaid');
$action = $routes['1'];
$admin = Admin::_info();
$ui->assign('_admin', $admin);
2021-08-19 14:38:29 +08:00
if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') {
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
2017-03-11 03:51:06 +08:00
}
2023-08-23 13:11:07 +08:00
$select2_customer = <<<EOT
<script>
document.addEventListener("DOMContentLoaded", function(event) {
$('#personSelect').select2({
theme: "bootstrap",
ajax: {
url: function(params) {
if(params.term != undefined){
return './index.php?_route=autoload/customer_select2&s='+params.term;
}else{
return './index.php?_route=autoload/customer_select2';
}
}
}
});
});
</script>
EOT;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
switch ($action) {
2023-09-15 15:15:43 +08:00
case 'sync':
set_time_limit(-1);
$plans = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
$log = '';
$router = '';
foreach ($plans as $plan) {
2023-10-12 16:47:45 +08:00
if ($router != $plan['routers'] && $plan['routers'] != 'radius') {
2023-09-15 15:15:43 +08:00
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
$p = ORM::for_table('tbl_plans')->findOne($plan['plan_id']);
$c = ORM::for_table('tbl_customers')->findOne($plan['customer_id']);
2023-10-18 18:24:00 +08:00
if ($plan['routers'] == 'radius') {
Radius::customerAddPlan($c, $p, $plan['expiration'] . ' ' . $plan['time']);
} else {
2023-10-12 16:47:45 +08:00
if ($plan['type'] == 'Hotspot') {
Mikrotik::addHotspotUser($client, $p, $c);
} else if ($plan['type'] == 'PPPOE') {
Mikrotik::addPpoeUser($client, $p, $c);
}
2023-09-15 15:15:43 +08:00
}
$log .= "DONE : $plan[username], $plan[namebp], $plan[type], $plan[routers]<br>";
}
r2(U . 'prepaid/list', 's', $log);
2021-08-19 14:38:29 +08:00
case 'list':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/prepaid.js"></script>');
2023-09-15 13:13:12 +08:00
$ui->assign('_title', $_L['Customers']);
2021-08-19 14:38:29 +08:00
$username = _post('username');
if ($username != '') {
2023-10-24 13:27:30 +08:00
$paginator = Paginator::build(ORM::for_table('tbl_user_recharges'), ['username' => '%' . $username . '%'], $username);
2021-08-19 14:38:29 +08:00
$d = ORM::for_table('tbl_user_recharges')->where_like('username', '%' . $username . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
} else {
2023-10-24 13:27:30 +08:00
$paginator = Paginator::build(ORM::for_table('tbl_user_recharges'));
2021-08-19 14:38:29 +08:00
$d = ORM::for_table('tbl_user_recharges')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
$ui->assign('d', $d);
2023-04-06 10:50:03 +08:00
$ui->assign('cari', $username);
2021-08-19 14:38:29 +08:00
$ui->assign('paginator', $paginator);
2022-09-18 01:00:40 +08:00
run_hook('view_list_billing'); #HOOK
2021-08-19 14:38:29 +08:00
$ui->display('prepaid.tpl');
2017-03-11 03:51:06 +08:00
break;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
case 'recharge':
2023-08-23 13:11:07 +08:00
$ui->assign('xfooter', $select2_customer);
2022-09-08 15:00:46 +08:00
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('p', $p);
2022-09-08 15:00:46 +08:00
$r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('r', $r);
2023-09-15 15:15:43 +08:00
if (isset($routes['2']) && !empty($routes['2'])) {
2023-09-15 12:33:46 +08:00
$ui->assign('cust', ORM::for_table('tbl_customers')->find_one($routes['2']));
}
2022-09-18 01:00:40 +08:00
run_hook('view_recharge'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('recharge.tpl');
break;
case 'recharge-user':
2021-08-19 14:38:29 +08:00
$id = $routes['2'];
$ui->assign('id', $id);
2017-03-11 03:51:06 +08:00
2021-08-19 14:38:29 +08:00
$c = ORM::for_table('tbl_customers')->find_many();
$ui->assign('c', $c);
2022-09-08 15:00:46 +08:00
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('p', $p);
2022-09-08 15:00:46 +08:00
$r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('r', $r);
2022-09-18 01:00:40 +08:00
run_hook('view_recharge_customer'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('recharge-user.tpl');
2021-08-19 14:38:29 +08:00
break;
2017-03-11 03:51:06 +08:00
case 'recharge-post':
$id_customer = _post('id_customer');
2021-08-19 14:38:29 +08:00
$type = _post('type');
2017-03-11 03:51:06 +08:00
$server = _post('server');
2021-08-19 14:38:29 +08:00
$plan = _post('plan');
$date_only = date("Y-m-d");
$time = date("H:i:s");
$msg = '';
if ($id_customer == '' or $type == '' or $server == '' or $plan == '') {
$msg .= 'All field is required' . '<br>';
}
if ($msg == '') {
2023-08-23 13:11:07 +08:00
if (Package::rechargeUser($id_customer, $server, $plan, "Recharge", $admin['fullname'])) {
2023-08-15 18:01:48 +08:00
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();
$ui->assign('in', $in);
$ui->assign('date', date("Y-m-d H:i:s"));
$ui->display('invoice.tpl');
2023-08-23 13:11:07 +08:00
_log('[' . $admin['username'] . ']: ' . 'Recharge ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', 'Admin', $admin['id']);
} else {
2023-08-15 18:01:48 +08:00
r2(U . 'prepaid/recharge', 'e', "Failed to recharge account");
2022-09-05 16:11:22 +08:00
}
2021-08-19 14:38:29 +08:00
} else {
2017-03-11 03:51:06 +08:00
r2(U . 'prepaid/recharge', 'e', $msg);
}
break;
2021-08-19 14:38:29 +08:00
2023-10-18 18:49:54 +08:00
case 'view':
$id = $routes['2'];
$d = ORM::for_table('tbl_transactions')->where('id', $id)->find_one();
$ui->assign('in', $d);
2023-10-24 13:27:30 +08:00
if (!empty($routes['3']) && $routes['3'] == 'send') {
2023-10-20 14:57:12 +08:00
$c = ORM::for_table('tbl_customers')->where('username', $d['username'])->find_one();
2023-10-24 13:27:30 +08:00
if ($c) {
2023-10-20 14:57:12 +08:00
Message::sendInvoice($c, $d);
2023-10-24 13:27:30 +08:00
r2(U . 'prepaid/view/' . $id, 's', "Success send to customer");
2023-10-20 14:57:12 +08:00
}
2023-10-24 13:27:30 +08:00
r2(U . 'prepaid/view/' . $id, 'd', "Customer not found");
2023-10-18 18:49:54 +08:00
}
2023-10-20 14:57:12 +08:00
$ui->assign('_title', 'View Invoice');
2023-10-24 13:27:30 +08:00
$ui->assign('date', Lang::dateAndTimeFormat($d['recharged_on'], $d['recharged_time']));
2023-10-18 18:49:54 +08:00
$ui->display('invoice.tpl');
break;
2021-08-19 14:38:29 +08:00
case 'print':
$id = _post('id');
$d = ORM::for_table('tbl_transactions')->where('id', $id)->find_one();
$ui->assign('d', $d);
2023-10-24 13:27:30 +08:00
$ui->assign('date', Lang::dateAndTimeFormat($d['recharged_on'], $d['recharged_time']));
2022-09-18 01:00:40 +08:00
run_hook('print_invoice'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('invoice-print.tpl');
break;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
case 'edit':
$id = $routes['2'];
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
2021-08-19 14:38:29 +08:00
if ($d) {
$ui->assign('d', $d);
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->where_not_equal('type', 'Balance')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('p', $p);
2022-09-18 01:00:40 +08:00
run_hook('view_edit_customer_plan'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('prepaid-edit.tpl');
2021-08-19 14:38:29 +08:00
} else {
2017-03-11 03:51:06 +08:00
r2(U . 'services/list', 'e', $_L['Account_Not_Found']);
}
break;
case 'delete':
$id = $routes['2'];
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
2021-08-19 14:38:29 +08:00
if ($d) {
2022-09-18 01:00:40 +08:00
run_hook('delete_customer_active_plan'); #HOOK
2023-10-04 17:11:55 +08:00
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
if ($p['is_radius']) {
Radius::customerDeactivate($d['username']);
} else {
$mikrotik = Mikrotik::info($d['routers']);
if ($d['type'] == 'Hotspot') {
2022-09-18 01:52:39 +08:00
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
2023-09-07 10:20:31 +08:00
Mikrotik::removeHotspotUser($client, $d['username']);
2023-09-13 10:37:05 +08:00
Mikrotik::removeHotspotActiveUser($client, $d['username']);
2023-10-04 17:11:55 +08:00
} else {
2022-09-18 01:52:39 +08:00
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
2023-09-07 10:20:31 +08:00
Mikrotik::removePpoeUser($client, $d['username']);
2023-09-13 10:37:05 +08:00
Mikrotik::removePpoeActive($client, $d['username']);
2021-08-19 14:38:29 +08:00
}
}
2023-10-04 17:11:55 +08:00
$d->delete();
2023-08-23 13:11:07 +08:00
_log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', 'Admin', $admin['id']);
2017-03-11 03:51:06 +08:00
r2(U . 'prepaid/list', 's', $_L['Delete_Successfully']);
}
break;
case 'edit-post':
$username = _post('username');
$id_plan = _post('id_plan');
$recharged_on = _post('recharged_on');
2021-08-19 14:38:29 +08:00
$expiration = _post('expiration');
2023-08-28 09:57:33 +08:00
$time = _post('time');
2017-03-11 03:51:06 +08:00
$id = _post('id');
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
2021-08-19 14:38:29 +08:00
if ($d) {
} else {
$msg .= $_L['Data_Not_Found'] . '<br>';
2017-03-11 03:51:06 +08:00
}
2023-11-15 12:08:18 +08:00
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one();
if ($d) {
} else {
$msg .= ' Plan Not Found<br>';
}
2021-08-19 14:38:29 +08:00
if ($msg == '') {
2022-09-18 01:00:40 +08:00
run_hook('edit_customer_plan'); #HOOK
2017-03-11 03:51:06 +08:00
$d->username = $username;
$d->plan_id = $id_plan;
2023-08-28 10:44:57 +08:00
//$d->recharged_on = $recharged_on;
2017-03-11 03:51:06 +08:00
$d->expiration = $expiration;
2023-08-28 09:57:33 +08:00
$d->time = $time;
2023-11-15 12:08:18 +08:00
$d->routers = $p['routers'];
2017-03-11 03:51:06 +08:00
$d->save();
2023-11-15 12:08:18 +08:00
Package::changeTo($username, $id_plan, $id);
2023-08-23 13:11:07 +08:00
_log('[' . $admin['username'] . ']: ' . 'Edit Plan for Customer ' . $d['username'] . ' to [' . $d['plan_name'] . '][' . Lang::moneyFormat($d['price']) . ']', 'Admin', $admin['id']);
2017-03-11 03:51:06 +08:00
r2(U . 'prepaid/list', 's', $_L['Updated_Successfully']);
2021-08-19 14:38:29 +08:00
} else {
r2(U . 'prepaid/edit/' . $id, 'e', $msg);
2017-03-11 03:51:06 +08:00
}
break;
2021-08-19 14:38:29 +08:00
case 'voucher':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/voucher.js"></script>');
$code = _post('code');
if ($code != '') {
$ui->assign('code', $code);
2023-10-24 13:27:30 +08:00
$paginator = Paginator::build(ORM::for_table('tbl_voucher'), ['code' => '%' . $code . '%'], $code);
2022-09-08 15:00:46 +08:00
$d = ORM::for_table('tbl_plans')->where('enabled', '1')
2021-08-19 14:38:29 +08:00
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
2023-04-06 10:47:26 +08:00
->where_like('tbl_voucher.code', '%' . $code . '%')
2021-08-19 14:38:29 +08:00
->offset($paginator['startpoint'])
->limit($paginator['limit'])
->find_many();
} else {
2023-10-24 13:27:30 +08:00
$paginator = Paginator::build(ORM::for_table('tbl_voucher'));
2022-09-08 15:00:46 +08:00
$d = ORM::for_table('tbl_plans')->where('enabled', '1')
2021-08-19 14:38:29 +08:00
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->offset($paginator['startpoint'])
->limit($paginator['limit'])->find_many();
}
$ui->assign('d', $d);
2023-04-06 10:47:26 +08:00
$ui->assign('_code', $code);
2021-08-19 14:38:29 +08:00
$ui->assign('paginator', $paginator);
2022-09-18 01:00:40 +08:00
run_hook('view_list_voucher'); #HOOK
2021-08-19 14:38:29 +08:00
$ui->display('voucher.tpl');
2017-03-11 03:51:06 +08:00
break;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
case 'add-voucher':
2021-08-19 14:38:29 +08:00
$c = ORM::for_table('tbl_customers')->find_many();
$ui->assign('c', $c);
2022-09-08 15:00:46 +08:00
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('p', $p);
2022-09-08 15:00:46 +08:00
$r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
2021-08-19 14:38:29 +08:00
$ui->assign('r', $r);
2022-09-18 01:00:40 +08:00
run_hook('view_add_voucher'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('voucher-add.tpl');
break;
2021-08-19 14:38:29 +08:00
case 'print-voucher':
2023-09-26 14:50:02 +08:00
$from_id = _post('from_id');
$planid = _post('planid');
$pagebreak = _post('pagebreak');
$limit = _post('limit');
2023-10-18 18:24:00 +08:00
$vpl = _post('vpl');
2023-10-24 13:27:30 +08:00
if (empty($vpl)) {
2023-10-18 18:24:00 +08:00
$vpl = 3;
}
if ($pagebreak < 1) $pagebreak = 12;
2021-08-19 14:38:29 +08:00
if ($limit < 1) $limit = $pagebreak * 2;
2023-10-24 13:27:30 +08:00
if (empty($from_id)) {
2023-10-18 18:24:00 +08:00
$from_id = 0;
}
2021-08-19 14:38:29 +08:00
if ($from_id > 0 && $planid > 0) {
$v = ORM::for_table('tbl_plans')
->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)
->find_many();
$vc = ORM::for_table('tbl_plans')
->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)
->count();
} else if ($from_id == 0 && $planid > 0) {
$v = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_plans.id', $planid)
->limit($limit)
->find_many();
$vc = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where('tbl_plans.id', $planid)
->count();
} else if ($from_id > 0 && $planid == 0) {
$v = ORM::for_table('tbl_plans')
->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)
->find_many();
$vc = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->where_gt('tbl_voucher.id', $from_id)
->count();
} else {
$v = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->limit($limit)
->find_many();
$vc = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where('tbl_voucher.status', '0')
->count();
}
2023-10-18 18:24:00 +08:00
$template = file_get_contents("pages/Voucher.html");
$template = str_replace('[[company_name]]', $config['CompanyName'], $template);
2021-08-19 14:38:29 +08:00
2022-10-13 15:00:54 +08:00
$ui->assign('_title', $_L['Voucher_Hotspot']);
2021-08-19 14:38:29 +08:00
$ui->assign('from_id', $from_id);
2023-10-18 18:24:00 +08:00
$ui->assign('vpl', $vpl);
2021-08-19 14:38:29 +08:00
$ui->assign('pagebreak', $pagebreak);
$plans = ORM::for_table('tbl_plans')->find_many();
$ui->assign('plans', $plans);
$ui->assign('limit', $limit);
$ui->assign('planid', $planid);
2023-10-18 18:24:00 +08:00
$voucher = [];
2023-10-20 15:31:56 +08:00
$n = 1;
2023-10-18 18:24:00 +08:00
foreach ($v 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);
2023-10-20 15:31:56 +08:00
$temp = str_replace('[[counter]]', $n, $temp);
2023-10-18 18:24:00 +08:00
$voucher[] = $temp;
2023-10-20 15:31:56 +08:00
$n++;
2023-10-18 18:24:00 +08:00
}
2023-10-24 13:27:30 +08:00
$ui->assign('voucher', $voucher);
2021-08-19 14:38:29 +08:00
$ui->assign('vc', $vc);
//for counting pagebreak
$ui->assign('jml', 0);
2022-09-18 01:00:40 +08:00
run_hook('view_print_voucher'); #HOOK
2021-08-19 14:38:29 +08:00
$ui->display('print-voucher.tpl');
break;
2017-03-11 03:51:06 +08:00
case 'voucher-post':
$type = _post('type');
2021-08-19 14:38:29 +08:00
$plan = _post('plan');
$server = _post('server');
$numbervoucher = _post('numbervoucher');
$lengthcode = _post('lengthcode');
$msg = '';
if ($type == '' or $plan == '' or $server == '' or $numbervoucher == '' or $lengthcode == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
if (Validator::UnsignedNumber($numbervoucher) == false) {
$msg .= 'The Number of Vouchers must be a number' . '<br>';
2017-03-11 03:51:06 +08:00
}
2021-08-19 14:38:29 +08:00
if (Validator::UnsignedNumber($lengthcode) == false) {
$msg .= 'The Length Code must be a number' . '<br>';
2017-03-11 03:51:06 +08:00
}
2021-08-19 14:38:29 +08:00
if ($msg == '') {
2022-09-18 01:00:40 +08:00
run_hook('create_voucher'); #HOOK
2021-08-19 14:38:29 +08:00
for ($i = 0; $i < $numbervoucher; $i++) {
$code = strtoupper(substr(md5(time() . rand(10000, 99999)), 0, $lengthcode));
2023-10-18 18:24:00 +08:00
if ($config['voucher_format'] == 'low') {
$code = strtolower($code);
} else if ($config['voucher_format'] == 'rand') {
$code = Lang::randomUpLowCase($code);
}
2021-08-19 14:38:29 +08:00
$d = ORM::for_table('tbl_voucher')->create();
$d->type = $type;
$d->routers = $server;
$d->id_plan = $plan;
$d->code = $code;
$d->user = '0';
$d->status = '0';
$d->save();
}
2017-03-11 03:51:06 +08:00
r2(U . 'prepaid/voucher', 's', $_L['Voucher_Successfully']);
2021-08-19 14:38:29 +08:00
} else {
r2(U . 'prepaid/add-voucher/' . $id, 'e', $msg);
2017-03-11 03:51:06 +08:00
}
break;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
case 'voucher-delete':
$id = $routes['2'];
2022-09-18 01:00:40 +08:00
run_hook('delete_voucher'); #HOOK
2017-03-11 03:51:06 +08:00
$d = ORM::for_table('tbl_voucher')->find_one($id);
2021-08-19 14:38:29 +08:00
if ($d) {
2017-03-11 03:51:06 +08:00
$d->delete();
r2(U . 'prepaid/voucher', 's', $_L['Delete_Successfully']);
}
break;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
case 'refill':
2023-08-23 13:11:07 +08:00
$ui->assign('xfooter', $select2_customer);
2023-08-15 18:01:48 +08:00
$ui->assign('_title', $_L['Refill_Account']);
2022-09-18 01:00:40 +08:00
run_hook('view_refill'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('refill.tpl');
break;
2021-08-19 14:38:29 +08:00
2017-03-11 03:51:06 +08:00
case 'refill-post':
2021-08-19 14:38:29 +08:00
$code = _post('code');
2023-08-30 10:01:37 +08:00
$user = ORM::for_table('tbl_customers')->where('id', _post('id_customer'))->find_one();
2021-08-19 14:38:29 +08:00
$v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one();
2022-09-18 01:00:40 +08:00
run_hook('refill_customer'); #HOOK
2021-08-19 14:38:29 +08:00
if ($v1) {
2023-08-30 10:01:37 +08:00
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Refill", "Voucher")) {
2021-08-19 14:38:29 +08:00
$v1->status = "1";
2023-08-30 10:01:37 +08:00
$v1->user = $user['username'];
2021-08-19 14:38:29 +08:00
$v1->save();
2023-08-30 10:01:37 +08:00
$in = ORM::for_table('tbl_transactions')->where('username', $user['username'])->order_by_desc('id')->find_one();
2023-08-15 18:01:48 +08:00
$ui->assign('in', $in);
$ui->assign('date', date("Y-m-d H:i:s"));
$ui->display('invoice.tpl');
2023-08-23 13:11:07 +08:00
} else {
2023-08-15 18:01:48 +08:00
r2(U . 'prepaid/refill', 'e', "Failed to refill account");
2021-08-19 14:38:29 +08:00
}
} else {
r2(U . 'prepaid/refill', 'e', $_L['Voucher_Not_Valid']);
}
2017-03-11 03:51:06 +08:00
break;
2023-08-15 18:01:48 +08:00
case 'deposit':
$ui->assign('_title', Lang::T('Refill Balance'));
2023-08-23 13:11:07 +08:00
$ui->assign('xfooter', $select2_customer);
2023-08-15 18:01:48 +08:00
$ui->assign('p', ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many());
run_hook('view_deposit'); #HOOK
$ui->display('deposit.tpl');
break;
case 'deposit-post':
$user = _post('id_customer');
$plan = _post('id_plan');
run_hook('deposit_customer'); #HOOK
if (!empty($user) && !empty($plan)) {
2023-08-23 13:11:07 +08:00
if (Package::rechargeUser($user, 'balance', $plan, "Deposit", $admin['fullname'])) {
2023-08-15 18:01:48 +08:00
$c = ORM::for_table('tbl_customers')->where('id', $user)->find_one();
$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();
$ui->assign('in', $in);
$ui->assign('date', date("Y-m-d H:i:s"));
$ui->display('invoice.tpl');
2023-08-23 13:11:07 +08:00
} else {
2023-08-15 18:01:48 +08:00
r2(U . 'prepaid/refill', 'e', "Failed to refill account");
}
} else {
r2(U . 'prepaid/refill', 'e', "All field is required");
}
break;
2017-03-11 03:51:06 +08:00
default:
2023-09-27 16:01:48 +08:00
$ui->display('a404.tpl');
2021-08-19 14:38:29 +08:00
}