ok
Direktori : /home2/selectio/www/lilyexpresslive/software/admin/data-tables/ |
Current File : /home2/selectio/www/lilyexpresslive/software/admin/data-tables/customer_dt.php |
<?php session_start(); include("../inc/config.php"); $condition=''; $branch_id=$_POST['branch_id']; if($branch_id==0){ $condition="";}else{$condition.=" and tb.id=".$branch_id;} $tbl_branch=""; if($_SESSION['lily_express_software_live']['id']!=1 && $_SESSION['lily_express_software_live']['role_branches']!='0'){ $condition.=" and tb.id in (".$_SESSION['lily_express_software_live']['role_branches'].")"; } $client_id=$_POST['client_id']; if($client_id==0){ $condition.="";}else{$condition.=" and tc.client_id=".$client_id;} $customer_type=$_POST['customer_type']; if($customer_type!='all'){$condition.=" and tc.cust_type='".$customer_type."'";} $requestData= $_REQUEST; /*Fetch Database column Details*/ $columns = array( 0 =>'cust_id', 1 =>'cust_name', 2 =>'cust_code', 3 =>'cust_city', 4 =>'cust_zip', 5 =>'cust_address', 6 =>'client_name', 7 =>'destination_city' ); /*Fetch All Data Start*/ $statement = $pdo->prepare("SELECT tc.*,tu.full_name,tb.branch_name FROM `tbl_customer` tc INNER JOIN tbl_user tu on tc.client_id=tu.id INNER JOIN tbl_branch tb on tu.branch_id=tb.id where 1=1 $condition "); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); $totalFiltered = $totalData; /*Fetch All Data End*/ /*Fetch Filter Data Start*/ $sql ="SELECT tc.*,tu.full_name as client_name,tb.branch_name FROM `tbl_customer` tc INNER JOIN tbl_user tu on tc.client_id=tu.id INNER JOIN tbl_branch tb on tu.branch_id=tb.id where 1=1 $condition"; if( !empty($requestData['search']['value']) ) { $sql.=" AND ( tbc.cust_name LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR tbc.cust_code LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR tbc.cust_city LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR tbc.cust_zip LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR tbu.full_name LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR tbc.destination_city LIKE '%".$requestData['search']['value']."%' ) "; } $statement = $pdo->prepare($sql); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalFiltered = $statement->rowCount(); /*Fetch Filter Data End*/ $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; $statement = $pdo->prepare($sql); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $data = array(); $i=$requestData['start']+1; foreach( $query as $row ) { // preparing an array $nestedData=array(); $action= "<div class='text-center'><div class='btn-group'>"; if($_SESSION['lily_express_software_live']['id']==1 || $allPermissions['customer']['update']=='1'){ $action.="<a style='margin-right: 3px;' href='customer-edit.php?id=".$row["cust_id"]."' title='Edit Users' class='tip btn btn-warning btn-xs'> <i class='fa fa-edit'></i> Edit </a> "; } $action.="</div></div>"; $nestedData[] = $i; $nestedData[] = $action; $nestedData[] = $row["branch_name"]; $nestedData[] = $row["client_name"]; $nestedData[] = $row["cust_name"]; $nestedData[] = $row["cust_code"]; $nestedData[] = $row["cust_address"]; $nestedData[] = $row["cust_city"]; $nestedData[] = $row["cust_zip"]; $nestedData[] = $row["destination_city"]; $data[] = $nestedData; $i++; } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); echo json_encode($json_data); // send data as json format //************************************************************************************