<?php 
include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }
function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}

	date_default_timezone_set('Asia/Calcutta');
$today = date("d/m/y");
$today1 = date("d-m-Y");
$today2 = date("Y-m-d");
$received_time = date("Y-m-d H:i:s");

$currentyear = date("Y");
$currentmonth = date("m");

if($currentmonth>03) { 
$cuyear = date("Y");
$cuyear1 = date("y")+1;
} 
else { 
$cuyear = date("Y")-1;
$cuyear1 =  date("y");
} 
$f_year = "$cuyear"."-"."$cuyear1";


$unique_id = randomPassword();	

$querylogin = "select * from  mst_users where user_name = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_name = $row['user_name'];
$user_id09 = $row['user_id'];
$login_type = $row['login_type'];

}	
?>



<?php
	


$vendor_name=$_POST['vendor_name'];
$gst_no=$_POST['gst_no'];
$email_id=$_POST['email_id'];
$contractor_name=$_POST['contractor_name'];
$contact_no=$_POST['contact_no'];
$product_wise_details=$_POST['product_wise_details'];
$address=$_POST['address'];
$product_specification = $_POST['product_specification'];
$vendor_source = $_POST['vendor_source'];


$entry_by=$_POST['entry_by'];
$entry_date=$_POST['entry_date'];



$qryauto="insert into vendor_master(vendor_name,gst_no,address,unique_id,vendor_source,entry_by,entry_date) values ('$vendor_name','$gst_no','$address','$unique_id','$vendor_source','$user_id09','$today2')";
$rauto=mysqli_query($conn,$qryauto);
//echo $rauto;
//exit();



$qry9aid = "select * from vendor_master where unique_id = '$unique_id'";
$re9aid = mysqli_query($conn,$qry9aid);
while($row=mysqli_fetch_array($re9aid))
{  
$vendor_id = $row['vendor_id'];
}


$qryauto="insert into vendor_contact(contact_name,mobile_no,email_id,vendor_id) values ('$contractor_name','$contact_no','$email_id','$vendor_id')";
$rauto=mysqli_query($conn,$qryauto);


$max_contact2N = $_POST['cntcount3'];
if($max_contact2N!=''){
for ($n = 1; $n <= $max_contact2N; $n++) {	 
$product_name = ucwords(strtolower($_POST['product_name'.$n]));
$product_details = $_POST['product_details'.$n];
$unit = $_POST['unit'.$n];
$price = $_POST['price'.$n];

$search_vproduct_name = preg_replace('/[^A-Za-z0-9-()]/', '', $product_name);

$qrycallan = "insert into vendor_product_master(product_name,product_details,unit,price,vendor_id,search_vproduct_name) values ('$product_name','$product_details','$unit','$price','$vendor_id','$search_vproduct_name')";
$rcallan=mysqli_query($conn,$qrycallan);




}

}

//exit();

?>



<script>
javascript:window.location.href="view_vendor_details.php";
</script>


