<head>
<?php
require_once ('../include/tc_calendar.php');
$start = strtotime($_SESSION['production_date']);
$d = date("d", $start );
$m = date("m", $start );
$y = date("Y", $start );
?>   
		
<!--jscript-->
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="javascript" src="../jscript/calendar.js"></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, 'produceWizbase.php?p=2&s=', 'The entered quantity exceeds the balance. The quantity has been cleared. Enter a new quantity.');
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>

<?php

$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";
$truss_query = "SELECT * FROM $table_name WHERE type = 'Truss' AND bill_id = '".$bill_id."' ORDER BY truss_type";
$truss_result = mySQL_query($truss_query);
$truss_num = mysql_num_rows($truss_result);
?>

<script>
function del_all() {
	var count = <?php echo $truss_num ?>;
	i=0;
	while (i < count) {
		document.getElementById('truss_no_text'+i).value=document.getElementById('balance_value'+i).value;
	
	i++;
	}
}
</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="produceWizbase.php?p=3&s=2" method="post" name="form1" id="form1">
<div class="wizard_frame">
   <div align="left">
          <label class="label_std">Production date:</label></div>
              <?php

		$myCalendar = new tc_calendar("production_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
		$myCalendar->writeScript();
?>
        </div>
    <br>
<br>


    <div class="wizard_frame" align="right">  
        <input name="button" type="button" class="imagebutton" id="button"  onClick="del_all()" value="Produce all" checked="checked" >
       </div> <br>
<br>
<br>
<br>

        <div class="wizard_frame" >
          <table width="645" id="table_details_display">
           <thead>
            <tr>
              <th align="left" valign="top">Truss</th>
              <th align="left" valign="top">FT</th>
              <th align="left" valign="top">Number</th>
              <th align="left" valign="top">Produced</th>
              <th align="left" valign="top">Balance</th>
              <th width="59" align="left" valign="top">Produce</th>
              <th width="104" align="left" valign="top">&nbsp;</th>
            </tr>
            </thead>
            <?php 
	
	$i=0;
	
	while ($i<$truss_num) {
		$a0 = mysql_result($truss_result, $i, "bill_line_id");
		$a1 = mysql_result($truss_result, $i, "truss_type");
		$a2 = mysql_result($truss_result, $i, "quantity");
		//$a4 = mysql_result($truss_result, $i, "produced");		
		$table_name2 = $_SESSION['db_prefix']."_production_bill_lines";
			$supplied_query = "SELECT SUM(quantity) AS summed_quantity FROM $table_name2 WHERE truss_type = '".$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;
		$a7 = mysql_result($truss_result, $i, "press_points");
	?>
            <tr>
              <td align="left" valign="middle" width="82"><?php echo $a1;  ?><?php $_SESSION['truss_type'.$i] = $a1; ?></td>
              <td align="left" valign="middle" width="93"><?php echo $a7 ?></td>
              <td align="left" valign="middle" width="117"><?php echo $a2 ?></td>
              <td align="left" valign="middle" width="109"><?php echo $a4 ?></td>
              <td align="left" valign="middle" width="82"><?php echo $a5 ?>
              <input type="hidden" name="balance_value<?php echo $i ?>" id="balance_value<?php echo $i ?>" value="<?php echo $a5 ?>"></td>
              <td colspan="2" align="left" valign="middle"><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 echo $_SESSION['truss_no'.$i]; ?>" autocomplete="off" autofocus>                <input type="hidden" name="bill_line_id<?php echo $i ?>" id="bill_line_id<?php echo $i ?>"  value="<?php echo $a0 ?>"></td>
            </tr>
            <?php
	$i++;
	}
	$_SESSION['line_no2'] = $i;
	?>
          </table>
          <br>
      </div>
      <div class="wizard_frame" style="border:hidden;">
      <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_showHideLayers('wait','','show'); MM_goToURL('parent','produceWizbase.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></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 type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
        </tr>
      </table>
</div>

</form>
</div>


</body>      