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






$query = "  SELECT a.*,b.name bname,b.code bcode,b.description bdescription,c.name cname,d.code dcode,
e.name ename,f.name fname    FROM itemprice a 
LEFT JOIN  item b ON a.item = b.id
LEFT JOIN  admpricegroup  c ON a.pricegroup=c.id
LEFT JOIN  acccurrency d ON a.currency=d.id
LEFT JOIN  aduom e ON a.uom = e.id
LEFT JOIN  adtaxrate f ON a.itemtaxrate=f.id  ";



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

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
  
   $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" 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="delete" value="' . $row["id"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i>  </button></form> ' ; 
      
 

   $sub_array = array();
  
   
   $sub_array[] =  $delete ;
   $sub_array[] =  $edit ;
   $sub_array[] =  $row['cname'];
   $sub_array[] =  $row['dcode'];
   $sub_array[] =  $row['date'];
  
   $sub_array[] =  $row['bname'];
   $sub_array[] =  $row['bcode'];
   $sub_array[] =  $row['bdescription'];
   $sub_array[] =  $row['ename'];
   $sub_array[] =  $row['fname'];
   $sub_array[] =  $row['itemprice'];
   // $sub_array[] =  $row['description'];
   // $sub_array[] =  $uomgroup ;
   // $sub_array[] =  $uomrate ;
   // $sub_array[] =  $uombase ;

//    $sub_array[] = $row['email'];
//    $sub_array[] = $row['bname'];
//    $sub_array[] = $row['pin'];
//    $sub_array[] = $row['vat'];
//    $sub_array[] = $row['address'];
//    $sub_array[] = $row['location'];
//    $sub_array[] = $row['cname'];
  
   $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);

?>




