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






$query = " SELECT * FROM ( 
           SELECT a.*,b.id bid,b.invnumber binvnumber,b.date bdate,b.enddate benddate,b.memo bmemo,b.voucher bvoucher ,b.transtype,
           b.transaction,b.transmode,c.name cname ,e.name ename,f.name fname   FROM  acctransactionsdetails a
          LEFT JOIN acctransactions b ON a.transid=b.id
          LEFT JOIN bppartner c ON a.partner=c.id
        
          LEFT JOIN admbranch e on a.branch=e.id
          LEFT JOIN admbranch f on a.branchto =f.id
          WHERE a.transmove=5  AND b.transtype=21 
       
          )h  where h.branch= '$storeID'  order by h.bdate  desc ";



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

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
   
   $actionButton = '<i class="fa fa-circle" style="color:green;"> </i></a>';
   $edit = ' <form method="post" action="transferedit" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="edit" value="' . $row["bid"] . '"   "> <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="deletetrans" value="' . $row["bid"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i>  </button></form> ' ; 
   $print = ' <form method="post" action="printtransfer" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="printtransfer" value="' . $row["bid"] . '"   "> <i class="fa fa-print" style="color:green;" ></i>  </button></form> ' ; 
 
        
   $sub_array = array();
  
   $sub_array[] =  $actionButton ;
   $sub_array[] =  $delete ;
   $sub_array[] =  $edit ;
   $sub_array[] =  $print ;
   $sub_array[] =  $row['ename'];
   $sub_array[] =  $row['fname'];
   $sub_array[] =  $row['binvnumber'];
   $sub_array[] =  $row['bdate'];
   $sub_array[] =  $row['benddate'];   
   $sub_array[] =  $row['bmemo'];
   
   $sub_array[] =  number_format($row['itemtotal'], 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);

?>




