<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."' ORDER BY truss_type";
$truss_result = mySQL_query($truss_query);
$truss_num = mysql_num_rows($truss_result);
?>

</head>

<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">

<div class="page_middle_frame">
<form action="produceWiz4.php?p=4&s=3" method="POST" name="form1" id="form1">
<table id="tableMain" width="595">
    <!--begin of tableMain-->
    <tr>
      <td><!--center of tableMain--><br>
<div class="wizard_frame">
  <label class="label_std">Production date: <?php echo date("l, d-m-Y", strtotime($_SESSION['production_date'] )) ?> </label>
</div><br>
<br>

        <div class="wizard_frame">
          <table width="645" id="table_details_display">
            <tr>
              <th align="center" valign="top">Truss</th>
              <th align="center" valign="top">FT</th>
              <th align="center" valign="top">Number</th>
              <th align="center" valign="top">Produced</th>
              <th align="center" valign="top">Balance</th>
              <th align="center" valign="top">To Produce</th>
              <th align="center" valign="top">Production FT</th>
            </tr>
            <?php 
	
	$i=0;
	$a8tot=0;
	while ($i<$truss_num) {
		$a1 = mysql_result($truss_result, $i, "truss_type");
		$a2 = mysql_result($truss_result, $i, "quantity");
		
		$a4 = mysql_result($truss_result, $i, "produced");
		$table_name2 = $_SESSION['db_prefix']."_production_bill_lines";
			$supplied_query = "SELECT SUM(quantity) AS summed_quantity FROM $table_name2 WHERE truss_type = '".$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;
		$a7 = mysql_result($truss_result, $i, "press_points");
		$a8 = $_SESSION['truss_no'.$i]* $a7;
		$a8tot = $a8tot+$a8;
	?>
            <tr>
              <td align="left" valign="middle" width="89"><?php echo $a1 ?></td>
              <td align="left" valign="middle" width="101"><?php echo $a7 ?></td>
              <td align="left" valign="middle" width="131"><?php echo $a2 ?></td>
              <td align="left" valign="middle" width="116"><?php echo $a4 ?></td>
              <td align="left" valign="middle" width="101"><?php echo $a5 ?></td>
              <td align="left" valign="middle" width="105"><?php echo $_SESSION['truss_no'.$i] ?></td>
              <td align="right" valign="middle" width="105"><?php echo $a8 ?></td>
            </tr>
            <?php
	$i++;
	}
	$_SESSION['line_no2'] = $i;
	?>
    <tfoot>
    <tr>
              <td colspan="6" align="right" valign="middle">Totoal production FT:</td>
              <td align="right" valign="middle"><?php echo $a8tot ?></td>
            </tr>
            </tfoot>
          </table>
          <br>
      </div></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
         </tr>
      <tr>
      <td><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','produceWizbase.php?s=&p=2&all=none');return document.MM_returnValue" /></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="3" />
            <input name="s" type="hidden" id="s" value="3" />
           <input name="all" type="hidden" id="all" value="none" />
           </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" /></td>
          <td width="110" align="right"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
        </tr>
      </table>


</td>
</tr>
</table>
</form>
</div>
</body>      