<head>
<?php

$table_name = $_SESSION['db_prefix']."_cash_job_lines";
$timber_query = "SELECT store_item_id, quantity FROM $table_name WHERE quote_no = '".$_SESSION['job_no']."' AND truss_item = 'Timber'";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);

$table_name = $_SESSION['db_prefix']."_cash_job_lines";
$mitek_query = "SELECT store_item_id, quantity FROM $table_name WHERE quote_no = '".$_SESSION['job_no']."' AND truss_item = 'Mitek' ";
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);

$table_name = $_SESSION['db_prefix']."_cash_job_lines";
$sundries_query = "SELECT store_item_id, quantity FROM $table_name WHERE quote_no = '".$_SESSION['job_no']."' AND truss_item = 'Sundries' ";
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);
?>
<!--style sheets-->


<script type="text/javascript">
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>
<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide');" onFocus="MM_showHideLayers('wait','','hide')";>
<div class="page_middle_frame">
<form action="cash_authorisationWiz6.php" method="get" name="form1" id="form1">
<table id="tableMain" width="595">
    <!--begin of tableMain-->
    <tr>
      <td><!--center of tableMain-->

        <div class="wizard_frame">
         Timber
          <table width="599"  id="table_display">
               <tr>
                 <td width="322">&nbsp;</td>
                 <td colspan="2" align="center">On order</td>
                 <td colspan="2" align="center">To authorise</td>
               </tr>
             <?php 
				  $i=0;
				  while ($i<$timber_num) { 
				       
						$store_item_id = mysql_result($timber_result, $i, "store_item_id");					
						$quantity = mysql_result($timber_result, $i, "quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						
						$table_name = $_SESSION['db_prefix']."_cash_authorisation_lines_temp";
						$quantity_query = "SELECT quantity FROM $table_name WHERE store_item_id = '".$store_item_id."' AND user_name = '".$_SESSION['username']."'  ";
						$quantity_result = mySQL_query($quantity_query);
						$quantity_num = mysql_num_rows($quantity_result);
						if ($quantity_num!='') {
						       $auth_quantity = mysql_result($quantity_result, 0, "quantity");
						}
						else {
							$auth_quantity = '0';
						}
								
				 ?>
             <tr>
               <td><?php echo $item_name ?></td>
               <td width="76" align="right"><input name="quantity<?php echo $i?>" id="quantity<?php echo $i?>" type="hidden" value="<?php echo number_format($quantity, 0, '.', '')?>"><?php echo number_format($quantity, 0, '.', '')?>&nbsp;&nbsp;</td>
               <td width="46">&nbsp;&nbsp;<?php echo $unit ?></td>
               <td width="86" align="right"><?php echo number_format($auth_quantity, 0, '.', '') ?>
  &nbsp;&nbsp;</td>
               <td width="45"><?php echo $unit ?></td>
             </tr>
             <?php
			  $i++;
             }
             ?>
           </table>
          <?php if ($timber_num==0) { ?>
          <img src="../images/exclamation.png" width="24" height="24">There is no timber on this order.<?php } ?>
          </div>
          <div class="wizard_frame">
         Eco products
          <table width="599"  id="table_display">
               <tr>
                 <td width="322">&nbsp;</td>
                 <td colspan="2" align="center">On order</td>
                 <td colspan="2" align="center">To authorise</td>
               </tr>
             <?php 
				  $i=0;
				  while ($i<$mitek_num) { 
				       
						$store_item_id = mysql_result($mitek_result, $i, "store_item_id");					
						$quantity = mysql_result($mitek_result, $i, "quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						
						$table_name = $_SESSION['db_prefix']."_cash_authorisation_lines_temp";
						$quantity_query = "SELECT quantity FROM $table_name WHERE store_item_id = '".$store_item_id."' AND user_name = '".$_SESSION['username']."'  ";
						$quantity_result = mySQL_query($quantity_query);
						$quantity_num = mysql_num_rows($quantity_result);
						if ($quantity_num!='') {
						       $auth_quantity = mysql_result($quantity_result, 0, "quantity");
						}
						else {
							$auth_quantity = '0';
						}
								
				 ?>
             <tr>
               <td><?php echo $item_name ?></td>
               <td width="76" align="right"><input name="quantity<?php echo $i?>" id="quantity<?php echo $i?>" type="hidden" value="<?php echo number_format($quantity, 0, '.', '')?>"><?php echo number_format($quantity, 0, '.', '')?>&nbsp;&nbsp;</td>
               <td width="46">&nbsp;&nbsp;<?php echo $unit ?></td>
               <td width="86" align="right"><?php echo number_format($auth_quantity, 0, '.', '') ?>
  &nbsp;&nbsp;</td>
               <td width="45"><?php echo $unit ?></td>
             </tr>
             <?php
			  $i++;
             }
             ?>
           </table>
          <?php if ($mitek_num==0) { ?>
          <img src="../images/exclamation.png" width="24" height="24">There are no eco products on this order.<?php } ?>
          </div>
          <div class="wizard_frame">
         Sundries
          <table width="599"  id="table_display">
               <tr>
                 <td width="322">&nbsp;</td>
                 <td colspan="2" align="center">On order</td>
                 <td colspan="2" align="center">To authorise</td>
               </tr>
             <?php 
				  $i=0;
				  while ($i<$sundries_num) { 
				       
						$store_item_id = mysql_result($sundries_result, $i, "store_item_id");					
						$quantity = mysql_result($sundries_result, $i, "quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						
						$table_name = $_SESSION['db_prefix']."_cash_authorisation_lines_temp";
						$quantity_query = "SELECT quantity FROM $table_name WHERE store_item_id = '".$store_item_id."' AND user_name = '".$_SESSION['username']."'  ";
						$quantity_result = mySQL_query($quantity_query);
						$quantity_num = mysql_num_rows($quantity_result);
						if ($quantity_num!='') {
						       $auth_quantity = mysql_result($quantity_result, 0, "quantity");
						}
						else {
							$auth_quantity = '0';
						}
								
				 ?>
             <tr>
               <td><?php echo $item_name ?></td>
               <td width="76" align="right"><input name="quantity<?php echo $i?>" id="quantity<?php echo $i?>" type="hidden" value="<?php echo number_format($quantity, 0, '.', '')?>"><?php echo number_format($quantity, 0, '.', '')?>&nbsp;&nbsp;</td>
               <td width="46">&nbsp;&nbsp;<?php echo $unit ?></td>
               <td width="86" align="right"><?php echo number_format($auth_quantity, 0, '.', '') ?>
  &nbsp;&nbsp;</td>
               <td width="45"><?php echo $unit ?></td>
             </tr>
             <?php
			  $i++;
             }
             ?>
           </table>
          <?php if ($mitek_num==0) { ?>
          <img src="../images/exclamation.png" width="24" height="24">There are no sundries on this order.<?php } ?>
          </div>
      </td>
      </tr>
      <tr>
      <td><table width="590" 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','cash_authorisationWizbase.php?s=&amp;p=4');return document.MM_returnValue"  tabindex="<?php echo $i+3 ?>"/></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="5" />
            <input name="s" type="hidden" id="s" value="5" />
            </span></td>
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../sales/sales_main.php');" value="Cancel" tabindex="<?php echo $i+4 ?>" /></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>      