<head>
<script language="javascript" src="../jscript/calendar.js"></script>

<?php
$all2 = $_GET['all2'];
$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";
$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/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=3&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['error3']=='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['error3']='no'?>  
<div class="page_middle_frame">   
<form id="form1" method="POST" action="cutJobWizbase.php?p=4&s=3">
<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=3&amp;s=0&amp;all2=all'" value="Supply all" checked="checked" <?php if ($all2=='all') { ?> <?php } ?>>
</div>               
            <br>
            <div class="wizard_frame">
              <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 width="61" align="left" valign="top">Supply</th>
                  <th width="99" align="right" valign="top">&nbsp;</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="110"><?php echo $a1a ?></td>
                  <td align="left" valign="middle" width="111"><?php echo $a2 ?></td>
                  <td align="left" valign="middle" width="121"><?php echo $a4 ?></td>
                  <td align="left" valign="middle" width="146"><?php echo $a5 ?></td>
                  <td colspan="2" align="left" valign="middle"><input name="plates_no_text<?php echo $i ?>" type="text" onKeyPress="return numbersonly(this, event)" class="text60" id="plates_no_text<?php echo $i ?>" value="<?php if ($all2=='all') {echo number_format($a5, 0, '.', '');} else { echo number_format($_SESSION['plates_no'.$i], 0, '.', '');} ?>" onKeyUp="validate_required(plates_no_text<?php echo $i?>, '', <?php echo $a5 ?>)" autocomplete="off" autofocus tabindex="<?php echo $i+1?>"  <?php if ($_SESSION['plates_error'.$i]=='yes') {?> style="background-color:#FC9" <?php } $_SESSION['plates_error'.$i]='no' ?>>
                    <input name="plate_id<?php echo $i ?>" id="plate_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>" >
                 </td> 
                  </tr>
                <?php
	$i++;
	}
	$_SESSION['line_no5'] = $i;
	?>
              </table>
              <br>
</div>
<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=2&all=');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" />
                  </span></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>
  <!--end of tableMain-->
</form>
</div>
	
    </body>