ok
Direktori : /home2/selectio/public_html/lilyexpresslive/expense-invoice/api/ |
Current File : /home2/selectio/public_html/lilyexpresslive/expense-invoice/api/invoice-count-api.php |
<?php ob_start(); session_start(); include"../config/config.php"; $allPermissions=$_SESSION['permission']; $requestData= $_REQUEST; $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; /*Fetch Filter Data End*/ $statement = $pdo->prepare($sql); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $twta=0;$tta=0;$ta=0;$t_received=0;$t_reduction=0;$t_pending=0; foreach( $query as $row ){ $twta=$twta+$row["invoice_amount"]; $tta=$tta+(($row["invoice_amount"]*$row["gst_percentage"])/100); $ta=$ta+$row["final_amount"]; $t_received=$t_received+$row["paid"]; $t_reduction=$t_reduction+$row["reduction"]; if(($row["paid"]+$row["reduction"])<$row["final_amount"]){ //$nestedData[] =number_format((float)$row["final_amount"]-($row["paid"]+$row["reduction"]), 2, '.', ''); $t_pending=$t_pending+($row["final_amount"]-($row["paid"]+$row["reduction"])); } } ?> <div class="row"> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-info btn-sm" style="width: 100%;"><span><b><?php echo "Total Invoice : ".$totalData ;?></b></span></button> </div> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-success btn-sm" style="width: 100%;"><span><b><?php echo "Total Without Tax Amount : ₹".number_format((float)$twta, 2, '.', '');?></b></span></button> </div> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-warning btn-sm" style="width: 100%;"><span><b><?php echo "Total Tax Amount : ₹".number_format((float)$tta, 2, '.', '') ;?></b></span></button> </div> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-info btn-sm" style="width: 100%;"><span><b><?php echo "Total Amount : ₹".number_format((float)$ta, 2, '.', '') ;?></b></span></button> </div> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-warning btn-sm" style="width: 100%;"><span><b><?php echo "Total Received : ₹".number_format((float)$t_received, 2, '.', '') ;?></b></span></button> </div> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-primary btn-sm" style="width: 100%;"><span><b><?php echo "Total Reduction : ₹".number_format((float)$t_reduction, 2, '.', '') ;?></b></span></button> </div> <div class="col-md-3" style="padding:2px;"> <button class="btn btn-danger btn-sm" style="width: 100%;"><span><b><?php echo "Total Pending : ₹".number_format((float)$t_pending, 2, '.', '') ;?></b></span></button> </div> </div>