ok
Direktori : /home2/selectio/public_html/lilyexpresslive/expense-invoice/api/ |
Current File : //home2/selectio/public_html/lilyexpresslive/expense-invoice/api/expense-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 =>'amount', 2 =>'ref_no', 3 =>'category', 4 =>'employee_name', 5 =>'expense_for', 6 =>'expense_date', 7 =>'payment_method', 8 =>'office', 9 =>'note', 10 =>'name' ); $location_id=$_REQUEST['location']; $payment_method=$_REQUEST['payment_method']; $start_date=$_REQUEST['start_date']; $end_date=$_REQUEST['end_date']; $category=$_REQUEST['category']; $expense_proof=$_REQUEST['expense_proof']; $conditions=""; if($location_id!=0){ $conditions.=" and ex.location=".$location_id; } if($payment_method!="0" ){ $conditions.=" and ex.payment_method='$payment_method'"; } if($category!=0){ $conditions.=" and ex.category_id=".$category; } if($expense_proof!=0){ if($expense_proof==1){ $conditions.=" and ex.proof_image!='expense-proof/default-img.png'"; }else if($expense_proof==2){ $conditions.=" and ex.proof_image='expense-proof/default-img.png'"; } } if($start_date!="" && $end_date!=""){ $conditions.=" and (ex.expense_date BETWEEN '$start_date' AND '$end_date') "; } /*Fetch All Data Start*/ $statement = $pdo->prepare("SELECT ex.*,u.name,ec.category,e.employee_name,el.office FROM `tbl_expense` ex inner join users u on ex.user_id=u.id inner join tbl_exp_category ec on ex.category_id=ec.id inner join tbl_employee e on e.id=ex.employee_id inner join tbl_exp_location el on ex.location=el.id where ex.id!=0 ".$conditions); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); $totalFiltered = $totalData; /*Fetch All Data End*/ /*Fetch Filter Data Start*/ $sql="SELECT ex.*,u.name,ec.category,e.employee_name,el.office FROM `tbl_expense` ex inner join users u on ex.user_id=u.id inner join tbl_exp_category ec on ex.category_id=ec.id inner join tbl_employee e on e.id=ex.employee_id inner join tbl_exp_location el on ex.location=el.id where ex.id!=0".$conditions; if( !empty($_REQUEST['search']) ) { $sql.=" AND ( ex.ref_no LIKE '%".$_REQUEST['search']."%' "; $sql.=" OR ec.category LIKE '%".$_REQUEST['search']."%' "; $sql.=" OR e.employee_name LIKE '%".$_REQUEST['search']."%' "; $sql.=" OR ex.payment_method LIKE '%".$_REQUEST['search']."%' "; $sql.=" OR u.name LIKE '%".$_REQUEST['search']."%' ) "; } $statement = $pdo->prepare($sql); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalFiltered = $statement->rowCount(); /*Fetch Filter Data End*/ if($requestData['length']!=-1){ $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(); $action= "<div class='text-center'><div class='btn-group'>"; $action.=" <a style='padding: 6px;margin-right: 3px;' href='expense-view.php?id=".$row["id"]."' title='view Employee' class='tip btn btn-warning btn-xs'><i class='fa fa-eye'></i></a> "; if($allPermissions['expense']['update']=="1"){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='expense-edit.php?id=".$row["id"]."' title='Edit Employee' class='tip btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> "; } if($allPermissions['expense']['delete']=="1"){ $action.=" <button style='padding: 6px;margin-right: 3px;' value='11' title='Delete Employee' onClick='delete_expense(".$row["id"].")' class='tip btn btn-danger btn-xs'><i class='fa fa-trash-o'></i></button>"; } if($row["proof_image"]!='expense-proof/default-img.png'){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='".$row["proof_image"]."' target='_blank' title='view Proof' class='tip btn btn-success btn-xs'><i class='fa fa-eye'></i></a> "; } if($row["proof_image2"]!='expense-proof/default-img.png'){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='".$row["proof_image2"]."' target='_blank' title='view Proof2' class='tip btn btn-success btn-xs'><i class='fa fa-eye'></i></a> "; } if($row["proof_image3"]!='expense-proof/default-img.png'){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='".$row["proof_image3"]."' target='_blank' title='view Proof3' class='tip btn btn-success btn-xs'><i class='fa fa-eye'></i></a> "; } if($row["proof_image4"]!='expense-proof/default-img.png'){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='".$row["proof_image4"]."' target='_blank' title='view Proof4' class='tip btn btn-success btn-xs'><i class='fa fa-eye'></i></a> "; } if($row["proof_image5"]!='expense-proof/default-img.png'){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='".$row["proof_image5"]."' target='_blank' title='view Proof5' class='tip btn btn-success btn-xs'><i class='fa fa-eye'></i></a> "; } $action.="</div></div>"; $nestedData[] = $action; $nestedData[] = $i; $nestedData[] = $row["amount"]; $nestedData[] = $row["ref_no"]; $nestedData[] = $row["category"]; $nestedData[] = $row["employee_name"]; $nestedData[] = $row["expense_for"]; $nestedData[] = $row["expense_date"]; $nestedData[] = $row["payment_method"]; $nestedData[] = $row["office"]; $nestedData[] = $row["note"]; $nestedData[] = $row["name"]; $nestedData[] = $row["created_at"]; $nestedData[] = $row["updated_at"]; $data[] = $nestedData; $i++; } $json_data = array( "draw" => intval( $requestData['draw'] ), "recordsTotal" => intval( $totalData ), "recordsFiltered" => intval( $totalFiltered ), "data" => $data ); echo json_encode($json_data); ?>