<?php
session_start();
require_once("config/configDB.php"); 
require "userPermission.php";
function validation_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

 $customername   = stripslashes($_POST['customername']);
 $cname_tamil   = stripslashes($_POST['cname_tamil']);
 
    $address1       = stripslashes($_POST['address1']);
   $customercode   = stripslashes($_POST['customercode']);
    $area          = stripslashes($_POST['area']);
	 $area_tamil          = stripslashes($_POST['area_tamil']);
   
    $pincode        = stripslashes($_POST['pincode']);
    $mobile         = stripslashes($_POST['mobile']);
	
	$opening_balance=$_POST['opening_balance'];
   
    $createdate  	= date("Y-m-d");
    $createdby      = stripslashes($_POST['createdby']);
    $userID         = stripslashes($_POST['userID']);

$autoinc=mysqli_query($conn,"ALTER TABLE customer_master CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");

$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cname) as counts FROM category_master WHERE cname = '$customername' "); // Check the database


while($row = mysqli_fetch_array($check_query)){
$count=$row['counts'];
}
if($count!=0){
// Already Exsist


		echo "<script> alert ('Data Inserted Success.');</script>";
		?>
<script language="javascript">window.location.href = "customerMasterDashboard.php";</script>
<?php
		

}		
else
{

$sql  = "INSERT INTO customer_master (cname,cname_tamil, caddress,  area,area_tamil, pincode, mobile, ccode,opening_balance, isdelete,createdby,userID,createdate) VALUES ('$customername','$cname_tamil', '$address1',  '$area','$area_tamil',  '$pincode', '$mobile',  '$customercode','$opening_balance', '1','".$createdby."','".$userID."','".$createdate."')";

mysqli_query($conn,$sql);



$conn->close();
}
// productID, customerID, productcode, productname, prodct_description, hsn_code, gst, purchase_rate, sale_rate


header("Location:customerMasterDashboard.php");




?>