
<?php
require_once ('../include/tc_calendar.php');
$depallet_date = strtotime($_SESSION['production_date']);
$day = date("l", $depallet_date );
$d = date("d", $depallet_date );
$m = date("m", $depallet_date );
$y = date("Y", $depallet_date );

if ($day=='Friday') {
	  $d=$d+3;
	  $to_depallet_date = date("Y-m-d") ;
}
else {
	$d=$d+1;
	$to_depallet_date = date("Y-m-d") ;
	
}


       
$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$production_line_query = "SELECT * FROM $table_name WHERE production_no = '".$_SESSION['production_no']."' ";
$production_line_result = mySQL_query($production_line_query);
$_SESSION['production_line_num'] = mysql_num_rows($production_line_result);
  
?>


</head>

<body >


<div class="wizard_page_middle_frame">   
<form id="form1" method="get" action="depallet_countWizbase.php">

<div class="wizard_frame">
                <table width="649" border="0">
                  <tr>
                    <td width="117"><label class="label_std">Depallet date:</label></td>
                    <td width="522"><?php

		$myCalendar = new tc_calendar("depallet_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2015, 2090);
		$myCalendar->writeScript();
?></td>
                  </tr>
                </table>
</div>
             
     <div class="wizard_frame">
      <table width="600" id='table_details_display'>
      <thead>
        <tr>
          <td width="226">Product</td>
          <td width="96" align="center">Produced<br>
            skips/batch</td>
          <td width="86" align="center">Produced<br>
            quantity
          </td>
          <td width="76" align="center">Depalleted<br>
            quantity</td>
          <td width="92" align="center">Pallets</td>
        </tr>
       </thead>
       <?php
	   $i=0;
	   while ($i<$_SESSION['production_line_num']) {
		   $mix_design_no =  mysql_result($production_line_result, $i, "mix_design_no");
		   $mix_design_name = mysql_result($production_line_result, $i, "mix_design_name");
		   $skip_quantity = mysql_result($production_line_result, $i, "skip_quantity");
		   $wet_quantity = mysql_result($production_line_result, $i, "wet_produced");
		   		   
		   
		   	$table_name = $_SESSION['db_prefix']."_depallet_count_temp";
			$produced_query = "SELECT depallet_quantity, pallets FROM $table_name WHERE production_no = '".$_SESSION['production_no']."' AND mix_design_no = '".$mix_design_no."' and user_name = '".$_SESSION['username']."'  ";
			$produced_result = mySQL_query($produced_query);
			$produced_num = mysql_num_rows($produced_result);
			if ($produced_num>0) {
			$depallet_quantity = mysql_result($produced_result, 0, "depallet_quantity");
			$pallets = mysql_result($produced_result, 0, "pallets");
			}
			else {
				$depallet_quantity='';
				$pallets='';
			}
		   
		   ?>	   
        <tr>
          <td><?php echo $mix_design_name ?><input name="mix_design_no<?php echo $i ?>" type="hidden" value="<?php echo $mix_design_no ?>"> </td>
          <td><?php echo $skip_quantity ?></td>
          <td><?php echo $wet_quantity ?></td>
          <td><input type="text" name="depallet_text<?php echo $i ?>" id="depallet_text<?php echo $i ?>" width="25px;" class="text60" value="<?php echo $depallet_quantity ?>"></td>
          <td><input type="text" name="pallets_text<?php echo $i ?>" id="pallets_text<?php echo $i ?>" width="25px;" class="text60" value="<?php echo $pallets ?>"></td>
        </tr>
        <?php
		$i++;
	   }
		?>
        <input name="production_line_num" type="hidden" value="<?php echo $_SESSION['production_line_num'] ?>">
      </table>
    </div>          
            <div class="wizard_frame">
              <table width="645" height="50" align="center" id="table_button_bar">
                <tr>
                  <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_goToURL('parent','depallet_countWizbase.php?s=&amp;p=1');return document.MM_returnValue" /></td>
                  <td width="115">&nbsp;</td>
                  <td width="99">
                    <input name="p" type="hidden" id="p" value="2" />
                    <input name="s" type="hidden" id="s" value="2" />
                  </td>
                  <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php?date=0');" value="Cancel" /></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; " /></td>
                </tr>
              </table>
    </div>
<script>
alertMessage(1, '', 'This is the production of <?php echo date("l, d-m-Y", strtotime($_SESSION['production_date']))?>.<br>Depallet date is set to <?php echo date("l, d-m-Y", strtotime($to_depallet_date)) ?>.'); 
</script>              
</form>
</div>
<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 20; i++) {
	frmvalidator.addValidation("skip_quantity"+i,"req","- no of skips on line "+(i+1)+".");
	frmvalidator.addValidation("wet_quantity"+i,"req","- quantity products on line "+(i+1)+".");
  }
  </script>


	
 </body>