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






$query = "       SELECT x.*,y.name yname ,z.name zname,v.name vname
                  FROM ( 

                                    SELECT a.id,a.branch branch,a.item,a.itemuom,a.itemunit,a.itemout,a.transmove, b.transtype,b.transmode btransmode,b.date,b.memo
                                    FROM acctransactionsdetails a
                                    LEFT JOIN acctransactions b ON a.transid=b.id
                                    WHERE b.transtype=10 OR b.transtype=18
                                                    
                                                        union
                                                        
                                    SELECT a.id,a.branch branch,a.item,a.itemuom,a.itemunit,a.itemout,a.transmove, b.transtype,b.transmode btransmode,b.date,b.memo
                                            FROM acctransactionsdetails a
                                                    LEFT JOIN acctransactions b ON a.transid=b.id
                                                    WHERE b.transtype=21
					   )x 
                         left join item y on x.item=y.id 
                         left join aduom z on x.itemuom=z.id 
                         left join adtransactiontype v on x.transtype=v.id 
                       
                       WHERE x.transmove=1 and x.branch='$storeID'   
        ";




$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="" /> </i></a>';
    //$edit = ' <form method="post" action="invcategorye" >  <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> ' ; 
    // $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> ' ; 
    
    
     $sub_array = array();
     $sub_array[] =  $actionButton  ;
     // $sub_array[] =  $edit  ;
     $sub_array[] = $row['vname'];
     $sub_array[] = $row['date'];
     $sub_array[] = $row['memo'];
     $sub_array[] = $row['yname'];
     $sub_array[] = $row['zname'];
     $sub_array[] =  number_format($row['itemout'], 2, '.', ','); 

    //  $sub_array[] = $row['name'];
    //  $sub_array[] = $row['code'];
    //  $sub_array[] = $row['itemunittotal'];
     
    //  $sub_array[] = $row['description'];
    //  $sub_array[] = $row['fname'];
    //  $sub_array[] = $row['gname'];
     $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);

?>

