<?php  include_once('../../config/db.php');  //include_once('../config/check.php'); 



$query = " SELECT a.*,b.name bname ,c.name cname,d.name dname   FROM savings_refunds a
LEFT JOIN clients b ON a.client_id = b.id
LEFT JOIN groups  c ON a.group_id = c.id
LEFT JOIN refundstatus d ON a.status=d.id
  ";




$statement = $conn->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
  
     $approve = ' <form method="post" action="apprefund" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="apprefund" value="' . $row["id"] . '"   "> <i class="fa fa-plus-circle fa-lg" style="color:green;" ></i>  </button></form> ' ; 

 //$actionButton = '<input type="radio" name="myradio" class="myradio" value="' . $row["id"] . '" /> </i></a>';
$edit = ' <form method="post" action="#" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="edit" value="' . $row["id"] . '"   "> <i class="fa fa-edit" style="color:green;" ></i>  </button></form> ' ; 
$delete = ' <form method="post" action="" >  <button type="submit" style="background:none;border:none;padding:0px; font-color:red; outline:none; " name="delete" value="' . $row["id"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i>  </button></form> ' ; 


 $sub_array = array();
 $sub_array[] =  $approve  ;
 
 $sub_array[] = $row['cname'];
 $sub_array[] = $row['bname'];
 $sub_array[] = $row['client_system_id'];
   $sub_array[] = $row['client_savings'];
  $sub_array[] = $row['exit_fee'];
 
 $sub_array[] = $row['final_amount'];
 $sub_array[] = $row['account_to_be_credited'];
 $sub_array[] = $row['application_date'];
 $sub_array[] = $row['maturity_date'];
  $sub_array[] = $row['dname'];
  $sub_array[] =  $delete ;
 $sub_array[] =  $edit  ;

 $data[] = $sub_array;

}

function count_all_data($conn,$query)
{
 $statement = $conn->prepare($query);
 $statement->execute();
 return $statement->rowCount();
}

$output = array(
                       "draw"       =>  $number_filter_row ,
                        "recordsTotal"   =>  count_all_data($conn,$query),
                        "recordsFiltered"  =>  $number_filter_row,
                        "data"       =>  $data
);

echo json_encode($output);

?>




