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






$query = "   SELECT * FROM ( SELECT a.*,b.date bdate,b.invnumber invnumber,b.memo bmemo,c.name cname ,d.name dname,
            e.name ename,f.name fname 
            FROM acctransactionsdetails a
                LEFT JOIN  acctransactions b ON a.transid=b.id
                LEFT JOIN admbranch c ON a.branch=c.id
                LEFT JOIN item d ON a.item = d.id
                left join aduom e on a.itemuom=e.id
                left join bppartner f on a.partner=f.id
                WHERE a.transmove=1 AND b.transtype=10 )z where z.branch='$storeID'

            " ;

$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; font-color:red; outline:none; " name="delete" value="' . $row["id"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i>  </button></form> ' ; 
    $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"></i>  </button></form> ' ; 
    $print = ' <form method="post" action="#" target="__blank">  <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[] =  $delete ;
     $sub_array[] =  $edit  ;
     $sub_array[] =  $print  ;
     $sub_array[] = $row['cname'];
     $sub_array[] = $row['fname'];
     $sub_array[] = $row['invnumber'];
     $sub_array[] = $row['bmemo'];
     $sub_array[] = $row['bdate'];
    
    
   
     $sub_array[] = $row['dname'];
     $sub_array[] = $row['ename'];
    // $sub_array[] =  number_format($row['uomunit'], 2, '.', ','); 
     $sub_array[] =  number_format($row['itemunit'], 2, '.', ','); 
  
     $sub_array[] = $row['itemprice'];
     $sub_array[] = number_format($row['itemsubtotal'], 2, '.', ','); 
     $sub_array[] = number_format($row['itemtax'], 2, '.', ','); 
     $sub_array[] = number_format($row['itemtotal'], 2, '.', ','); 
    //  $sub_array[] = $row['ename'];
    //  $mytotal = $mytotal + floatval( $row['glamount']  );
      $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);

?>