<?php
	//Connects to your Database
	include "../db_connection/db_connection.php";
	include "../config/config.php";		
	$page_id	=	base64_decode(base64_decode(base64_decode($_GET['page_id']))); //THIS IS PAGE ID  

if($page_id==1) 
{
		//$hdes_name	=	$_POST['hdes_name'];
		$lob		=	$_POST['lob']; 
		$lob		= 	str_replace("/", "-", $lob);
		$pack_name	=	$_POST['pack_name'];
		$cut_name	=	$_POST['cut_name'];
		$lop = 0;
		$mat_name = $_POST['mat_name'];	
		foreach($_POST['category'] as $cat_id)
		{

			//echo $mat_name;
			$mas_wt = $_POST['mas_wt'][$cat_id];

			//echo $cat_id."-".$mat_name."-".$mas_wt."<br/>";	
			$INSRT_d	= "INSERT INTO mas_finishing(`design_det_id`, `master_mat_id`, `mas_weight`, `finishing_date`, `post_dt`) VALUES('$cat_id','$mat_name','$mas_wt','$lob','$cur_time')";
			//echo $INSRT_d;
			$QURY_d		= mysqli_query($connect,$INSRT_d);

			//THI IS FOR UPDATING THE DESIGN STATUS
			$UPDATE = "UPDATE design_det SET design_status = 'In Master Finishing',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
			//echo $UPDATE;
			$QRY    = mysqli_query($connect,$UPDATE); 

			//THI IS FOR UPDATING THE Buffing Finishing STATUS
			$UPDATE_cd = "UPDATE buf_finishing_des SET buf_fin_status = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
			//echo $UPDATE_cd;
			$QRY_cd    = mysqli_query($connect,$UPDATE_cd); 

			//This is for insert the design to the stack details
			$INRT_sto	= "INSERT INTO `stock_det`(`design_det_id`, `pack_emp_id`, `cut_emp_id`, `die_fin_date`, `stock_rel_date`, `post_dt`) VALUES ('$cat_id','$pack_name','$cut_name','$lob','','$cur_time')";
			//echo $INRT_sto;
			$QURY_sto	= mysqli_query($connect,$INRT_sto);	

			$lop++;
		}

?>
		<script type="text/javascript">
            //alert("Data inserted successfully");
            //history.back();
            window.location='../mas_finishing_list.php';
        </script>
<?php
}
else if($page_id==2) 
{
		$lop = 1;
		$finishing_date = $_POST['finishing_date'];
		$mat_name = $_POST['mat_name'];
		foreach($_POST['category'] as $cat_id)
		{

			//echo $mat_name;
			$mas_wt = $_POST['mas_wt'][$cat_id];
					
			$UPDATE_cd = "UPDATE mas_finishing SET `master_mat_id`='$mat_name', `mas_weight`='$mas_wt',`update_dt`='$cur_time' WHERE design_det_id = '$cat_id'";		
			//echo $UPDATE_cd;
			$QRY_cd    = mysqli_query($connect,$UPDATE_cd); 
			$lop++;	
		}

?>
	<script type="text/javascript">
		//alert("Data inserted successfully");
		//history.back();
		window.location='../mas_finishing_upd.php?finishing_date=<?php echo $finishing_date ?>';
	</script>
<?php
}
?>
	
