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






$query = "   SELECT * FROM (

            SELECT a.*,b.transtype,b.id bid,b.memo bmemo,b.notes bnotes, b.description bdescription, b.date bdate ,b.memo,b.notes,
            c.name cname,d.code dcode,e.name ename,f.name fname,g.name gname,i.fname ifname ,i.lname ilname   FROM  acctransactionsdetails a 
            LEFT JOIN  acctransactions b ON  a.transid=b.id 
            LEFT JOIN bppartner c ON a.partner=c.id 
            LEFT JOIN  acccurrency d ON a.currency=d.id
            LEFT JOIN coa e ON a.coa=e.id
            LEFT JOIN admbranch f ON a.branch=f.id
            LEFT JOIN coa g ON a.coagen=g.id
            LEFT JOIN sys_user i on b.transuid=i.id
            WHERE b.transtype=15   AND transmove=5

             )h where h.branch= '$storeID' order by h.bdate desc    ";




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

$statement->execute();

$number_filter_row = $statement->rowCount();

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

$statement->execute();

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
  
    $actionButton = '<input type="radio" name="myradio" class="myradio" value="' . $row["id"] . '" /> </i></a>';
    $edit = ' <form method="post" action="expensesedit" >  <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="deleteexpe" value="' . $row["bid"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i>  </button></form> ' ; 
    
  $print = ' <form method="post" action="printexpense" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="printexpense" value="' . $row["bid"] . '"   "> <i class="fa fa-print" style="color:green;" ></i>  </button></form> ' ; 
  

    $sub_array = array();
   
    $sub_array[] =  $print ;
     $sub_array[] =  $edit ;
     $sub_array[] =  $delete ;
    $sub_array[] = $row['fname'];
    $sub_array[] = $row['gname'];
    $sub_array[] = $row['bdate'];
    $sub_array[] = $row['cname'];
    $sub_array[] = $row['dcode'];
    $sub_array[] = $row['bmemo'];
    $sub_array[] = $row['bdescription'];  
    $sub_array[] =  number_format($row['itemtotal'], 2, '.', ','); 
    //$sub_array[] = $row['itemtotal'];
    $sub_array[] = $row['ename'];
    $sub_array[] = $row['ifname'].' '.$row['ilname'];
     
    $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);

?>
