fix pagination Voucher

This commit is contained in:
Ibnu Maksum
2024-04-23 11:51:34 +07:00
parent 18bdf185d6
commit 8dc7707b3a
6 changed files with 132 additions and 131 deletions

View File

@ -25,7 +25,7 @@ switch ($action) {
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
$cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id', 'id')
->select('tbl_customers.username', 'username')
@ -37,7 +37,7 @@ switch ($action) {
->select('service_type')
->order_by_asc('tbl_customers.id')
->find_array();
$h = false;
set_time_limit(-1);
header('Pragma: public');
@ -46,7 +46,7 @@ switch ($action) {
header("Content-type: text/csv");
header('Content-Disposition: attachment;filename="phpnuxbill_customers_' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');
$headers = [
'id',
'username',
@ -57,12 +57,12 @@ switch ($action) {
'balance',
'service_type',
];
if (!$h) {
echo '"' . implode('","', $headers) . "\"\n";
$h = true;
}
foreach ($cs as $c) {
$row = [
$c['id'],
@ -78,75 +78,75 @@ switch ($action) {
}
break;
//case csv-prepaid can be moved later to (plan.php) php file dealing with prepaid users
case 'csv-prepaid':
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
$cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id', 'id')
->select('tbl_customers.username', 'username')
->select('fullname')
->select('address')
->select('phonenumber')
->select('email')
->select('balance')
->select('service_type')
->select('namebp')
->select('routers')
->select('status')
->select('method', 'Payment')
->join('tbl_user_recharges', array('tbl_customers.id', '=', 'tbl_user_recharges.customer_id'))
->order_by_asc('tbl_customers.id')
->find_array();
$h = false;
set_time_limit(-1);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-type: text/csv");
header('Content-Disposition: attachment;filename="phpnuxbill_prepaid_users' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');
$headers = [
'id',
'username',
'fullname',
'address',
'phonenumber',
'email',
'balance',
'service_type',
'namebp',
'routers',
'status',
'Payment'
case 'csv-prepaid':
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
$cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id', 'id')
->select('tbl_customers.username', 'username')
->select('fullname')
->select('address')
->select('phonenumber')
->select('email')
->select('balance')
->select('service_type')
->select('namebp')
->select('routers')
->select('status')
->select('method', 'Payment')
->join('tbl_user_recharges', array('tbl_customers.id', '=', 'tbl_user_recharges.customer_id'))
->order_by_asc('tbl_customers.id')
->find_array();
$h = false;
set_time_limit(-1);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-type: text/csv");
header('Content-Disposition: attachment;filename="phpnuxbill_prepaid_users' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');
$headers = [
'id',
'username',
'fullname',
'address',
'phonenumber',
'email',
'balance',
'service_type',
'namebp',
'routers',
'status',
'Payment'
];
if (!$h) {
echo '"' . implode('","', $headers) . "\"\n";
$h = true;
}
foreach ($cs as $c) {
$row = [
$c['id'],
$c['username'],
$c['fullname'],
$c['address'],
$c['phonenumber'],
$c['email'],
$c['balance'],
$c['service_type'],
$c['namebp'],
$c['routers'],
$c['status'],
$c['Payment']
];
if (!$h) {
echo '"' . implode('","', $headers) . "\"\n";
$h = true;
}
foreach ($cs as $c) {
$row = [
$c['id'],
$c['username'],
$c['fullname'],
$c['address'],
$c['phonenumber'],
$c['email'],
$c['balance'],
$c['service_type'],
$c['namebp'],
$c['routers'],
$c['status'],
$c['Payment']
];
echo '"' . implode('","', $row) . "\"\n";
}
break;
echo '"' . implode('","', $row) . "\"\n";
}
break;
case 'add':
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");

View File

@ -132,7 +132,7 @@ switch ($action) {
$using = _post('using');
$stoken = _post('stoken');
if(!empty(App::getTokenValue($stoken))){
if (!empty(App::getTokenValue($stoken))) {
$username = App::getTokenValue($stoken);
$in = ORM::for_table('tbl_transactions')->where('username', $username)->order_by_desc('id')->find_one();
Package::createInvoice($in);
@ -325,18 +325,13 @@ switch ($action) {
case 'voucher':
$ui->assign('_title', Lang::T('Vouchers'));
$limit = 10;
$page = _get('p', 0);
$pageNow = $page * $limit;
$search = _req('search');
if ($search != '') {
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
$d = ORM::for_table('tbl_plans')->where('enabled', '1')
$query = ORM::for_table('tbl_plans')->where('enabled', '1')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where_like('tbl_voucher.code', '%' . $search . '%')
->offset($pageNow)
->limit($limit)
->findArray();
->where_like('tbl_voucher.code', '%' . $search . '%');
$d = Paginator::findMany($query, ["search" => $search]);
} else if ($admin['user_type'] == 'Agent') {
$sales = [];
$sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray();
@ -344,21 +339,17 @@ switch ($action) {
$sales[] = $s['id'];
}
$sales[] = $admin['id'];
$d = ORM::for_table('tbl_plans')
$query = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where_in('generated_by', $sales)
->where_like('tbl_voucher.code', '%' . $search . '%')
->offset($pageNow)
->limit($limit)
->findArray();
->where_like('tbl_voucher.code', '%' . $search . '%');
$d = Paginator::findMany($query, ["search" => $search]);
}
} else {
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
$d = ORM::for_table('tbl_plans')->where('enabled', '1')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->offset($pageNow)
->limit($limit)
->findArray();
$query = ORM::for_table('tbl_plans')->where('enabled', '1')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'));
$d = Paginator::findMany($query);
} else if ($admin['user_type'] == 'Agent') {
$sales = [];
$sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray();
@ -366,12 +357,10 @@ switch ($action) {
$sales[] = $s['id'];
}
$sales[] = $admin['id'];
$d = ORM::for_table('tbl_plans')
$query = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where_in('generated_by', $sales)
->offset($pageNow)
->limit($limit)
->findArray();
->where_in('generated_by', $sales);
$d = Paginator::findMany($query);
}
}
// extract admin
@ -581,6 +570,7 @@ switch ($action) {
} else if ($voucher_format == 'rand') {
$code = Lang::randomUpLowCase($code);
}
die($code);
$d = ORM::for_table('tbl_voucher')->create();
$d->type = $type;
$d->routers = $server;
@ -743,15 +733,15 @@ switch ($action) {
$id = $routes[2];
$days = $routes[3];
$stoken = $_GET['stoken'];
if(App::getTokenValue($stoken)){
if (App::getTokenValue($stoken)) {
r2(U . 'plan', 's', "Extend already done");
}
$tur = ORM::for_table('tbl_user_recharges')->find_one($id);
$status = $tur['status'];
if(strtotime($tur['expiration'].' '.$tur['time']) > time()){
if (strtotime($tur['expiration'] . ' ' . $tur['time']) > time()) {
// not expired
$expiration = date('Y-m-d', strtotime($tur['expiration']." +$days day"));
}else{
$expiration = date('Y-m-d', strtotime($tur['expiration'] . " +$days day"));
} else {
//expired
$expiration = date('Y-m-d', strtotime(" +$days day"));
}
@ -759,7 +749,7 @@ switch ($action) {
$tur->status = "on";
$tur->save();
App::setToken($stoken, $id);
if($status=='off'){
if ($status == 'off') {
if ($tur['routers'] != 'radius') {
$mikrotik = Mikrotik::info($tur['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);