<?php
date_default_timezone_set('Asia/Kolkata');
require_once("config/configDB.php"); 
require "userPermission.php";

$productcode   = stripslashes($_POST['productcode']);
$productname   = stripslashes($_POST['productname']);
$productname_tamil=$_POST['productname_tamil'];

$qty_type   = stripslashes($_POST['qty_type']);

$category   = stripslashes($_POST['category']);
$gst   = stripslashes($_POST['gst']);

$description   = stripslashes($_POST['description']);
$product_type="Sales";

$hsn=$_POST['hsn_code'];
//$create_date  	        = date("Y-m-d H:i:s"); 

$createdate  	= date("Y-m-d");
    $createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];

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

		$count=0;
$check_query	= mysqli_query($conn,"SELECT count(productcode) as counts FROM product_master WHERE productcode = '$productcode' "); // 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 = "productMasterDashboard.php";</script>
<?php
		

}		
else
{


$sql  = "INSERT INTO product_master (productcode, productname,productname_tamil,qty_type,product_type, category, gst,hsn, prodct_description, createddate,createdby,userId,isdelete) VALUES ('$productcode','$productname','$productname_tamil','$qty_type','$product_type','$category','$gst','$hsn','$description','$createdate', '$createdby','0','1')";

//echo $sql;

mysqli_query($conn,$sql);



$conn->close();
}

header("Location:productMasterDashboard.php");


?>