Merge pull request #180 from freeispradius/master

Update to case csv. added columns
This commit is contained in:
iBNu Maksum 2024-04-23 11:31:18 +07:00 committed by GitHub
commit 7b40fc850e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 106 additions and 19 deletions

View File

@ -25,19 +25,19 @@ switch ($action) {
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_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");
} }
$cs = ORM::for_table('tbl_customers') $cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id', 'id') ->select('tbl_customers.id', 'id')
->select('tbl_customers.username', 'username') ->select('tbl_customers.username', 'username')
->select('fullname') ->select('fullname')
->select('address')
->select('phonenumber') ->select('phonenumber')
->select('email') ->select('email')
->select('balance') ->select('balance')
->select('namebp') ->select('service_type')
->select('routers') ->order_by_asc('tbl_customers.id')
->select('status') ->find_array();
->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; $h = false;
set_time_limit(-1); set_time_limit(-1);
header('Pragma: public'); header('Pragma: public');
@ -46,20 +46,107 @@ switch ($action) {
header("Content-type: text/csv"); header("Content-type: text/csv");
header('Content-Disposition: attachment;filename="phpnuxbill_customers_' . date('Y-m-d_H_i') . '.csv"'); header('Content-Disposition: attachment;filename="phpnuxbill_customers_' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
$headers = [
'id',
'username',
'fullname',
'address',
'phonenumber',
'email',
'balance',
'service_type',
];
if (!$h) {
echo '"' . implode('","', $headers) . "\"\n";
$h = true;
}
foreach ($cs as $c) { foreach ($cs as $c) {
$ks = []; $row = [
$vs = []; $c['id'],
foreach ($c as $k => $v) { $c['username'],
$ks[] = $k; $c['fullname'],
$vs[] = $v; $c['address'],
} $c['phonenumber'],
if (!$h) { $c['email'],
echo '"' . implode('";"', $ks) . "\"\n"; $c['balance'],
$h = true; $c['service_type'],
} ];
echo '"' . implode('";"', $vs) . "\"\n"; echo '"' . implode('","', $row) . "\"\n";
} }
break; 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'
];
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;
case 'add': case 'add':
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");

View File

@ -11,7 +11,7 @@
class="glyphicon glyphicon-refresh" aria-hidden="true"></span> sync</a> class="glyphicon glyphicon-refresh" aria-hidden="true"></span> sync</a>
</div> </div>
<div class="btn-group pull-right"> <div class="btn-group pull-right">
<a class="btn btn-info btn-xs" title="save" href="{$_url}customers/csv" <a class="btn btn-info btn-xs" title="save" href="{$_url}customers/csv-prepaid"
onclick="return confirm('This will export to CSV?')"><span class="glyphicon glyphicon-download" onclick="return confirm('This will export to CSV?')"><span class="glyphicon glyphicon-download"
aria-hidden="true"></span> CSV</a> aria-hidden="true"></span> CSV</a>
</div> </div>
@ -100,4 +100,4 @@ function extend(idP){
} }
</script> </script>
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}