<head>

<?php
   
$all = $_GET['all'];
$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";
$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);


?>
<!--jscript-->
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>  
<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>  
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>	
<script type="text/javascript">
function validate_required(input,alerttxt,maxvalue)
{
with (input)
  {
  if (value>maxvalue)
    {
     alertMessage(1, 'cutJobWizbase.php?p=2&s=', 'The delivery quantity exceeds the balance, the entry will be cleared.<br><br>Please enter a valid quantity.');
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}

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

<body onLoad="MM_showHideLayers('wait','','hide'); <?php if ($_SESSION['error2']=='yes') {?> alertMessage(2, 'cutJobWizbase.php?p=2&s=', 'The quantity in the orange coloured boxes exceeded the maximum available stock quantity.<br><br>The quantity is now replaced by the maximum available stock quantity.');<?php } ?>   " onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<?php $_SESSION['error2']='no'?> 
<div class="page_middle_frame"> 
<form id="form1" method="POST" action="cutJobWizbase.php?p=3&s=2&all2=">
      <div class="wizard_frame" align="right"><input name="button" type="button" class="imagebutton" id="button"  onClick="needToConfirm = false;MM_showHideLayers('wait','','show');  window.location='cutJobWizbase.php?p=2&amp;s=0&amp;all=all'" value="Supply all" checked="checked" <?php if ($all=='all') { ?> <?php } ?>>
</div>
            <br>

            <div class="wizard_frame">
              <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;
			
			if ($_SESSION['timber_no'.$i]<0) {$_SESSION['timber_no'.$i]=0;}
		
	?>
                <tr>
                  <td align="left" valign="middle" width="162"><?php echo $a1a ?>===<?php echo $i ?></td>
                  <td align="left" valign="middle" width="99"><?php echo $a2 ?></td>
                  <td align="left" valign="middle" width="99"><?php echo $a4 ?></td>
                  <td align="left" valign="middle" width="132"><?php echo $a5 ?></td>
                  <td align="left" valign="middle">
                  
                  
                  
                  <input name="timber_no_text<?php echo $i ?>" type="text" class="text60" id="timber_no_text<?php echo $i ?>"  <?php if ($_SESSION['timber_error'.$i]=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['timber_error'.$i]='no' ?>
 onkeypress="return numbersonly(this, event)" onKeyUp="validate_required(timber_no_text<?php echo $i?>, '', <?php echo $a5 ?>)" value="<?php if ($all=='all') {echo number_format($a5, 0, '.', ',');} else { echo number_format($_SESSION['timber_no'.$i], 0, '.', ','); } ?>" onfocus = "this.select();" autocomplete="off" autofocus tabindex="<?php echo $i+1?>">
                    <input name="timber_id<?php echo $i ?>" id="timber_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>" ></td>
                </tr>
                <?php
	$i++;
	}
	$_SESSION['line_no3'] = $i;
	?>
              </table>
              <br>
               </div>
            <br>
<br>

              <br />
<br>
<br>
<div class="button_bar_frame">
              <table width="660" height="50" align="left" cellpadding="20"  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=&p=1');return document.MM_returnValue" /></td>
                  <td width="115">&nbsp;</td>
                  <td width="99">
                    <input name="p" type="hidden" id="p" value="2" />
                    <input name="s" type="hidden" id="s" value="2" />
                  </span>
                  <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" /></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" tabindex="<?php echo $i+2?>"/></td>
                </tr>
            </table>
            </div>
</form>
</div>
	
    </body>