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








  
    $query = "   SELECT * FROM ( 
        SELECT a.*,sum(balance)  OVER(PARTITION BY account order BY a.date  asc   rows unbounded preceding) mybalance ,
b.name from bank_reconcile a JOIN coa b ON a.account=b.id 
ORDER BY account,date,id asc
                 
         ) h          ";



$statement = $conn->prepare($query);

$statement->execute();

$number_filter_row = $statement->rowCount();

$statement = $conn->prepare($query );

$statement->execute();

$result = $statement->fetchAll();

$data = array();

// $mydr=0;
// $mycr=0;

foreach($result as $row)
{
  
  
    $delete = ' <form method="post" action="" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="delete" value="' . $row["id"] . '"   "> <i class="fa fa-trash"></i>  </button></form> ' ; 
    $print = ' <form method="post" action="Report/bankreconciled" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="print" value="' . $row["id"] . '"   "> <i class="fa fa-print"></i>  </button></form> ' ; 
   
  
  $sub_array = array();
 // $sub_array[] =  $actionButton  ;
   $sub_array[] =  $delete  ;
   $sub_array[] =  $print  ;

  $sub_array[] = $row['date'];
  $sub_array[] = $row['name'];
  $sub_array[] = $row['memo']; 
  $sub_array[] = $row['description'];
  $sub_array[] =  number_format($row['balance'], 2) ; 
  $sub_array[] =  number_format($row['mybalance'], 2) ; 

  $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);

?>














