
<?php
$table_name = $_SESSION['db_prefix']."_mworks_order_job_lines_supply_temp";
$line_query = "SELECT *  FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' AND  user_name =  '".$_SESSION['username']."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$cust_id = $_SESSION['cust_id'];


?>

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></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="wizard_page_middle_frame">
<form id="form1" method="get" action="m_supplyJobWiz5.php" >
<div class="wizard_frame">
<?php 
include('../include/customer_block.php');
?>
</div> 
<div class="wizard_frame">
<table width="650" id="table_details_display">
    <tr>
      <td align="left" valign="top">Project:</td>
      <td colspan="2" align="left" valign="top"><?php  echo $_SESSION['project'];  ?></td>
      <td align="left" valign="top"><?php echo 'Job card no:&nbsp;&nbsp;'.$_SESSION['job_card_no'];  ?></td>
    </tr>
    <tr>
      <td align="left" valign="top">Project description:</td>
      <td colspan="3" align="left" valign="top"><?php  echo $_SESSION['project_description'];  ?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Order date:;</td>
      <td width="186" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($_SESSION['order_date']));  ?></td>
      <td width="86" align="left" valign="top"></td>
      <td width="232" align="left" valign="top"></td>
    </tr>
    <tr>
      <td align="left" valign="top">Delivery date:</td>
      <td colspan="3" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($_SESSION['deliver_date']));  ?></td>
      </tr>
    <tr>
      <td width="126" align="left" valign="top">Project place:</td>
      <td colspan="3" align="left" valign="top"><?php echo $_SESSION['project_no'] ?>&nbsp;&nbsp;<?php echo $_SESSION['project_area']?>&nbsp;&nbsp;<?php echo $_SESSION['project_place']?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Notes:</td>
      <td colspan="3" align="left" valign="top"><?php echo $_SESSION['quote_note'] ?>&nbsp;</td>
    </tr>
  </table>
</div> 
<div class="wizard_frame">
Supplied to: <?php echo $_SESSION['employee_name'] ?>  
</div>
<div class="wizard_frame">
<table width="650" id="table_details_display">
 <thead> 
  <tr>
    <td width="396">Item</td>
    <td width="55">Ordered</td>
    <td width="65" align="center">To supply</td>
    <td width="49" align="center">Unit price</td>
    <td width="61" align="center">Total</td>
  </tr>
  </thead>
<?php
$all_total='';
$i=0;
while ($i<$line_num) {
	$store_item_id = mysql_result($line_result, $i, "store_item_id");
	$spec_name = mysql_result($line_result, $i, "item_name");
	$spec_price = mysql_result($line_result, $i, "price");
	     if (($store_item_id>0) AND ($store_item_id<100000)) {
				$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, price, register, unit FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
				$name_result = mySQL_query($name_query);
				$item_name = mysql_result($name_result, 0, "item_name");
				$price = mysql_result($name_result, 0, "price");
				$register = mysql_result($name_result, 0, "register");
				$unit = mysql_result($name_result, 0, "unit");
		 }
		 if ($store_item_id>100000) {
				$table_name = $_SESSION['db_prefix']."_store_items_special";
				$name_query = "SELECT item_name, price FROM $table_name WHERE special_store_item_id = '".$store_item_id."'  ";
				$name_result = mySQL_query($name_query);
				$item_name = mysql_result($name_result, 0, "item_name");
				$price = mysql_result($name_result, 0, "price");
				$register = 'no';
				$unit = '';
		 }
		 
		  if ($store_item_id==0) {
					   $item_name = $spec_name;
					   $price = $spec_price;
					   $register = 'no';
					 }
					 
	
	$quantity = mysql_result($line_result, $i, "quantity");
	$line_total = $quantity*$price;
	$all_total = $all_total + $line_total;
	
	$table_name = $_SESSION['db_prefix']."_mworks_order_job_lines";
	$ordered_query = "SELECT quantity  FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' AND  store_item_id = '".$store_item_id."'";
	$ordered_result = mySQL_query($ordered_query);
	$ordered_num = mysql_num_rows($ordered_result);
	$ordered = mysql_result($ordered_result, 0, "quantity");
	?> 
  <tr>
    <td><?php echo $item_name ?>
	<?php if ($register=='yes') {
	$table_name = $_SESSION['db_prefix']."_store_register";
    $position_query = "SELECT serial_number FROM $table_name WHERE store_item_id = '".$store_item_id."' AND job_card IS NULL ORDER BY serial_number ASC";
	$arrId2 = array ();
	$arrName2 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId2[$b] = mysql_result($position_result, $b, "serial_number");
		$arrName2[$b] = mysql_result($position_result, $b, "serial_number");
		$b++;
	}
	}
	}
	?>
    <div id='select_div' style="display:<?php if (($register=='yes') AND ($quantity>0)) {?> block; <?php } else { ?> none; <?php } ?>"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/exclamation_mark_red_small.png" width="10" height="16">Serial no: 
      <select name="serial_select<?php echo $i ?>"  id="serial_select<?php echo $i ?>" class="select120"  >
        <?php if (($register=='yes') AND ($quantity>0)) {?>
        <option value="  " selected="selected"> </option>
        <?php } else { ?>
        <option value="." selected="selected">.</option>
        <?php } ?>
         <?php
        	for ($j = 0; $j < count($arrId2); $j++) {
    		echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
	}
?>

      </select>
	</div>  
<input type="hidden" name="register_text<?php echo $i ?>" id="register_text<?php echo $i ?>" value="<?php if ($register=='yes') {echo 'yes';} else {echo 'no';} ?>">      
    </td>
    <td align="center"><?php if ($unit!='no') {echo number_format($ordered, 2, '.', ',');} else { echo number_format($ordered, 0, '.', ','); } ?>      &nbsp;</td>
    <td align="center"><?php if ($unit!='no') {echo number_format($quantity, 2, '.', ',');} else { echo number_format($quantity, 0, '.', ','); } ?></td>
    <td align="right"><?php echo number_format($price, 2, '.', ',') ?></td>
    <td align="right"><?php echo number_format($line_total, 2, '.', ',') ?></td>
  </tr>
  <?php
  $i++;
}
?>
<tfoot>
<tr>
    <td></td>
    <td></td>
    <td></td>
    <td ></td>
    <td align="right"><?php echo number_format($all_total, 2, '.', ',') ?></td>
  </tr>
  </tfoot>
</table>

</div>        
    <div class="wizard_frame">
          <input name="s" type="hidden" id="s" value="3" />
          <input name="p" type="hidden" id="p" value="3" />
          <label class="label_std">If you want to make changes use the 'Prev' button to go back. <br />
            Click 'New' to make a new entry or to finish the wizard click 'Finish'.</label>
    </div>
        <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','m_supplyJobWizbase.php?s=&p=2');return document.MM_returnValue" /></td>
            <td width="115">&nbsp;</td>
            <td width="99"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="javascript:cancel_confirmation(1, '../store/store_main.php'); needToConfirm = false;" value="Cancel" /></td>
            <td width="125">&nbsp;</td>
            <td width="110"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" 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();
  
  for (i = 0; i < 50; i++) {
  frmvalidator.addValidation("serial_select"+i,"req","- serial no on line "+(i+1)+".");
  }
</script>