<?php
require_once ('../include/tc_calendar.php');
	$start = strtotime($_SESSION['install_date']);
	$d = date("d", $start );
	$m = date("m", $start );
	$y = date("Y", $start );

$table_name = $_SESSION['db_prefix']."_mworks_job_components";
$component_query = "SELECT component, quantity, produced_quantity, quantity_delivered, notes FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' ";
$component_result = mySQL_query($component_query);
$component_num = mysql_num_rows($component_result);
	
$table_name = $_SESSION['db_prefix']."_vehicle";
$select_query = "SELECT vehicle_id, registration_no, make, model FROM $table_name";
	$arrId = array ();
	$arrName = array ();
	$select_result = execsql($select_query);
	$select_num = mysql_num_rows($select_result);
	$a = 0;
	while ($a < $select_num) {
		$arrId[$a] = mysql_result($select_result, $a, "vehicle_id");
		$arrName[$a] = mysql_result($select_result, $a, "registration_no").' '.mysql_result($select_result, $a, "make").' '.mysql_result($select_result, $a, "model");
		$a++;
	}		
?>

<script type="text/javascript">
function validate_required(input,alerttxt,maxvalue)
{
	
with (input)
  {
  if (value>maxvalue)
    {
    alertMessage(1, '', 'The delivery number exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid number.');
	input.value = '';
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>

<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="javascript" src="../jscript/calendar.js"></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');"  onBlur="MM_showHideLayers('wait','','hide');">

<div class="wizard_page_middle_frame">
<form action="" method="get" name="form1" id="form1" >
     
        
        <div class="wizard_frame" style="min-height:180px;">
          <table width="650" id="table_details_display">
            <tr>
              <td width="156">Item</td>
              <td width="146">Notes</td>
              <td width="51">Quantity</td>
              <td width="59">Produced</td>
              <td width="58">Delivered</td>
              <td width="66">Balance</td>
              <td width="82">Deliver now</td>
            </tr>
            <?php 
  $i=0;
  while ($i<$component_num) {
	  $component = mysql_result($component_result, $i, "component");
	  $quantity = mysql_result($component_result, $i, "quantity");
	  $produced_quantity = mysql_result($component_result, $i, "produced_quantity");
	  $quantity_delivered = mysql_result($component_result, $i, "quantity_delivered");
	  
	  if ($produced_quantity=='') {$produced_quantity=0;}
	  $notes = mysql_result($component_result, $i, "notes");
	  $balance =$produced_quantity-$quantity_delivered;
	  
	?>
            <tr>
              <td><?php echo $component ?>
                <input type="hidden" name="component_text<?php echo $i?>" id="component_text<?php echo $i?>" value="<?php echo $component ?>"></td>
              <td><?php echo $notes ?></td>
              <td align="center"><?php echo $quantity ?>
                <input type="hidden" name="quantity_text<?php echo $i?>" id="quantity_text<?php echo $i?>" value="<?php echo $quantity ?>"></td>
              <td align="center"><?php echo $produced_quantity ?>
                <input type="hidden" name="produced_text<?php echo $i?>" id="produced_text<?php echo $i?>" value="<?php echo $produced_quantity ?>"></td>
              <td align="center"><?php echo $quantity_delivered ?>
              <input type="hidden" name="delivered_text<?php echo $i?>2" id="delivered_text<?php echo $i?>2" value="<?php echo $quantity_delivered ?>"></td>
              <td align="center"><?php echo $balance ?>
                <input type="hidden" name="balance_text<?php echo $i?>" id="balance_text<?php echo $i?>" value="<?php echo $balance ?>"></td>
              <td align="center"><input type="text" name="new_text<?php echo $i?>" id="new_text<?php echo $i?>"  width="50px;" class="text40" style="text-align:right" onKeyUp="validate_required(new_text<?php echo $i?>, 'The delivery number exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid number.', <?php echo $balance ?>)"   onKeyPress="return numbersonly(this, event)" onfocus = "this.select();" autocomplete="off"  value="<?php echo $_SESSION['new_delivered'.$i] ?>"></td>
              <?php
	$i++;
  }
  $_SESSION['line_num'] = $i;
	?>
              <input name="line_num_text" id="line_num_text" type="hidden" value="<?php echo $_SESSION['line_num'] ?>">
            </tr>
          </table>
        </div>
<?php
if ($_SESSION['mworks']=='only') { ?>        
   <div class="wizard_frame">
    <table width="600" id="table_details_display">
  <tr>
    <td width="131">Vehicle to be used: 
      <label class="star">*</label></td>
    <td width="469"><select name="vehicle_select" id="vehicle_select" class="select200" >
      <option selected value="<?php echo $_SESSION['vehicle_id']?>"><?php echo $_SESSION['vehicle_name']?></option>
      <?php
        	for ($i = 0; $i < count($arrId); $i++) {
    		echo "<option value=".$arrId[$i].">".$arrName[$i]."</option>";
	}
?>
    </select></td>
  </tr>
</table>
</div>  
<?php } ?>   
        <div class="wizard_frame">
      <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','deliverJobWizbase.php?s=&amp;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" id="next_button" class="imagebutton" value="Next"  onClick="needToConfirm = false; MM_showHideLayers('wait','','show'); " /></td>
        </tr>
      </table>
      </div>
</form>
</div>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("vehicle_select","req","- vehicle to be used.");
  
</script>
</body>      