export csv

This commit is contained in:
Ibnu Maksum 2024-02-12 11:35:59 +07:00
parent 9543ee6e34
commit bf6ec9d4cd
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
4 changed files with 59 additions and 10 deletions

View File

@ -372,7 +372,7 @@ try {
r2(U . 'dashboard', 'e', 'not found'); r2(U . 'dashboard', 'e', 'not found');
} }
} catch (Throwable $e) { } catch (Throwable $e) {
if (Admin::getID()) { if (!Admin::getID()) {
r2(U . 'home', 'e', $e->getMessage()); r2(U . 'home', 'e', $e->getMessage());
} }
$ui->assign("error_message", $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>'); $ui->assign("error_message", $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>');
@ -380,7 +380,7 @@ try {
$ui->display('router-error.tpl'); $ui->display('router-error.tpl');
die(); die();
} catch (Exception $e) { } catch (Exception $e) {
if (Admin::getID()) { if (!Admin::getID()) {
r2(U . 'home', 'e', $e->getMessage()); r2(U . 'home', 'e', $e->getMessage());
} }
$ui->assign("error_message", $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>'); $ui->assign("error_message", $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>');

View File

@ -20,7 +20,6 @@ if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') {
switch ($action) { switch ($action) {
case 'list': case 'list':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/customers.js"></script>');
$search = _post('search'); $search = _post('search');
run_hook('list_customers'); #HOOK run_hook('list_customers'); #HOOK
if ($search != '') { if ($search != '') {
@ -49,6 +48,42 @@ switch ($action) {
$ui->display('customers.tpl'); $ui->display('customers.tpl');
break; break;
case 'csv':
$cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id','id')
->select('tbl_customers.username','username')
->select('fullname')
->select('phonenumber')
->select('email')
->select('balance')
->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_customers_' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');
foreach ($cs as $c) {
$ks = [];
$vs = [];
foreach ($c as $k => $v) {
$ks[] = $k;
$vs[] = $v;
}
if(!$h){
echo '"'.implode('";"', $ks)."\"\n";
$h = true;
}
echo '"'.implode('";"', $vs)."\"\n";
}
break;
case 'add': case 'add':
run_hook('view_add_customer'); #HOOK run_hook('view_add_customer'); #HOOK
$ui->display('customers-add.tpl'); $ui->display('customers-add.tpl');

View File

@ -3,7 +3,14 @@
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<div class="panel panel-hovered mb20 panel-primary"> <div class="panel panel-hovered mb20 panel-primary">
<div class="panel-heading">{$_L['Manage_Accounts']}</div> <div class="panel-heading">
<div class="btn-group pull-right">
<a class="btn btn-primary btn-xs" title="save" href="{$_url}customers/csv"
onclick="return confirm('This will export to CSV?')"><span
class="glyphicon glyphicon-download" aria-hidden="true"></span> CSV</a>
</div>
{$_L['Manage_Accounts']}
</div>
<div class="panel-body"> <div class="panel-body">
<div class="md-whiteframe-z1 mb20 text-center" style="padding: 15px"> <div class="md-whiteframe-z1 mb20 text-center" style="padding: 15px">
<div class="col-md-8"> <div class="col-md-8">
@ -41,8 +48,10 @@
<tbody> <tbody>
{foreach $d as $ds} {foreach $d as $ds}
<tr> <tr>
<td onclick="window.location.href = '{$_url}customers/view/{$ds['id']}'" style="cursor:pointer;">{$ds['username']}</td> <td onclick="window.location.href = '{$_url}customers/view/{$ds['id']}'"
<td onclick="window.location.href = '{$_url}customers/view/{$ds['id']}'" style="cursor: pointer;">{$ds['fullname']}</td> style="cursor:pointer;">{$ds['username']}</td>
<td onclick="window.location.href = '{$_url}customers/view/{$ds['id']}'"
style="cursor: pointer;">{$ds['fullname']}</td>
<td>{Lang::moneyFormat($ds['balance'])}</td> <td>{Lang::moneyFormat($ds['balance'])}</td>
<td>{$ds['phonenumber']}</td> <td>{$ds['phonenumber']}</td>
<td>{$ds['email']}</td> <td>{$ds['email']}</td>

View File

@ -8,6 +8,11 @@
<a class="btn btn-primary btn-xs" title="save" href="{$_url}prepaid/sync" <a class="btn btn-primary btn-xs" title="save" href="{$_url}prepaid/sync"
onclick="return confirm('This will sync/send Caustomer active plan to Mikrotik?')"><span onclick="return confirm('This will sync/send Caustomer active plan to Mikrotik?')"><span
class="glyphicon glyphicon-refresh" aria-hidden="true"></span> sync</a> class="glyphicon glyphicon-refresh" aria-hidden="true"></span> sync</a>
</div>
<div class="btn-group pull-right">
<a class="btn btn-info btn-xs" title="save" href="{$_url}customers/csv"
onclick="return confirm('This will export to CSV?')"><span
class="glyphicon glyphicon-download" aria-hidden="true"></span> CSV</a>
</div>{$_L['Prepaid_User']} </div>{$_L['Prepaid_User']}
</div> </div>
<div class="panel-body"> <div class="panel-body">