<?php include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }
	
date_default_timezone_set('Asia/Calcutta');
$today = date("d-m-Y");
$time = date("h:i A"); 
$currentyear = date("Y");

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
}
$unique_id = randomPassword();


?>
<?php 
$querylogin = "select * from  users where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_id = $row['user_id'];
$first_name = $row['first_name'];
$login_type=$row['login_type'];
}

?>



  
<?php
$package_name = $_POST['package_name'];
$format = $_POST['format'];
$unit = $_POST['unit'];
$price = $_POST['price'];
$stock = $_POST['stock'];


$query1 = "insert into package_master (package_name,format,unit,price,unique_id,entry_by,entry_date,entry_time,stock) values ('$package_name','$format','$unit','$price','$unique_id','$user_id','$today','$time','$stock')";
//echo $query;
$result=mysqli_query($conn,$query1);


$qry9 = "select * from package_master where unique_id = '$unique_id'";
$re9 = mysqli_query($conn,$qry9);
while($row=mysqli_fetch_array($re9))
{  
$package_id  = $row['package_id'];
}



$max_contact2N = $_POST['cntcount2'];
if($max_contact2N!=''){
for ($n = 1; $n <= $max_contact2N; $n++) {	 
$product_id = $_POST['product_id'.$n];
$unit = $_POST['unit'.$n];
$quantity = $_POST['quantity'.$n];

$qry10 = "select * from  product_master where product_id = '$product_id'";
$re10 = mysqli_query($conn,$qry10);
while($row=mysqli_fetch_array($re10))
{  
$product_name  = $row['product_name'];
}



$qrycallan = "insert into  product_BOM (product_name,product_id,unit,package_id,package_name,quantity) values ('$product_name','$product_id','$unit','$package_id','$package_name','$quantity')";
$rcallan=mysqli_query($conn,$qrycallan);


}

}


//echo "<br>";






//exit();

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