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


$query = "  SELECT a.*, b.name bname, c.name cname, d.name dname   FROM orders a
            LEFT JOIN  branches b ON a.branch_id = b.id
            LEFT JOIN  groups  c ON a.group_id  = c.id
            LEFT JOIN  clients  d ON a.client_id = d.id 
            where a.uid='$uid'
            
              ";


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

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
  
    $approve = ' <form method="post" action="orderview" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="approve" value="' . $row["id"] . '"   "> <i class="fa fa-plus-circle fa-lg" style="color:green;" ></i>  </button></form> ' ; 

    $actionButton = '<i class="fa fa-circle" style="color:green;"></i>';
    //$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> ' ; 
    $delete = ' <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-trash" style="color:red;"></i>  </button></form> ' ; 
    
    
     $sub_array = array();
     $sub_array[] =  $approve  ;
    
     
     $sub_array[] = $row['bname'];
     $sub_array[] = $row['cname'];
     $sub_array[] = $row['group_loan_balance'];
     $sub_array[] = $row['group_arrears'];
     $sub_array[] = $row['dname'];
     $sub_array[] = $row['client_loan_balance'];
    
     $sub_array[] = $row['total_price'];
      $sub_array[] = $row['loan_term'];
       $sub_array[] =  $edit  ;
     $sub_array[] =  $delete  ;
    //  $sub_array[] = $row['slug'];
    // $sub_array[] = $row['price'];
    // $sub_array[] = $row['stock'];
    //  $sub_array[] = $row['ename'];
     
    //  $sub_array[] = $row['description'];
     $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);

?>












