<head>
<?php

$all = $_GET['all'];   

$table_name = $_SESSION['db_prefix']."_production_bill";
$cutting_query = "SELECT * FROM $table_name WHERE job_no = '".$_SESSION['job_no']."' ";
$cutting_result = mySQL_query($cutting_query);
$cutting_num = mysql_num_rows($cutting_result);
if($cutting_num!=0) {
$production_bill_id = mysql_result($cutting_result, 0, "production_bill_id");
$table_name = $_SESSION['db_prefix']."_production_bill_lines";
$truss_query = "SELECT * FROM $table_name WHERE  production_bill_id = '".$production_bill_id."' ";
$truss_result = mySQL_query($truss_query);
$truss_num = mysql_num_rows($truss_result);
}
else {
	$truss_num = 0;
}
   
?>   
<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></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, 'deliverJobWizbase.php?p=2&s=', 'The delivery amount exceeds the balance, the entry will be cleared.<br><br>Please enter a valid amount.');
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</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="deliverJobWizbase.php?p=3&s=2&all=" method="post" name="form1" id="form1">
<div class="wizard_frame" align="right">
<input name="button" type="button" class="imagebutton" id="button"  onClick="needToConfirm = false;MM_showHideLayers('wait','','show');  window.location='deliverJobWizbase.php?p=2&s=&all=all'" value="Deliver all" checked="checked" <?php if ($all=='all') { ?> <?php } ?>><br>
</div>
<br><br>
        <table width="676" id="table_details_display">
          <tr>
            <th width="172">Truss type </th>
            <th width="116">Quantity</th>
            <th width="131">Produced</th>
            <th width="101">Delivered</th>
            <th width="132">Balance</th>
            <th width="65">Deliver</th>
            <th width="65">&nbsp;</th>
            <?php 
			
	if ($truss_num!=0) {
	$i=0;
	while ($i<$truss_num) {
		$a1 = mysql_result($truss_result, $i, "truss_type");
		$a2 = mysql_result($truss_result, $i, "quantity");
			$table_name = $_SESSION['db_prefix']."_production_bill_lines";
			$produced_query = "SELECT SUM(quantity) AS summed_quantity  FROM $table_name WHERE job_no = '".$_SESSION['job_no']."' AND truss_type = '".$a1."' ";
			$produced_result = mySQL_query($produced_query);
			$a3 = mysql_result($produced_result, 0, "summed_quantity");
		$a4 = mysql_result($truss_result, $i, "delivered");
		$a5 = $a2 - $a4;
		
		$table_name = $_SESSION['db_prefix']."_supply_customer_temp";
		$qty_query = "SELECT quantity  FROM $table_name WHERE truss_type = '".$a1."' ";
		$qty_result = mySQL_query($qty_query);
		$qty_num = mysql_num_rows($qty_result);
		if ($qty_num!=0) {
				$a6 = mysql_result($qty_result, 0, "quantity");
		}
		else {
			$a6='';
		}
		
	?>
          <tr>
            <td align="left" valign="top"><?php echo $a1 ?>
            <input type="hidden" name="truss_type_text<?php echo $i ?>" id="truss_type_text<?php echo $i ?>" value="<?php echo $a1?>"></td>
            <td align="left" valign="top"><?php echo $a2 ?></td>
            <td align="left" valign="top"><?php echo $a3 ?></td>
            <td align="left" valign="top"><?php echo $a4 ?></td>
            <td align="left" valign="top"><?php echo $a5 ?></td>
            <td colspan="2" align="left" valign="top"><input name="truss_no_text<?php echo $i ?>" type="text" class="text60" id="truss_no_text<?php echo $i ?>" 
 onkeypress="return numbersonly(this, event)" onKeyUp="validate_required(truss_no_text<?php echo $i?>, 'The delivery amount exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid amount.', <?php echo $a5 ?>)" value="<?php if ($all=='all') {echo $a5;} else { echo $a6; } ?>" autocomplete="off" autofocus 	tabindex="<?php echo $i+1?>"></td>
          </tr>
          <?php
	$i++;
	$_SESSION['line_no2']=$i;
	}
	
    }
    else {
    ?>
          <tr>
            <td colspan="3"><label class="label_std">Cutting bill not yet made.</label><?php $i=0?>
              <label class="label_std">&nbsp;</label>
              <label class="label_std">&nbsp;</label></td>
            <td><label class="label_std">&nbsp;</label></td>
            <td><label class="label_std">&nbsp;</label></td>
            <td colspan="2">&nbsp;</td>
          </tr>
          <?php
	}
	?>
      </table>
      <br>
<br>
<div class="button_bat_frame">
      <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_goToURL('parent','deliverJobWizbase.php?s=&p=1&all=none'); return document.MM_returnValue;MM_showHideLayers('wait','','show');return document.MM_returnValue" tabindex="<?php echo $i+3?>" /></td>
          <td width="115"><input name="p" type="hidden" id="p" value="2" />
            <input name="s" type="hidden" id="s" value="2" />
            <input name="all" type="hidden" id="all" value="none" /></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, '../store/store_main.php');" value="Cancel" tabindex="<?php echo $i+4?>"/></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>
<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("roofcover_select","req","Please select type of roof cover");
  frmvalidator.addValidation("roof_pitch_text","req","Please enter roof pitch");
  frmvalidator.addValidation("overhang_text","req","Please enter the maximum overhang");
  frmvalidator.addValidation("roof_area_text","req","Please enter the roof area");
  frmvalidator.addValidation("floor_area_text","req","Please enter the floor area");
</script>
</body>      