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






$query = "  SELECT * FROM ( 
                              SELECT a.*,b.id bid ,b.name bname ,c.id cid ,c.name cname ,d.code dcode  , e.id eid , e.name ename  FROM bppartner a 
                                 JOIN bppartnertype b ON a.type=b.id   
                                 left JOIN bppartnerentity c ON a.entity =c.id 
                                 left JOIN acccurrency d ON a.currency =d.id 
                                 left JOIN adcountry e ON a.country =e.id  
                                 WHERE a.type=2

             ) h WHERE h.branch='$storeID' or h.branch= 0
";





// if($_POST["length"] != -1)
// {
//  $query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
// }

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

$result = $statement->fetchAll();

$data = array();

// $mydr=0;
// $mycr=0;

foreach($result as $row)
{
  
 //$actionButton = '<input type="radio" name="myradio" class="myradio" value="' . $row["id"] . '" /> </i></a>';
$edit = ' <form method="post" action="bpartnere" >  <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['bname'];
 $sub_array[] = $row['name'];
//  $sub_array[] = $row['regno'];
 $sub_array[] = $row['dcode'];
 $sub_array[] = $row['phone'];
 $sub_array[] = $row['email'];
 $sub_array[] = $row['pin'];
 $sub_array[] = $row['zrb'];
//  $sub_array[] = $row['website'];
 $sub_array[] = $row['address'];
//  $sub_array[] = $row['location'];
 $sub_array[] = $row['ename'];
 $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);

?>




