ok
Direktori : /home2/selectio/public_html/lilyexpresslive/expense-invoice/api/ |
Current File : /home2/selectio/public_html/lilyexpresslive/expense-invoice/api/invoice-data-table.php |
<?php ob_start(); session_start(); include"../config/config.php"; $allPermissions=$_SESSION['permission']; $requestData= $_REQUEST; if($requestData['length']==-1){ $requestData['length']=100000; } /*Fetch Database column Details*/ $columns = array( 0 =>'inv.id', 1 =>'inv_no', 2 =>'date', 3 =>'amount', 4 =>'final_amount', ); $conditions=""; $client=$_REQUEST['client']; $payment_status=$_REQUEST['payment_status']; $start_date=$_REQUEST['start_date']; $end_date=$_REQUEST['end_date']; $financial_year=$_REQUEST['financial_year']; $submitted_status=$_REQUEST['submitted_status']; $conditions=""; if($client!="0"){ $conditions.=" and inv.client_id=".$client; } if($payment_status!=0){ if($payment_status==3){ //unpiad $conditions.=" and (SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)+(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id)=0"; }else if($payment_status==1){//Fully Paid $conditions.="and ( ((SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)+(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id))>=inv.final_amount or (inv.final_amount-((SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)+(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id)))<1 )"; }else if($payment_status==2){//Partially Paid //$conditions.=" and ((SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)+(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id))<inv.final_amount and (SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)!=0"; $conditions.=" and ((SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)+(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id))<inv.final_amount and (SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)!=0 and (inv.final_amount-((SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id)+(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id)))>1"; } } if($financial_year!="0" ){ $conditions.=" and inv.year='$financial_year'"; } if($submitted_status!="0" ){ $conditions.=" and inv.submitted_status='$submitted_status'"; } if($start_date!="" && $end_date!=""){ $conditions.=" and (inv.date BETWEEN '$start_date' AND '$end_date') "; } /*Fetch All Data Start*/ $statement = $pdo->prepare("SELECT inv.*,c.name,c.gst,(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id) as paid,(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id) as reduction FROM `tbl_invoice` inv inner JOIN tbl_client c on inv.client_id=c.id where inv.type=1 ".$conditions); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); $totalFiltered = $totalData; /*Fetch All Data End*/ /*Fetch Filter Data Start*/ $sql="SELECT inv.*,c.name,c.gst,(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=1 and invoice_id=inv.id) as paid,(SELECT COALESCE(SUM(amount),0) FROM `tbl_invoice_payment` WHERE type=2 and invoice_id=inv.id) as reduction FROM `tbl_invoice` inv inner JOIN tbl_client c on inv.client_id=c.id where inv.type=1 ".$conditions; if( !empty($_REQUEST['search']) ) { $sql.=" AND ( c.name LIKE '%".$_REQUEST['search']."%' "; $sql.=" OR inv.inv_no LIKE '%".$_REQUEST['search']."%' ) "; } /*Fetch Filter Data End*/ $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // error_log('Sql :'.$sql); $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'>"; if($allPermissions['invoice']['read']=="1"){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='invoice-view.php?id=".$row["id"]."&inv_no=".$row["name"]."-".$row["inv_no"]."' title='View' class='tip btn btn-primary btn-xs' ><i class='fa fa-file-text-o'></i></a> "; } if($allPermissions['invoice']['update']=="1"){ $action.=" <a style='padding: 6px;margin-right: 3px;' href='invoice-edit.php?id=".$row["id"]."&inv_no=".$row["name"]."-".$row["inv_no"]."' title='Edit Invoice' class='tip btn btn-warning btn-xs'> <i class='fa fa-edit'></i> </a>"; } if($allPermissions['invoice']['delete']=="1"){ $action.=" <a style='padding: 6px;margin-right: 3px;' title='' onclick='delete_item(".$row['id'].")' class='btn btn-danger btn-sm' style='cursor: pointer;'><i class='fa fa-trash-o'> <b style='font-size:16px;'></b></i></a> "; } $action.="</div></div>"; $nestedData[] = $action; $nestedData[] = $i; $nestedData[] = $row["inv_no"]."/".$row["year"]; $nestedData[] = $row["period"]; $nestedData[] = $row["date"]; $nestedData[] = number_format((float)$row["invoice_amount"], 2, '.', ''); $nestedData[] = $row["gst_percentage"]; $nestedData[] = number_format((float)($row["invoice_amount"]*$row["gst_percentage"])/100, 2, '.', ''); $nestedData[] = number_format((float)$row["final_amount"], 2, '.', ''); $nestedData[] = $row["name"]; $nestedData[] = $row["gst"]; if(($row["paid"]+$row["reduction"])==0){ $nestedData[] = "<button class='tip btn btn-danger btn-xs'>Un-Paid</button>"; } else if(($row["paid"]+$row["reduction"])>=$row["final_amount"] || ($row["final_amount"]-($row["paid"]+$row["reduction"]))<1 ){ $nestedData[]="<button class='tip btn btn-success btn-xs'>Fully Paid</button>"; }else if(($row["paid"]+$row["reduction"])<$row["final_amount"]){ $nestedData[]="<button class='tip btn btn-warning btn-xs'>Partially Paid</button>"; } $nestedData[] = number_format((float)$row["final_amount"], 2, '.', ''); $nestedData[] = number_format((float)$row["paid"], 2, '.', ''); $nestedData[] = number_format((float)$row["reduction"], 2, '.', ''); // if(($row["paid"]+$row["reduction"])<$row["final_amount"]){ $nestedData[] =number_format((float)$row["final_amount"]-($row["paid"]+$row["reduction"]), 2, '.', ''); /* }else{ $nestedData[] ="0.00"; }*/ /*if($row["submitted_status"]==1){ $nestedData[]="<button class='tip btn btn-success btn-xs'>Submitted</button>"; }else { $nestedData[]="<button class='tip btn btn-danger btn-xs'>Not Submitted</button>"; }*/ $data[] = $nestedData; $i++; } $json_data = array( "draw" => intval( $requestData['draw'] ), "recordsTotal" => intval( $totalData ), "recordsFiltered" => intval( $totalFiltered ), "data" => $data ); echo json_encode($json_data); ?>