<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['m_name']) && isset($_POST['m_phone']) && isset($_POST['manager_id']) && isset($_POST['address']) && isset($_POST['email']))
{
	$ver = $_POST['manager_id'];
	$cust_id = $_POST['customer_id'];
	$m_name=$_POST['m_name'];
	$m_phone=$_POST['m_phone'];
	$address=$_POST['address'];
	$email=$_POST['email'];
	
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d")." ".date('h:i:sa');
	$res_product_stock = mysqli_query($con,"SELECT customer_name FROM  tbl_customer where customer_id='$cust_id'");
	if(mysqli_num_rows($res_product_stock)>0)
	{	
		$res_customer = mysqli_query($con,"SELECT * FROM  tbl_customer where customer_id='$cust_id'");
		while($fetch_detail=mysqli_fetch_assoc($res_customer))
		{
			$query = mysqli_query($con,"INSERT INTO `tbl_customer_history`(`customer_id`,`manager_id`, `customer_name`, `phone_no`, `email`, `address`, `insert_datetime`,`update_by`) VALUES ('$cust_id','".$fetch_detail['manager_id']."','".$fetch_detail['customer_name']."','".$fetch_detail['phone_no']."','".$fetch_detail['email']."','".$fetch_detail['address']."','$cdate','$ver')");	
			
			$uq2=mysqli_query($con,"update tbl_customer set customer_name='$m_name',phone_no='$m_phone',address='$address',email='$email',update_datetime='$cdate' where customer_id='$cust_id'"); 
		}
		$response['success']='1';
		$response['details']="Update Successful";			
	}
	else
	{
		$response['success']='0';
		$response['details']="Customer doesn't exists";
	}
}
else
{
	$response['success']='0';
	$response['details']="Required field missing";
}	
echo json_encode($response);
?>