<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include ("../navigation/header.php");
include ("../navigation/production_sidebar.php");
?>

<?php
		
	$s = $_GET['s'];
	$p = $_GET['p'];
	$_SESSION['p']=$p;
	$_SESSION['s']=$s;
	
	if (isset($_GET['prev_button']) )
	   {
		 $_SESSION['p']= $_SESSION['p']-1;
	   }
		 
	if (isset($_GET['next_button']) )
	  {
		$_SESSION['p']=$_SESSION['p']+1;
	  }
	
	if($s==1) {
		$_SESSION['production_date'] = $_GET['production_date'];
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$check_query = "SELECT production_date FROM $table_name WHERE production_date = '".$_SESSION['production_date']."'  ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num>0) {
			?>
            <script language="javascript" type="text/javascript">
			needToConfirm = false;
            window.location="production_planWizbase.php?s=&p=1&e=1";
			</script>
			 
			
            <?php
		}
		}

	
	if($s==2) {
	
		$table_name = $_SESSION['db_prefix']."_production_plan_lines_temp";
		$delete_query = "DELETE FROM $table_name WHERE user_name = '".$_SESSION['username']."' "; 
		execsql($delete_query);
		
		//$_SESSION['production_date'] = $_GET['production_date'];
		
		
		
		$year_no = date("Y", strtotime($_SESSION['production_date']));
		$month_no = date("m", strtotime($_SESSION['production_date']));
		$day_no = date("d", strtotime($_SESSION['production_date']));
		
		
		
		switch ($year_no) {
		case 2015: $year_code = 'A'; break;
		case 2016: $year_code = 'B'; break;
		case 2017: $year_code = 'C'; break;
		case 2018: $year_code = 'D'; break;
		case 2019: $year_code = 'E'; break;	
		case 2020: $year_code = 'F'; break;
		}
		
		switch ($month_no) {
    	case '01': $month_code = 'Z'; break;
		case '02': $month_code = 'Y'; break;
		case '03': $month_code = 'X'; break;
		case '04': $month_code = 'W'; break;
		case '05': $month_code = 'V'; break;
		case '06': $month_code = 'U'; break;
		case '07': $month_code = 'T'; break;
		case '08': $month_code = 'S'; break;
		case '09': $month_code = 'R'; break;
		case '10': $month_code = 'P'; break;
		case '11': $month_code = 'O'; break;
		case '12': $month_code = 'N'; break;
		}
		
		
		$_SESSION['batch_code'] = $year_code.$month_code.$day_no;
		
		$line_num = $_GET['line_num'];
		$i=0;
		while ($i < $line_num) {
			$store_item_id = $_GET['store_item_id'.$i];
			if ($store_item_id!='---') {
			$quantity = $_GET['quantity_text'.$i];	
			$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT subCategory, item_name, mix_design_id, item_type  FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
			$name_result = mySQL_query($name_query);
			$item_name = mysql_result($name_result, 0, "item_name");
			$sub_cat = mysql_result($name_result, 0, "subCategory");
			$mix_design_id = mysql_result($name_result, 0, "mix_design_id");
			$item_type = mysql_result($name_result, 0, "item_type");
			
					
			$table_name = $_SESSION['db_prefix']."_production_plan_lines_temp";
			$mix_query = "INSERT INTO $table_name (production_date, sub_category, mix_design_id, mix_design_name, item_type, skip_quantity, user_name) VALUES ('".$_SESSION['production_date']."', '".$sub_cat."', '".$mix_design_id."', '".$item_name."', '".$item_type."', '".$quantity."', '".$_SESSION['username']."'  ) ";
			execsql($mix_query);
			}
			$i++;
		}
		
		//$table_name = $_SESSION['db_prefix']."_production_plan";
//		$check_query = "SELECT production_date FROM $table_name WHERE  production_date = '".$_SESSION['production_date']."' ";
//		$check_result = mySQL_query($check_query);
//		$check_num = mysql_num_rows($check_result);
//		if ($check_num>0) {
//			  ?>
              <script language="javascript" type="text/javascript">
//         			 window.location="production_planWizbase.php?p=1&s=&e=1";
//			  </script>
              <?php
//		}
		
		}

	
	if($s==3) {
	
	
	};
	
	
	?>
    
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<!--reference to main.css removed-->    
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />

<!--jscript-->
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>    
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/go_to_url.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script> 
<script language="javascript" src="../jscript/calendar.js"></script>  


</head>

<body>
<div class="main_frame">

<table id="tableMain" width="595">
  <!--begin of tableMain-->
  <tr>
    <td >
    <div class="page_head_frame">
      <table width="678" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="547"><label class="label_page_head">Production plan</label>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
          <td width="131" align="center"><b>&nbsp;</b></td>
        </tr>
    </table>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
      <br /><br /><br /><br />

      <div class="wizard_paging_frame">
      <table align="left">
      <tr>
      <td>
      <?php if ($_SESSION['p']==1) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;1</div>
      <div class="active_step_label"><br /><br /><br />Select date</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;1</div>
      <div class="de_active_step_label"><br /><br /><br />Select date</div></div>
      <?php } ?>
      </td>
      <td>
      <?php if ($_SESSION['p']==2) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;2</div>
      <div class="active_step_label"><br /><br /><br />Select production</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;2</div>
      <div class="de_active_step_label"><br /><br /><br />Select production</div></div>
      <?php } ?>
      </td>
      <td>
      <?php if ($_SESSION['p']==3) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;2</div>
      <div class="active_step_label"><br /><br /><br />Finish</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;2</div>
      <div class="de_active_step_label"><br /><br /><br />Finish</div></div>
      <?php } ?>
      </td>
      
      </tr>
      </table>
      </div>
      <br /></td>
    <!--center of tableMain-->
  </tr>
  <tr>
    <td><!--center of tableMain-->
      <?php 
	if ($_SESSION['p']==1) { include("production_planWiz1.php"); }
	if ($_SESSION['p']==2) { include("production_planWiz2.php"); }
	if ($_SESSION['p']==3) { include("production_planWiz5.php"); }
	
    ?></td>
  </tr>
</table>

</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>
</html>