<?php
include_once 'opendb.php';
$filter="";
$CompID=0;

//print_r($_POST);

if (isset($_POST["filter"]))
{
     $filter=" and " . $_POST["filter"];

}
 if (isset($_POST["comp_id"]))
{
    $CompID=$_POST["comp_id"]; 
     $filter.=" and comp_id=" . $CompID;
}
if($CompID==0) {
    $response["message"] = "|No Web Co ID|";
               
        die( json_encode($response));
}
  if (isset($_POST["last_edit"]))
{
    $last_edit=$_POST["last_edit"];
    if ($last_edit=='') $last_edit="0" ;        
    $filter.=" and edit_time >= " . $last_edit  ;
    
}
// die($filter);
// echo "1"."</br>";
 
$Qry="SELECT prod_code,prod_name,barcode,quantity ,unit1,edit_time ,add_time,brand,category,price,price2,price3,mrp,cost,inactive,outof_stock,disp_order,packing,offer_price,offer_date,scheme_text,scheme_date,tax_rate,prod_name_local FROM products ";
$Qry.=" where 1=1 ".$filter . " order by edit_time " ;
$response["message"] =$Qry;
$result = $conn->query($Qry) or die(json_encode($response));
if ($result->num_rows > 0) {    
     $rows = array();
    while ($r = mysqli_fetch_assoc($result)) {   
         $rows[] = $r;
    }
    echo json_encode($rows);
} else {
    $response["message"] = "|No Records|";
    echo json_encode($response);
}
$conn->close();
?>
    