<head>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<?php

$job_no = $_SESSION['job_no'];
$quote='no';
$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_no = '".$job_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");	
$job_value = mysql_result($job_result, 0, "value");

$table_name = $_SESSION['db_prefix']."_store_items";
$mitek_query = "SELECT store_item_id, item_name FROM $table_name WHERE subCategory='Mitek' AND class='' ORDER BY item_name";
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);

$table_name = $_SESSION['db_prefix']."_list_bracing";
$bracing_query = "SELECT * FROM $table_name ORDER BY item_name  ";
$bracing_result = mySQL_query($bracing_query);
$bracing_num = mysql_num_rows($bracing_result);

$table_name = $_SESSION['db_prefix']."_list_sundries";
$sundries_query = "SELECT * FROM $table_name ORDER BY item_name  ";
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);

$table_name = $_SESSION['db_prefix']."_store_items";
$laminated_query = "SELECT store_item_id, item_name, width, depth, class, price FROM $table_name WHERE class = 'La' ORDER BY item_name  ";
$laminated_result = mySQL_query($laminated_query);
$laminated_num = mysql_num_rows($laminated_result);

$table_name = $_SESSION['db_prefix']."_store_items";
$additional_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory='Sundries' AND class='' ORDER BY item_name";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_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="wizard_page_middle_frame" style="width:700px;">
<form id="feedbackform" method="post" action="captureJobWiz8.php" >
<div class="wizard_frame">
<?php 
        $in_del_date = $_SESSION['deliver_date'];
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/job_block.php')
		?>
</div>
  
<div class="wizard_frame">
  <table width="646" id="table_details_display" > 
              <tr>
                <td width="97" align="left" valign="top"><label class="label_std">Class 5 timber: </label></td>
                <td width="75" align="left" valign="top"><?php echo $_SESSION['length_tot_1'] ?>&nbsp;
<label class="label_std">m</label></td>
                <td colspan="2" align="left" valign="top"><table width="338" border="0" style="border-collapse:collapse;">
                <?php 
				$total_timber = '0';
				$total_meter_price = '0';
                $i=0;
				while ($i<$_SESSION['list_1']) {
					
				$table_name = $_SESSION['db_prefix']."_timber_meter_price";
				$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$_SESSION['type_'.$i]."' ";
				$meter_price_result = mySQL_query($meter_price_query);
				$meter_price_num = mysql_num_rows($meter_price_result);
						
						if ($meter_price_num>0) {
						$meter_price = mysql_result($meter_price_result, 0, "price");
						}
						else {
							$meter_price=0;
						}
				
				$total_meter_price = $meter_price * $_SESSION['length_'.$i];
				$total_timber = $total_timber + $total_meter_price;
				?>
                <tr>
                    <td width="115"><?php echo $_SESSION['type_'.$i] ?>&nbsp;</td>
                    <td width="86" align="right"><?php echo $_SESSION['length_'.$i] ?>&nbsp;m&nbsp;</td>
                    <td width="46" align="right"><?php echo number_format($meter_price, 2, '.', ',') ?></td>
                    <td width="73" align="right"><?php echo number_format($total_meter_price, 2, '.', ',') ?></td>
                 </tr>
                  <?php
				  $i++;
				}
				  ?>
                </table>
                </td>
              </tr>
              
              <tr>
                <td align="left" valign="top"><label class="label_std">Class 7 timber:</label></td>
                <td align="left" valign="top"><?php echo $_SESSION['length_tot_2'] ?>&nbsp;
<label class="label_std">m</label></td>
                <td colspan="2" align="left" valign="top"><table width="338" border="0" style="border-collapse:collapse;">
                  <?php 
                $i=0;
				$total_meter_price='0';
				while ($i<$_SESSION['list_2']) {
				
				$table_name = $_SESSION['db_prefix']."_timber_meter_price";
				$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$_SESSION['type2_'.$i]."' ";
				$meter_price_result = mySQL_query($meter_price_query);
				$meter_price = mysql_result($meter_price_result, 0, "price");	
				$total_meter_price = $meter_price * $_SESSION['length2_'.$i];
				$total_timber = $total_timber + $total_meter_price;	
				?>
                  <tr>
                    <td width="115"><?php echo $_SESSION['type2_'.$i] ?>&nbsp;</td>
                    <td width="86" align="right"><?php echo $_SESSION['length2_'.$i] ?>&nbsp;m&nbsp;</td>
                    <td width="46" align="right"><?php echo number_format($meter_price, 2, '.', ',') ?></td>
                    <td width="73" align="right"><?php echo number_format($total_meter_price, 2, '.', ',') ?></td>
                  </tr>
                  <?php
				  $i++;
				}
				  ?>
                </table></td> 
        </tr>
              <tr>
                <td align="left" valign="top">&nbsp;</td>
                <td align="left" valign="top">&nbsp;</td>
                <td width="300" align="left" valign="top">&nbsp;</td>
                <td width="78" align="right" valign="top"><?php echo number_format($total_timber, 2, '.', ',') ?></td>
              </tr>
              
      </table>
  </div><br>
<br>

  <div class="wizard_frame">
<?php
$table_name = $_SESSION['db_prefix']."_presets";
$plate_area_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'Plate area' ";
$plate_area_result = mySQL_query($plate_area_query);
$plate_area_charge = mysql_result($plate_area_result, 0, "preset_value");

$table_name = $_SESSION['db_prefix']."_presets";
$press_point_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'Press points' ";
$press_point_result = mySQL_query($press_point_query);
$press_point_charge = mysql_result($press_point_result, 0, "preset_value");
?>
 <table width="646"  id="table_details_display" > 
              <tr>
                <td width="256" align="left" valign="middle"><label class="label_std">Estimated plate area:</label></td>
                <td width="206" align="left" valign="middle"><?php echo $_SESSION['plate_area'] ?>&nbsp;<label class="label_std">m<sup>2</sup></label></td>
                <td width="76" align="right" valign="middle"><?php echo number_format($plate_area_charge, 2, '.', ',') ?></td>
                <td width="88" align="right" valign="middle"><?php $plate_area_total = $_SESSION['plate_area'] * $plate_area_charge; echo number_format($plate_area_total, 2, '.', ','); ?> </td>
              </tr>
              <tr>
                <td align="left" valign="middle"><label class="label_std">Estimated FT:</label></td>
                <td align="left" valign="middle"><?php echo $_SESSION['press_points'] ?></td>
                <td align="right" valign="middle"><?php echo number_format($press_point_charge, 2, '.', ',') ?></td>
                <td align="right" valign="middle"><?php $press_points_total = $_SESSION['press_points'] * $press_point_charge; echo number_format($press_points_total, 2, '.', ','); ?></td>
              </tr>
              </table>
  </div>
  <div class="wizard_frame">
 <table width="646" id="table_details_display" > 
              <tr>
                <td colspan="5" align="left" valign="top"><label class="label_std">Mitek products:</label></td>
              </tr>
               <?php
			   	  $mitek_total='0';	 
				  $i=0;
				  $_SESSION['list_3'] = $mitek_num;
				  while ($i<$mitek_num) { 
					    $_SESSION['item_id'.$i] = mysql_result($mitek_result, $i, "store_item_id");
						$item_name = mysql_result($mitek_result, $i, "item_name");
						
						$table_name = $_SESSION['db_prefix']."_store_items";
						$price_query = "SELECT price FROM $table_name WHERE store_item_id = '".$_SESSION['item_id'.$i]."' ";
						$price_result = mySQL_query($price_query);
						$price = mysql_result($price_result, 0, "price");
						
						$total_price = $_SESSION['quantity_'.$i] * $price;
						$mitek_total = $mitek_total + $total_price;
						  
						if ($_SESSION['quantity_'.$i]!='') {
							
						$table_name = $_SESSION['db_prefix']."_store_items";
						$price_query = "SELECT price FROM $table_name WHERE store_item_id = '".$_SESSION['item_id'.$i]."' ";
						$price_result = mySQL_query($price_query);
						$price = mysql_result($price_result, 0, "price");
						
						$total_price = $_SESSION['quantity_'.$i] * $price;			
				 ?>
             <tr>
               <td width="304"><?php echo $item_name ?>
                 <input type="hidden" name="item_id_<?php echo $i?>" id="item_id_<?php echo $i?>" value="<?php echo $_SESSION['item_id'.$i] ?>">
               </td>
               <td width="68"><?php echo $_SESSION['quantity_'.$i] ?></td>
               <td width="86" align="right"><?php  echo number_format($price, 2, '.', ',') ?></td>
               <td width="76" align="right"><?php  echo number_format($total_price, 2, '.', ',') ?></td>
               <td width="88" align="right">&nbsp;</td>
             </tr>
             <?php
						}
			  $i++;
             }
             ?>
             <tfoot>
             <tr>
               <td colspan="4">&nbsp;</td>
               <td align="right"><?php echo number_format($mitek_total, 2, '.', ',') ?></td>
             </tr>
             </tfoot>
             </table></div>
  <div class="wizard_frame">
 <table width="646" id="table_details_display" > 
             <tr>
               <td colspan="5"><label class="label_std">Bracing</label></td>
             </tr>
            
             <?php 
			 $bracing_total='0';
			 $j=0;
			 $_SESSION['list_5a'] = $bracing_num;
			 while ($j<$_SESSION['list_5a']) {
				 $bracing_name = mysql_result($bracing_result, $j, "item_name");
				 $bracing_depth = mysql_result($bracing_result, $j, "depth");
				 $bracing_width = mysql_result($bracing_result, $j, "width");
				 $bracing_class = mysql_result($bracing_result, $j, "class");
				 
				 if ($_SESSION['bracing_qty_'.$j]!='') {
					 	$type = $bracing_depth.'x'.$bracing_width.' ('.$bracing_class.')';
						$table_name = $_SESSION['db_prefix']."_timber_meter_price";
						$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$type."' ";
						$meter_price_result = mySQL_query($meter_price_query);
						$meter_price = mysql_result($meter_price_result, 0, "price");	
						$total_meter_price = $meter_price * $_SESSION['bracing_qty_'.$j];
						$bracing_total = $bracing_total + $total_meter_price;
			 ?>
             <tr>
               <td width="292"><?php echo $bracing_name ?>
               <input type="hidden" name="bracing_name.<?php echo $j ?>" id="bracing_name.<?php echo $j ?>" value="<?php echo $bracing_name ?>">
               <input type="hidden" name="bracing_depth.<?php echo $j ?>" id="bracing_depth.<?php echo $j ?>" value="<?php echo $bracing_depth ?>">
               <input type="hidden" name="bracing_width.<?php echo $j ?>" id="bracing_width.<?php echo $j ?>" value="<?php echo $bracing_width ?>">
               <input type="hidden" name="bracing_class.<?php echo $j ?>" id="bracing_class.<?php echo $j ?>" value="<?php echo $bracing_class ?>">
               <label for="textfield"></label></td>
               <td width="80"><?php echo $_SESSION['bracing_qty_'.$j]?>
               m </td>
               <td width="86" align="right"><?php  echo number_format($meter_price, 2, '.', ',') ?></td>
               <td width="76" align="right"><?php  echo number_format($total_meter_price, 2, '.', ',') ?></td>
               <td width="88" align="right">&nbsp;</td>
             </tr>
             <?php
				 }
			 $j++;
			 }
			 ?>
             <tfoot>
             <tr>
               <td colspan="4">&nbsp;</td>
               <td align="right"><?php echo number_format($bracing_total, 2, '.', ',') ?></td>
             </tr>
             </tfoot>
      </table></div>
  <div class="wizard_frame">
   <table width="646" id="table_details_display" > 
             <tr>
               <td colspan="5"><label class="label_std">Sundry Timbers</label></td>
             </tr>
             <?php 
			 $sundries_total='0';
			 $k=0;
			 $_SESSION['list_5b'] = $sundries_num;
			 while ($k<$sundries_num) {
				 $sundries_name = mysql_result($sundries_result, $k, "item_name");
				 $sundries_depth = mysql_result($sundries_result, $k, "depth");
				 $sundries_width = mysql_result($sundries_result, $k, "width");
				 $sundries_class = mysql_result($sundries_result, $k, "class");
				 
			     if ($_SESSION['sundries_qty_'.$k]!='') {
					 
					 	$type = $sundries_depth.'x'.$sundries_width.' ('.$sundries_class.')';
						$table_name = $_SESSION['db_prefix']."_timber_meter_price";
						$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$type."' ";
						$meter_price_result = mySQL_query($meter_price_query);
						$meter_price_num = mysql_num_rows($meter_price_result);
						
						if ($meter_price_num>0) {
						$meter_price = mysql_result($meter_price_result, 0, "price");
						}
						else {
							$meter_price=0;
						}
						$total_meter_price = $meter_price * $_SESSION['sundries_qty_'.$k];
					 	$sundries_total = $sundries_total + $total_meter_price;
			 ?>
               <tr>
               <td width="292"><?php echo $sundries_name ?>
               <input type="hidden" name="sundries_name.<?php echo $k ?>" id="sundries_name.<?php echo $k ?>" value="<?php echo $sundries_name ?>">
               <input type="hidden" name="sundries_depth.<?php echo $k ?>" id="sundries_depth.<?php echo $k ?>" value="<?php echo $sundries_depth ?>">
               <input type="hidden" name="sundries_width.<?php echo $k ?>" id="sundries_width.<?php echo $k ?>" value="<?php echo $sundries_width ?>">
               <input type="hidden" name="sundries_class.<?php echo $k ?>" id="sundries_class.<?php echo $k ?>" value="<?php echo $sundries_class ?>"></td>
               <td width="80"><?php echo $_SESSION['sundries_qty_'.$k]?>
               m </td>
               <td width="86" align="right"><?php  echo number_format($meter_price, 2, '.', ',') ?></td>
               <td width="76" align="right"><?php  echo number_format($total_meter_price, 2, '.', ',') ?></td>
               <td width="88" align="right">&nbsp;</td>
             </tr>
             <?php
				  }
			 $k++;
			 }
			 ?>
             <tfoot>
               <tr>
                 <td>&nbsp;</td>
                 <td>&nbsp;</td>
                 <td colspan="2" align="right">&nbsp;</td>
                 <td align="right"><?php echo number_format($sundries_total, 2, '.', ',') ?></td>
               </tr>
             </tfoot>
             </table></div>
             <div class="wizard_frame">
   <table width="646" id="table_details_display" > 
             <tr>
               <td colspan="5"><label class="label_std">Laminated beams</label></td>
             </tr>
             <?php 
			 $laminated_total='0';
			 $p=0;
			 $_SESSION['list_5c'] = $laminated_num;
			 while ($p<$laminated_num) {
				 $laminated_name = mysql_result($laminated_result, $p, "item_name");
				 $laminated_depth = mysql_result($laminated_result, $p, "depth");
				 $laminated_width = mysql_result($laminated_result, $p, "width");
				 $laminated_class = mysql_result($laminated_result, $p, "class");
				 $laminated_price = mysql_result($laminated_result, $p, "price");
				 $laminated_name = 'Laminated '.$laminated_depth.'x'.$laminated_width.'('.$laminated_class.')';
				 $_SESSION['laminated_meter_price_'.$p] = $laminated_price;
				 
				 
			     if ($_SESSION['laminated_qty_'.$p]!='') {
				 
						$total_meter_price = $laminated_price * $_SESSION['laminated_qty_'.$p];
					 	$laminated_total = $laminated_total + $total_meter_price;
			 ?>
               <tr>
               <td width="292"><?php echo $laminated_name ?>
               <input type="hidden" name="laminated_name.<?php echo $p ?>" id="laminated_name.<?php echo $p ?>" value="<?php echo $laminated_name ?>">
               <input type="hidden" name="laminated_depth.<?php echo $p ?>" id="laminated_depth.<?php echo $p ?>" value="<?php echo $laminated_depth ?>">
               <input type="hidden" name="laminated_width.<?php echo $p ?>" id="laminated_width.<?php echo $p ?>" value="<?php echo $laminated_width ?>">
               <input type="hidden" name="laminated_class.<?php echo $p ?>" id="laminated_class.<?php echo $p ?>" value="<?php echo $laminated_class ?>"></td>
               <td width="80"><?php echo $_SESSION['laminated_qty_'.$p]?>
               m </td>
               <td width="86" align="right"><?php  echo number_format($laminated_price, 2, '.', ',') ?></td>
               <td width="76" align="right"><?php  echo number_format($total_meter_price, 2, '.', ',') ?></td>
               <td width="88" align="right">&nbsp;</td>
             </tr>
             <?php
				  }
			 $p++;
			 }
			 ?>
             <tfoot>
               <tr>
                 <td>&nbsp;</td>
                 <td>&nbsp;</td>
                 <td colspan="2" align="right">&nbsp;</td>
                 <td align="right"><?php echo number_format($laminated_total, 2, '.', ',') ?></td>
               </tr>
             </tfoot>
             </table></div>
  <div class="wizard_frame">
 <table width="646" id="table_details_display" > 
             <tr>
               <td colspan="5"><label class="label_std">Additional Sundries</label></td>
             </tr>
             <?php
			 	  $add_sundries_total='0';	 
				  $m=0;
				  $_SESSION['list_6'] = $additional_num;
				  while ($m<$additional_num) { 
					    $_SESSION['additional_item_id'.$m] = mysql_result($additional_result, $m, "store_item_id");
						$item_name = mysql_result($additional_result, $m, "item_name");  
						if ($_SESSION['additional_quantity_'.$m]!='') {
						
						$table_name = $_SESSION['db_prefix']."_store_items";
						$price_query = "SELECT price FROM $table_name WHERE store_item_id = '".$_SESSION['additional_item_id'.$m]."' ";
						$price_result = mySQL_query($price_query);
						$price = mysql_result($price_result, 0, "price");
						
						$total_price = $_SESSION['additional_quantity_'.$m] * $price;
						$add_sundries_total = $add_sundries_total + $total_price;				
				 ?>
             <tr>
               <td width="295"><?php echo $item_name ?>
                 <input type="hidden" name="additional_item_id_<?php echo $m?>" id="additional_item_id_<?php echo $m?>" value="<?php echo $_SESSION['additional_item_id'.$m] ?>">
               </td>
               <td width="77"><?php echo $_SESSION['additional_quantity_'.$m] ?></td>
               <td width="86" align="right"><?php  echo number_format($price, 2, '.', ',') ?></td>
               <td width="84" align="right"><?php  echo number_format($total_price, 2, '.', ',') ?></td>
               <td width="80" align="right">&nbsp;</td>
             </tr>
             <?php
						}
			  $m++;
             }
             ?>
             <tfoot>
             <tr>
               <td colspan="4">&nbsp;</td>
               <td align="right"><?php echo number_format($add_sundries_total, 2, '.', ',') ?></td>
             </tr>
            </table>
  </div>
<div class="wizard_frame">
 <table width="646" id="table_details_display" > 
  <tr>
    <td width="556"><?php $captured_total=$total_timber+$plate_area_total+$press_points_total+$mitek_total+$bracing_total+$sundries_total+$laminated_total+$add_sundries_total ?> 
    Job value: <?php echo number_format($job_value, 2, '.', ',') ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    Result:&nbsp;&nbsp;<?php $result = (($job_value-$captured_total)/$job_value)*100; echo number_format($result, 2, '.', ','); ?>% 
    <input type="hidden" name="result_text" id="result_text" value="<?php echo $result ?>">
    <?php if ($result<10) { ?> <script>alertMessage(1, '', 'The result on this job is less than 10%. Check used quantities again.');</script>
    <?php } ?> <input type="hidden" name="job_value_text" id="job_value_text" value="<?php echo $job_value ?>">
    <input type="hidden" name="captured_value_text" id="captured_value_text" value="<?php echo $captured_total?>"></td>
    <td width="78" align="right"><?php echo number_format($captured_total, 2, '.', ','); ?></td>
  </tr>
</table>
 
</div>  
    <br />
<br />

  <div class="wizard_frame">
              <label class="label_std">If you want to make changes use the 'Prev' button to go back. <br />
              To finish the wizard click 'Finish'.</label>
           </div>
       
              <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','captureJobWizbase.php?s=&p=6');return document.MM_returnValue" /></td>
                  <td width="115">
                    <input name="s" type="hidden" id="s" value="7" />
                    <input name="p" type="hidden" id="p" value="7" />
                  </td>
                  <td width="99">&nbsp;</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>
 
  
</form>
</div>

</body>