<?php 

require_once("config/configDB.php"); 

if(isset($_POST['field']) && isset($_POST['value']) && isset($_POST['id'])){
    $field = mysqli_real_escape_string($conn,$_POST['field']); 
    $value = mysqli_real_escape_string($conn,$_POST['value']); 
    $editid = mysqli_real_escape_string($conn,$_POST['id']);
	
	$sql_rate=mysqli_query($conn,"select purchase_rate from product_rate_update where productid='$editid' ORDER BY id DESC LIMIT 1");
	
	//echo "select purchase_rate from product_rate_update where productid='$editid' ORDER BY id DESC LIMIT 1";
	
	$row_rate=mysqli_fetch_array($sql_rate,MYSQLI_ASSOC);
    
	$oldrate=$row_rate['purchase_rate'];
	
    
    $query = "UPDATE product_master SET purchase_rate='".$value."' WHERE id=".$editid;
    mysqli_query($conn,$query);
	
	
    
	$sqle=mysqli_query($conn,"select * from product_master where id='$editid'");
	while($row=mysqli_fetch_array($sqle))
	{
	$pid=$row['id'];
	$productcode=$row['productcode'];
	$productname=$row['productname'];
	$product_tamil=$row['product_tamil'];
	$qty_type=$row['qty_type'];
	$product_type=$row['product_type'];
	$purchase_rate=$row['purchase_rate'];
	$gst=$row['gst'];
	$hsn_code=$row['hsn_code'];
	$prodct_description=$row['prodct_description'];
	$create_date  	        = date("Y-m-d"); 
	
	
	$sql  = "INSERT INTO product_rate_update (productid,productcode, productname,product_tamil,qty_type,product_type,oldrate, purchase_rate, gst, hsn_code,prodct_description, create_date, isdelete) VALUES ('$pid','$productcode','$productname','$product_tamil','$qty_type','$product_type','$oldrate','$purchase_rate','$gst','$hsn_code','$prodct_description','$create_date', '1')";

echo $sql;

mysqli_query($conn,$sql);
	}
	
	}
	
	
exit;