<head>

<!--jscript-->
<script language="JavaScript"  src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  



</head>
<?php include('../include/wait.php') ?>
<body onLoad="MM_showHideLayers('wait','','hide'); <?php if ($_SESSION['error3']=='yes') {?> alert('The issued quantity and required quantity do not match.\r\n\r\nPlease adjust quantities.');<?php } ?>" onFocus="MM_showHideLayers('wait','','hide'); ">
<?php $_SESSION['error3']='no'?>
<div class="page_middle_frame">
<form id="form1" method="POST"  action="trussesJobWizbase.php?p=5&s=4"  >
<table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
        <td width="525" ><div class="wizard_frame"  onmousemove="calculateSum();" >
       <label class="label_std">S5 Timber</label>
<table width="667" border="0">
  <tr>
    <td width="194">Item</td>
    <td>Current stock</td>
    <td width="92">Quantity</td>
    <td width="86" align="right">Length</td>
    <td width="113">&nbsp;</td>
  </tr>
</table>
<hr>  
<?php
$i=0;
while ($i<4) {
$table_name = $_SESSION['db_prefix']."_cutting_temp";
$selected_query = "SELECT store_item_id, quantity FROM $table_name WHERE job_id  = '".$_SESSION['job_no']."' AND class='S5' AND width='".$_SESSION['S5_width'.$i]."' AND user =  '".$_SESSION['username']."' ORDER BY depth, width, length "; 
$selected_result = mySQL_query($selected_query);
$selected_num = mysql_num_rows($selected_result);
?>
<table width="667" id="table_resume_wizard3">

    <?php
	$t=0;
	$tab=0;
while ($t<$selected_num) {
	?>
 <script>
    $(document).ready(function(){
        //iterate through each textboxes and add keyup
        //handler to trigger sum event
        $(".text60<?php echo $i?>").each(function() {
             $(this).keyup(function(){
                calculateSum<?php echo $i?>();
            });
        });

    });
 
    function calculateSum<?php echo $i?>() {
         var sum = 0;
        //iterate through each textboxes and add the values
        $(".text60<?php echo $i?>").each(function() {
             //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum += parseFloat(this.value);
            }
         });
        //.toFixed() method will roundoff the final sum to 2 decimal places
        $("#sum<?php echo $i?>").html(sum.toFixed(2));
		issued_total<?php echo $i?> = (sum.toFixed(2));
		document.getElementById('issued_total<?php echo $i?>').value = issued_total<?php echo $i?> ;
		var  sum3 = sum1 + sum2;
    }
</script>       
<?php
	
	
	$a1 = mysql_result($selected_result, $t, "store_item_id");
	$a6 = mysql_result($selected_result, $t, "quantity");
	
	
	$table_name = $_SESSION['db_prefix']."_store_items";
	$name_query = "SELECT item_name, length, quantity, depth, width FROM $table_name WHERE store_item_id = '".$a1."' ";
	$name_result = mySQL_query($name_query);
	$a2 = mysql_result($name_result, 0, "item_name");
	$a4 = mysql_result($name_result, 0, "length");
	$a3 = mysql_result($name_result, 0, "quantity");
	
	
	
		
	$table_name = $_SESSION['db_prefix']."_captured_timber";
	$required_query = "SELECT SUM(cap_timber_length) AS required_length  FROM $table_name WHERE cap_width='".$_SESSION['S5_width'.$i]."' AND cap_timber_group = 'Trusses' AND cap_job ='". $_SESSION['job_no']."' AND cap_class='S5' GROUP BY cap_width  ";
	$required_result = mySQL_query($required_query);
	$required_num = mysql_num_rows($required_result);
	if ($required_num>0) {
			$_SESSION['required_length'.$i] = mysql_result($required_result, 0, "required_length");
	}
	else {
			$_SESSION['required_length'.$i] = 0;
	}
	
	

?>
   <tr> 
    <td width="194"><label class="label_std"><?php echo $a2 ?>
      <input type="hidden" name="<?php echo "store_item_id".$i.$t ?>" id="<?php echo "store_item_id".$i.$t ?>"  value="<?php echo $a1 ?>"/>
      <input type="hidden" name="<?php echo "length".$i.$t ?>" id="<?php echo "length".$i.$t ?>"  value="<?php echo $a4 ?>"/>
    </label></td>
    <td width="66" align="right"><?php echo number_format($a3, 0, '.', ',') ?>&nbsp;no</td>
    <td width="186" align="right">&nbsp;<input name="<?php echo "qty_text".$i.$t ?>" type="text" class="text40" id="<?php echo "qty_text".$i.$t ?>" tabindex="<?php echo $tab+1?>" style="text-align:right"  onfocus = "this.select(); " autocomplete="off" autofocus value="<?php if($a6!=0) { echo $a6; }?>"
onkeyup=" 
   var textValue1 = document.getElementById('<?php echo "length".$i.$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text".$i.$t ?>').value;
   var textValue3 = (((textValue1 * textValue2) / 1000).toFixed(2));
   document.getElementById('<?php echo 'sub'.$i.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text'.$i.$t ?>').value = textValue3;
   calculateSum<?php echo $i?>(); 
" 
onblur=" 
   var textValue1 = document.getElementById('<?php echo "length".$i.$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text".$i.$t ?>').value;
   var textValue3 = (((textValue1 * textValue2) / 1000).toFixed(2));
   document.getElementById('<?php echo 'sub'.$i.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text'.$i.$t ?>').value = textValue3;
   calculateSum<?php echo $i?>(); 
" 
onkeypress="return numbersonly(this, event)"  />      
      &nbsp;</td>
    <td width="86" align="right"><label id=<?php echo 'sub'.$i.$t ?> ></label> 
      m </td>
    <td width="113" align="right"><input type="text" name="<?php echo 'text'.$i.$t ?>" id="<?php echo 'text'.$i.$t ?>" class='text60<?php echo $i?>' style="width:25px;" hidden="hidden"></td>
   
</tr>
    
    <?php

$t++;
$_SESSION['list_no_4a'.$i]=$t;
//echo '<br>'.'no'.$i.'='.$_SESSION['list_no_4a'.$i]; 
}

?>
 <tr>
     <td colspan="2"><?php if ($t==0) {
     if ($_SESSION['required_length'.$i]>0) {?>
      <font color="#FF0000"><b>No items selected but quoted length for  38x<?php echo $_SESSION['S5_width'.$i] ?> is <?php echo $_SESSION['required_length'.$i]; $_SESSION['list_no_4a'.$i]=0;?> m</b></font>
	  <?php } else { ?>
		<b>No items selected, nothing quoted  for 38x<?php echo $_SESSION['S5_width'.$i]; $_SESSION['list_no_4a'.$i]=0; ?>.</b>
        <?php }
	 } else { 
     if ($_SESSION['required_length'.$i]>0) { ?>
     Quoted Length:&nbsp;&nbsp;<?php echo $_SESSION['required_length'.$i] ?>
     <?php } 
	 else {
		 ?>
     <font color="#FF0000"><b>Items selected but nothing quoted  for 38x<?php echo $_SESSION['S5_width'.$i] ?>.</b></font>    
	 <?php }
	 }?></td>
     <td align="right"><?php if (($_SESSION['required_length'.$i]!=0) OR ($t>0)){?> Total Length:<?php } ?></td>
     <td align="right"><?php if(($_SESSION['required_length'.$i]!=0) OR ($t>0)){?><label class="txt3"><b><span id="sum<?php echo $i?>"></span> m</b></label><?php } ?>
		      </td>
     <td align="right"><span class="label_std">
       <input name="issued_total<?php echo $i?>"  id="issued_total<?php echo $i?>" type="text" size="5" readonly hidden="hidden" >
     </span></td>
   </tr>     
</table> 
<hr>
<br>
 
 <?php
$i++;

}
  

?>
         
        </div>
<table width="667" border="0">
  <tr>
    <td width="661">&nbsp;&nbsp;</td>
  </tr>
</table>

          <div class="wizard_frame"  onmousemove="calculateSum();" >
          <label class="label_std">S7 Timber</label>
            <table width="667" border="0">
              <tr>
                <td width="194">Item</td>
                <td>Current stock</td>
                <td width="92">Quantity</td>
                <td width="86" align="right">Length</td>
                <td width="113">&nbsp;</td>
              </tr>
            </table>
            <hr>
            <?php
$j=0;
while ($j<3) {
$table_name = $_SESSION['db_prefix']."_cutting_temp";
$selected_query = "SELECT store_item_id, quantity FROM $table_name WHERE job_id  = '".$_SESSION['job_no']."' AND class='S7' AND width='".$_SESSION['S7_width'.$j]."'  AND user =  '".$_SESSION['username']."'  ORDER BY depth, width, length "; 
$selected_result = mySQL_query($selected_query);
$selected_num = mysql_num_rows($selected_result);
?>
            <table width="667" id="table_resume_wizard3">
              <?php
$t=0;
while ($t<$selected_num) {
	?>
              <script>
    $(document).ready(function(){
        //iterate through each textboxes and add keyup
        //handler to trigger sum event
        $(".text60<?php echo $j?>").each(function() {
             $(this).keyup(function(){
                calculateSum2_<?php echo $j?>();
            });
        });

    });
 
    function calculateSum2_<?php echo $j?>() {
         var sum = 0;
        //iterate through each textboxes and add the values
        $(".text2_60_<?php echo $j?>").each(function() {
             //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum += parseFloat(this.value);
            }
         });
        //.toFixed() method will roundoff the final sum to 2 decimal places
        $("#sum2_<?php echo $j?>").html(sum.toFixed(2));
		issued_total2_<?php echo $j?> = (sum.toFixed(2));
		document.getElementById('issued_total2_<?php echo $j?>').value = issued_total2_<?php echo $j?> ;
		var  sum3 = sum1 + sum2;
    }
              </script>
     
              <?php
	
	
	$a1 = mysql_result($selected_result, $t, "store_item_id");
	$a6 = mysql_result($selected_result, $t, "quantity");
	
	$table_name = $_SESSION['db_prefix']."_store_items";
	$name_query = "SELECT item_name, length, quantity FROM $table_name WHERE store_item_id = '".$a1."' ";
	$name_result = mySQL_query($name_query);
	$a2 = mysql_result($name_result, 0, "item_name");
	$a4 = mysql_result($name_result, 0, "length");
	$a3 = mysql_result($name_result, 0, "quantity");
	
	
	$table_name = $_SESSION['db_prefix']."_captured_timber";
	$required_query = "SELECT SUM(cap_timber_length) AS required_length  FROM $table_name WHERE cap_width='".$_SESSION['S7_width'.$j]."' AND cap_timber_group = 'Trusses' AND cap_job ='". $_SESSION['job_no']."' AND cap_class='S7' GROUP BY cap_width  ";
	$required_result = mySQL_query($required_query);
	$required_num = mysql_num_rows($required_result);
	if ($required_num>0) {
			$_SESSION['required_length2_'.$j] = mysql_result($required_result, 0, "required_length");
	}
	else {
			$_SESSION['required_length2_'.$j] = 0;
	}
	

?>
              <tr>
                <td width="194"><label class="label_std"><?php echo $a2 ?>
                  <input type="hidden" name="<?php echo "store_item_id2_".$j.$t ?>" id="<?php echo "store_item_id2_".$j.$t ?>"  value="<?php echo $a1 ?>"/>
                  <input type="hidden" name="<?php echo "length2_".$j.$t ?>" id="<?php echo "length2_".$j.$t ?>"  value="<?php echo $a4 ?>"/>
                </label></td>
                <td width="66" align="right"><?php echo number_format($a3, 0, '.', ',') ?>&nbsp;no</td>
                <td width="186" align="right">&nbsp;
                  <input name="<?php echo "qty_text2_".$j.$t ?>" type="text" class="text40" id="<?php echo "qty_text2_".$j.$t ?>" tabindex="<?php echo $tab+1?>" style="text-align:right"  onfocus = "this.select(); " autocomplete="off" autofocus value="<?php if($a6!=0) { echo $a6; }?>"
onkeyup=" 
   var textValue1 = document.getElementById('<?php echo "length2_".$j.$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text2_".$j.$t ?>').value;
   var textValue3 = (((textValue1 * textValue2) / 1000).toFixed(2));
   document.getElementById('<?php echo 'sub2_'.$j.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text2_'.$j.$t ?>').value = textValue3;
   calculateSum2_<?php echo $j?>(); 
" 
onblur=" 
   var textValue1 = document.getElementById('<?php echo "length2_".$j.$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text2_".$j.$t ?>').value;
   var textValue3 = (((textValue1 * textValue2) / 1000).toFixed(2));
   document.getElementById('<?php echo 'sub2_'.$j.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text2_'.$j.$t ?>').value = textValue3;
   calculateSum2_<?php echo $j?>(); 
" 
onkeypress="return numbersonly(this, event)"  />
                  &nbsp;</td>
                <td width="86" align="right"><label id=<?php echo 'sub2_'.$j.$t ?> ></label>
                  m </td>
                <td width="113" align="right"><input type="text" name="<?php echo 'text2_'.$j.$t ?>" id="<?php echo 'text2_'.$j.$t ?>" class='text2_60_<?php echo $j?>' style="width:25px;" hidden="hidden" ></td>
              </tr>
              <?php

$t++;
$_SESSION['list_no_4b'.$j]=$t;
//echo '<br>'.$_SESSION['list_no_4b'.$j];
}

?>
              <tr>
                <td colspan="2"><?php if ($t==0) {
     if ($_SESSION['required_length2_'.$j]>0) {?>
      <font color="#FF0000"><b>No items selected but quoted length for  38x<?php echo $_SESSION['S7_width'.$j] ?> is <?php echo $_SESSION['required_length2_'.$j]; $_SESSION['list_no_4b'.$j]=0; ?> m</b></font>
	  <?php } else { ?>
		<b>No items selected, nothing quoted  for 38x<?php echo $_SESSION['S7_width'.$j]; $_SESSION['list_no_4b'.$j]=0; ?>.</b>
        <?php }
	 } else { 
     if ($_SESSION['required_length2_'.$j]>0) { ?>
     Quoted Length:&nbsp;&nbsp;<?php echo $_SESSION['required_length2_'.$j] ?>
     <?php } 
	 else {
		 ?>
     <font color="#FF0000"><b>Items selected but nothing quoted  for 38x<?php echo $_SESSION['S7_width'.$j] ?>.</b></font>    
	 <?php }
	 }?></td>
     <td align="right"><?php if (($_SESSION['required_length2_'.$j]!=0) OR ($t>0)){?> Total Length<?php } ?></td>
     <td align="right"><?php if (($_SESSION['required_length2_'.$j]!=0) OR ($t>0)){?> <label class="txt3"><b><span id="sum2_<?php echo $j?>"></span></b></label><b>m</b><?php } ?></td>
                <td align="right"><span class="label_std">
                  <input name="issued_total2_<?php echo $j?>"  id="issued_total2_<?php echo $j?>" type="text" size="5" readonly hidden="hidden"  >
                </span></td>
                
                
              </tr>
            </table>
            <hr>
            <br>
            <?php
$j++;
}

?>
        </div></td>
    </tr>
          <tr>
            <td>
              <table width="675" 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_showHideLayers('wait','','show');MM_goToURL('parent','trussesJobWizbase.php?s=&amp;p=3');return document.MM_returnValue" tabindex="<?php echo $tab+2?>"/></td>
                  <td width="115">&nbsp;</td>
                  <td width="99"><span class="wizard">
                    <input name="s" type="hidden" id="s" value="4" />
                    <input name="p" type="hidden" id="p" value="4" />
                  </span></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')" value="Cancel" tabindex="<?php echo $tab+3?>"/></td>
                  <td width="110" align="right" ><input type="submit" name="next_button" class="imagebutton" tabindex="<?php echo $tab+1?>" value="Next" onClick="needToConfirm = false;  check(); MM_showHideLayers('wait','','show');" /></td>
                </tr>
              </table></td>
          </tr>
  </table>
  </table>
</form>
</div>

<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
<?php
   $n=0;
   while ($n<4) { 
   $m=0;
   while ($m<$_SESSION['list_no_4a'.$n]) { 
   ?>
  frmvalidator.addValidation("qty_text<?php echo $n.$m ?>","req","Not all quantities for S5 timber were entered.");
  
  <?php
  $m++;
	  }
	  $n++;
  }
  ?>
</script>

<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
<?php
   $n=0;
   while ($n<3) { 
   $m=0;
   while ($m<$_SESSION['list_no_4b'.$n]) { 
   ?>
  frmvalidator.addValidation("qty_text2_<?php echo  $n.$m ?>","req","Not all quantities for S7 timber were entered.");
  <?php
  $m++;
	  }
	  $n++;
  }
  ?>
</script>


<?php 
$i=0;
while ($i<4) {
	$t=0;
	while ($t<$_SESSION['list_no_4a'.$i]) {
		?>
        <script>
   var textValue1 = document.getElementById('<?php echo "length".$i.$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text".$i.$t ?>').value;
   var textValue3 = (((textValue1 * textValue2) / 1000).toFixed(2));
   document.getElementById('<?php echo 'sub'.$i.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text'.$i.$t ?>').value = textValue3;
   calculateSum<?php echo $i?>();
   </script>
<?php
$t++;
	}
$i++;
}
?>

<?php 
$j=0;
while ($j<3) {
	$t=0;
	while ($t<$_SESSION['list_no_4b'.$j]) {
		?>
        <script>
   var textValue1 = document.getElementById('<?php echo "length2_".$j.$t ?>').value;
   var textValue2 = document.getElementById('<?php echo "qty_text2_".$j.$t ?>').value;
   var textValue3 = (((textValue1 * textValue2) / 1000).toFixed(2));
   document.getElementById('<?php echo 'sub2_'.$j.$t ?>').innerHTML = textValue3;
   document.getElementById('<?php echo 'text2_'.$j.$t ?>').value = textValue3;
   calculateSum2_<?php echo $j?>(); 
   </script>
<?php
$t++;
	}
$j++;
}
?>
   
  

</body>

