Export CSV by Filter data

This commit is contained in:
Ibnu Maksum 2024-05-20 09:33:37 +07:00
parent 1ab19bfe64
commit 12726bdaa0
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
3 changed files with 53 additions and 7 deletions

View File

@ -186,7 +186,7 @@ switch ($action) {
}
$usings = explode(',', $config['payment_usings']);
$usings = array_filter(array_unique($usings));
if(count($usings)==0){
if (count($usings) == 0) {
$usings[] = Lang::T('Cash');
}
$ui->assign('usings', $usings);
@ -621,18 +621,59 @@ switch ($action) {
if ($search != '') {
$query = ORM::for_table('tbl_customers')
->whereRaw("username LIKE '%$search%' OR fullname LIKE '%$search%' OR address LIKE '%$search%' ".
"OR phonenumber LIKE '%$search%' OR email LIKE '%$search%' AND status='$filter'");
->whereRaw("username LIKE '%$search%' OR fullname LIKE '%$search%' OR address LIKE '%$search%' " .
"OR phonenumber LIKE '%$search%' OR email LIKE '%$search%' AND status='$filter'");
} else {
$query = ORM::for_table('tbl_customers');
$query->where("status", $filter);
}
if($orderby=='asc'){
if ($orderby == 'asc') {
$query->order_by_asc($order);
}else{
} else {
$query->order_by_desc($order);
}
$d = $query->findMany();
if (_post('export', '') == 'csv') {
$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_' . $filter . '_' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');
$headers = [
'id',
'username',
'fullname',
'address',
'phonenumber',
'email',
'balance',
'service_type',
];
$fp = fopen('php://output', 'wb');
if (!$h) {
fputcsv($fp, $headers, ";");
$h = true;
}
foreach ($d as $c) {
$row = [
$c['id'],
$c['username'],
$c['fullname'],
str_replace("\n", " ", $c['address']),
$c['phonenumber'],
$c['email'],
$c['balance'],
$c['service_type'],
];
fputcsv($fp, $row, ";");
}
fclose($fp);
die();
}
$ui->assign('xheader', '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">');
$ui->assign('d', $d);
$ui->assign('statuses', ORM::for_table('tbl_customers')->getEnum("status"));

View File

@ -591,5 +591,6 @@
"Descending": "Descending",
"Created_Date": "Created Date",
"Inactive": "Inactive",
"Suspended": "Suspended"
"Suspended": "Suspended",
"Query": "Query"
}

View File

@ -66,7 +66,11 @@
<input type="text" name="search" class="form-control"
placeholder="{Lang::T('Search')}..." value="{$search}">
<div class="input-group-btn">
<button class="btn btn-primary" type="submit">{Lang::T('Search')}</button>
<button class="btn btn-primary" type="submit">{Lang::T('Query')}</button>
<button class="btn btn-primary" type="submit" name="export" value="csv">
<span class="glyphicon glyphicon-download"
aria-hidden="true"></span> CSV
</button>
</div>
</div>
</div>