ok
Direktori : /proc/thread-self/root/home2/selectio/www/lilyexpresslive/software/admin/excel/ |
Current File : //proc/thread-self/root/home2/selectio/www/lilyexpresslive/software/admin/excel/monthly-report.php |
<?php ini_set('memory_limit', '-1'); include("../inc/config.php"); include("../db.php"); $status='';$client_id=''; $from = $_POST['from']; $to = $_POST['to']; if(isset($_POST['set_status'])){ $status = $_POST['set_status']; } $client_id = $_POST['client_id']; $report_name="Monthly-Report"; $client_type=""; $client_idss="0"; if(isset($client_id) && is_array($client_id)){ foreach($client_id as $ids){ $client_idss.=","; $client_idss.=$ids; } } $client_id=$client_idss; if($client_id=='0'){ $client_id="all"; } $status_idss=""; if(isset($status) && is_array($status)){ foreach($status as $ids){ if($status_idss!=""){ $status_idss.=","; } $status_idss.="'".$ids."'"; } } $status=$status_idss; if($status==''){ $status="all"; } $where=""; if($status!="all"){ $where.=" and pickup_entry.status in (".$status.")"; } if(isset($_POST['entry_type']) && $_POST['entry_type']!=""){ $where.=" and pickup_entry.entry_type=".$_POST['entry_type']; } if($client_id!="all"){ $where.="and pickup_entry.client_id in (".$client_id.")"; $report_name=""; $statements = "SELECT role,full_name FROM `tbl_user` WHERE id in (".$client_id.")"; $client_result=mysqli_query($conn,$statements); foreach ($client_result as $row) { $report_name.=$row['full_name']."-"; $client_type=$row['role']; } } if($from!='' && $to!=''){ $where.=' and pickup_entry.created_at BETWEEN "'.$from.'" and "'.$to.'"'; } $statement = "SELECT pickup_entry.*,(select created_at from tbl_tracking where pickup_entry_id=pickup_entry.id order BY t_id DESC LIMIT 1) as current_status_date,(SELECT COUNT(id) from tbl_pod WHERE awb_id=pickup_entry.id) as pod_status,tbl_user.full_name as client_name,pickup_entry.created_at as added,tbl_customer.cust_code as cust_code, material_desc.full_desc as content,tbl_customer.cust_name as cust_name FROM pickup_entry INNER JOIN tbl_user INNER JOIN tbl_customer INNER JOIN material_desc on pickup_entry.client_id=tbl_user.id AND pickup_entry.content_desc=material_desc.id AND pickup_entry.customer_id=tbl_customer.cust_id where pickup_entry.id!=0 $where order by pickup_entry.id ASC"; $result=mysqli_query($conn,$statement); /* header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename='.$report_name.'-'.date("Y-m-d").'.csv'); $output = fopen("php://output", "w"); */ // Headers for download $fileName = $report_name."-". date('Y-m-d') . ".xls"; header("Content-Disposition: attachment; filename=".$fileName); header("Content-Type: application/vnd.ms-excel"); $flag = false; foreach($result as $row) { if(!$flag) { // display column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } // filter data array_walk($row, 'filterData'); echo implode("\t", array_values($row)) . "\n"; } function filterData(&$str){ $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } exit; /* fputcsv($output, array('SL', 'Booking Date','Sender Name','Ref Number','Packing List No','Customer Name','Address','Mobile','Pincode','Destination','No.Of.Pics','Actual Weight','Charged Weight','AWB Number','Status','Status Updated Date','POD Status','Description','Remark','Receiver_Name','Receiver_Mobile','Relation','Reason','Delivery Date')); $i=1; foreach ($result as $row) { $date=date_create($row['created_at']); $day=date_format($date,'d-m-Y'); $current_status_date=date_create($row['current_status_date']); $current_status_date=date_format($current_status_date,'d-m-Y'); $statements ='SELECT * FROM `tbl_tracking` WHERE pickup_entry_id='.$row['id'].' ORDER by t_id DESC LIMIT 1'; $tracking_result=mysqli_query($conn,$statements); foreach ($tracking_result as $rows) { $description=$rows['description']; $remark=$rows['remark'];$receiver_name=$rows['receiver_name'];$receiver_mobile=$rows['receiver_mobile'];$relation=$rows['relation'];$reason=$rows['reason'];$delivery_date=$rows['delivery_date']; if($delivery_date=='0000-00-00' || $rows['status']!='Delivered'){ $delivery_date=''; }else{ $delivery_date=date_create($delivery_date); $delivery_date=date_format($delivery_date,'d-m-Y'); } } $time= date('h:i:s A', strtotime($row['updated_at'])); $pod_status="POD Not Updated"; fputcsv($output, array($i,$day,$row['client_name'],$row['cust_code'],$row['picklist_no'],$row['cust_name'],$row['address'],str_replace("$","",$row["phone"]),$row['pincode'],$row['destination'],$row['pics'],$row['a_weight'],$row['c_weight'],$row['ref_no'],$row['status'],$current_status_date,$pod_status,$description,$remark,$receiver_name,$receiver_mobile,$relation,$reason,$delivery_date)); //fputcsv($output, array($i,$row['ref_no'],$row['cust_code'],$row['picklist_no'],$row['destination'],$row['client_name'],$row['cust_name'],$row['address'],$row['pincode'],str_replace("$","",$row["phone"]),$row['a_weight'],$row['c_weight'],$row['pics'],$row['status'],$current_status_date,$day,$pod_status)); //fputcsv($output, array($i,$row['ref_no'],$row['cust_code'],$row['status'],$row['client_name'],$row['address'],$row['pincode'],$row['phone'],$row['a_weight'],$row['c_weight'],$row['pics'],$day,$row['cust_name'])); $i++; } fclose($output);*/ ?>