<head>
<?php
  
$table_name = $_SESSION['db_prefix']."_cutting_bill";
$cutting_query = "SELECT * FROM $table_name WHERE job_no = '".$_SESSION['job_no']."' ";
$cutting_result = mySQL_query($cutting_query);
$bill_id = mysql_result($cutting_result, 0, "bill_id");

$table_name = $_SESSION['db_prefix']."_cutting_bill_lines";
$truss_query = "SELECT * FROM $table_name WHERE type = 'Truss' AND bill_id = '".$bill_id."' ";
$truss_result = mySQL_query($truss_query);
$truss_num = mysql_num_rows($truss_result);

$table_name = $_SESSION['db_prefix']."_cutting_bill_lines";
$timber_query = "SELECT * FROM $table_name WHERE type = 'Timber' AND bill_id = '".$bill_id."' ";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);

$table_name = $_SESSION['db_prefix']."_cutting_bill_lines";
$plates_query = "SELECT * FROM $table_name WHERE type = 'Plate' AND bill_id = '".$bill_id."' ";
$plates_result = mySQL_query($plates_query);
$plates_num = mysql_num_rows($plates_result);
?>

<!--jscript-->
<script language="JavaScript" src="../jscript/go_to_URL.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
 
</head>
<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide'); document.getElementById('wizard_frame').focus();" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">

<div class="page_middle_frame">
<form action="cutJobWiz5.php?p=5&s=" method="POST" id='form1' name='form1'>
     <div class="wizard_frame" >
        <label class="label_std" style="font-size:18px">Timber</label>
           
           <table width="645" id="table_details_display">
             <tr>
               <th align="left" valign="top">Timber</th>
               <th align="left" valign="top">Number</th>
               <th align="left" valign="top">Supplied</th>
               <th align="left" valign="top">Balance</th>
               <th align="left" valign="top">Supply</th>
             </tr>
             <?php 
	
	$i=0;
	while ($i<$timber_num) {
		$a1 = mysql_result($timber_result, $i, "store_item_id");
		 	$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$a1."' ";
			$name_result = mySQL_query($name_query);
			$a1a = mysql_result($name_result, 0, "item_name");
		$a2 = mysql_result($timber_result, $i, "quantity");
		$table_name2 = $_SESSION['db_prefix']."_cutting_supplies_lines";
			$supplied_query = "SELECT SUM(quantity) AS summed_quantity FROM $table_name2 WHERE store_item_id = '".$a1."' AND job_no = '".$_SESSION['job_no']."'  ";
			$supplied_result = mySQL_query($supplied_query);
			$a4 = mysql_result($supplied_result, 0, "summed_quantity");
			if ($a4=='') {$a4=0;}
			$a5 = $a2-$a4;
		
	?>
             <tr>
               <td align="left" valign="middle" width="159"><?php echo $a1a ?></td>
               <td align="left" valign="middle" width="96"><?php echo $a2 ?></td>
               <td align="left" valign="middle" width="96"><?php echo $a4 ?></td>
               <td align="left" valign="middle" width="121"><?php echo $a5 ?></td>
               <td align="left" valign="middle" width="180"><?php echo $_SESSION['timber_no'.$i] ?> </td>
             </tr>
             <?php
	$i++;
	}
	$_SESSION['line_no3'] = $i;
	?>
           </table>
           <p>
             <label class="label_std" style="font-size:18px">Plates</label>
           </p>
           <table width="645" id="table_details_display">
             <tr>
               <th align="left" valign="top">Plate</th>
               <th align="left" valign="top">Number</th>
               <th align="left" valign="top">Supplied</th>
               <th align="left" valign="top">Balance</th>
               <th align="left" valign="top">Supply</th>
             </tr>
             <?php 
	
	$i=0;
	while ($i<$plates_num) {
		$a1 = mysql_result($plates_result, $i, "store_item_id");
		  	$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$a1."' ";
			$name_result = mySQL_query($name_query);
			$a1a = mysql_result($name_result, 0, "item_name");
		$a2 = mysql_result($plates_result, $i, "quantity");
		$table_name2 = $_SESSION['db_prefix']."_cutting_supplies_lines";
			$supplied_query = "SELECT SUM(quantity) AS summed_quantity FROM $table_name2 WHERE store_item_id = '".$a1."' AND job_no = '".$_SESSION['job_no']."'  ";
			$supplied_result = mySQL_query($supplied_query);
			$a4 = mysql_result($supplied_result, 0, "summed_quantity");
			if ($a4=='') {$a4=0;}
			$a5 = $a2-$a4;
		
	?>
             <tr>
               <td align="left" valign="middle" width="159"><?php echo $a1a ?></td>
               <td align="left" valign="middle" width="96"><?php echo $a2 ?></td>
               <td align="left" valign="middle" width="96"><?php echo $a4 ?></td>
               <td align="left" valign="middle" width="121"><?php echo $a5 ?></td>
               <td align="left" valign="middle" width="180"><?php echo $_SESSION['plates_no'.$i] ?>
               </td>
             </tr>
             <?php
	$i++;
	}
	$_SESSION['line_no5'] = $i;
	?>
           </table>
           </div>
           <div class="button_bar_frame">
           <table width="590" height="50" align="left" 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','cutJobWizbase.php?s=&amp;p=3&all2=none');return document.MM_returnValue" tabindex="-1" /></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="4" />
            <input name="s" type="hidden" id="s" value="4" />
            <input name="all2" type="hidden" id="all2" value="none" /></td>
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../store/store_main.php');" value="Cancel" tabindex="-1" /></td>
          <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
        </tr>
      </table>
      </div>
</form>
</div>
<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("last_group","selone","Please select if this is the last supply.");
</script>


</body>      