ok
Direktori : /home2/selectio/www/obnovit-tracking/data-tables/ |
Current File : /home2/selectio/www/obnovit-tracking/data-tables/reports-data-table.php |
<?php ob_start(); session_start(); include"../config/config.php"; // $allPermissions=$_SESSION['permission']; $requestData= $_REQUEST; /*Fetch Database column Details*/ $columns = array( 0 =>'id', 1 =>'name', 2 =>'sku_no', 3 =>'user_id', 4 =>'site_id', 5 =>'created_at' ); // $conditions=""; $conditions=""; if($_POST['filter_sites']){ $conditions.=" and h.project_name=".$_POST['filter_sites']; } if($_POST['filter_products']){ $conditions.=" and h.resource_name=".$_POST['filter_products']; } if($_POST['filter_department']){ $conditions.=" and h.department=".$_POST['filter_department']; } if($_POST['filter_attendence_type']){ $conditions.=" and h.attendence_type=".$_POST['filter_attendence_type']; } if($_POST['start_date']!="" && $_POST['end_date']!=""){ $conditions.=" and (h.attendence_date BETWEEN '".$_POST['start_date']."' AND '".$_POST['end_date']."') "; } /*Fetch All Data Start*/ $statement = $pdo->prepare("SELECT h.* FROM tbl_attendence h ORDER BY h.id DESC"); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); $totalFiltered = $totalData; /*Fetch All Data End*/ /*Fetch Filter Data Start*/ $sql="SELECT *,(select uname from tbl_user where id=h.resource_name) as employee_name,(select site_name from tbl_site where id=h.project_name) as site_name ,(select name from tbl_department where id=h.department) as department FROM `tbl_attendence` h where 1=1 ".$conditions; if( !empty($_REQUEST['search']) ) { $sql.=" AND ( h.name LIKE '%".$_REQUEST['search']."%' "; $sql.=" OR h.site_name LIKE '%".$_REQUEST['search']."%' ) "; } $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=1; foreach( $query as $row ) { // preparing an array $nestedData=array(); $nestedData[] = "<div class='text-center'>".$i."</div>"; $nestedData[] = "<div class='text-center'>".date('d-m-Y', strtotime($row["attendence_date"]))."</div>"; $nestedData[] = "<div class='text-center'>".$row["employee_name"]."</div>"; $nestedData[] = "<div class='text-center'>".$row["site_name"]."</div>"; $nestedData[] = "<div class='text-center'>".$row["department"]."</div>"; $nestedData[] = "<div class='text-center'>".$row["salary_per_day"]."</div>"; if($row["attendence_type"]=="1"){ $nestedData[] = "<div class='text-center'><span class='label label-success'>Full Day</span></div>";}else{$nestedData[] ="<div class='text-center'><span class='label label-warning'>Half a Day</span></div>";} /*if($row["created_at"]!=""){ $nestedData[] =date('d-m-Y', strtotime($row["created_at"]));}else{$nestedData[] ="";}*/ $data[] = $nestedData; $i++; } $json_data = array( "draw" => intval( $requestData['draw'] ), "recordsTotal" => intval( $totalData ), "recordsFiltered" => intval( $totalFiltered ), "data" => $data ); echo json_encode($json_data); ?>