<?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
$queryls = "select * from rowmaterial_master where row_id = '".$_POST['row_id']."'";
$resultls = mysqli_query($conn,$queryls);	
while($row=mysqli_fetch_array($resultls))
{
$bar_size=$row['bar_size'];
$material_name=$row['material_name'];
}
$row_id = $_POST['row_id'];
$item_code=$_POST['item_code'];
$description=$_POST['description'];
$bom_weight_kg=$_POST['bom_weight_kg'];
$bar_size_unit=$_POST['bar_size_unit'];
$finish_shaft_wt_kg=$_POST['finish_shaft_wt_kg'];
$old_labour_rate_rs = $_POST['old_labour_rate_rs'];
$revised_labour_rate_rs = $_POST['revised_labour_rate_rs'];

$difference=$_POST['difference'];
$add_kw_rate_mail=$_POST['add_kw_rate_mail'];
$add_bmst_kw_ext_rate=$_POST['add_bmst_kw_ext_rate'];
$final_i_c_rate=$_POST['final_i_c_rate'];
$category_id=$_POST['category_id'];

$DRAWING_NO=$_POST['DRAWING_NO'];
$CUT=$_POST['CUT'];
$FINISH=$_POST['FINISH'];
$DE=$_POST['DE'];
$NDE=$_POST['NDE'];


$queryls = "select * from category_master where category_id = '".$_POST['category_id']."'";
$resultls = mysqli_query($conn,$queryls);	
while($row=mysqli_fetch_array($resultls))
{
$category_id=$row['category_id'];
$category_name=$row['category_name'];
}

$turning_scrap_wt=$_POST['turning_scrap_wt'];

 $qryauto="insert into finish_product_master(row_id,bar_size,material_name,item_code,description,bom_weight_kg,bar_size_unit,finish_shaft_wt_kg,old_labour_rate_rs,revised_labour_rate_rs,difference,add_kw_rate_mail,add_bmst_kw_ext_rate,final_i_c_rate,turning_scrap_wt,entry_by,entry_date,category_id,category_name,DRAWING_NO,CUT,FINISH,DE,NDE) values ('$row_id','$bar_size','$material_name','$item_code','$description','$bom_weight_kg','$bar_size_unit','$finish_shaft_wt_kg','$old_labour_rate_rs','$revised_labour_rate_rs','$difference','$add_kw_rate_mail','$add_bmst_kw_ext_rate','$final_i_c_rate','$turning_scrap_wt','$user_id09','$today','$category_id','$category_name','$DRAWING_NO','$CUT','$FINISH','$DE','$NDE')";
$rauto=mysqli_query($conn,$qryauto);
$rauto;
//exit();




//exit();

?>



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


