<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include ("../navigation/header.php");

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {

include ("../navigation/store_sidebar.php");

$order_no = $_GET['order_no'];
    
		$table_name = $_SESSION['db_prefix']."_tile_orders";
		$quote_query = "SELECT *  FROM $table_name WHERE order_no = '".$order_no."'";
		$quote_result = mySQL_query($quote_query);
		$cust_id=mysql_result($quote_result, 0, "cust_id");
		
		$branch=mysql_result($quote_result, 0, "branch");	
		$direct=mysql_result($quote_result, 0, "direct");	
		$pallets=mysql_result($quote_result, 0, "pallets");
		$pallets_price=mysql_result($quote_result, 0, "pallets_price"); 
		$del_pallets=mysql_result($quote_result, 0, "del_pallets");
		
		$available_pallets = $pallets - $del_pallets;
		
		$quote='no';
		
		$job_no=$order_no;
		
		$table_name = $_SESSION['db_prefix']."_tile_order_lines";
		$line_query = "SELECT *  FROM $table_name WHERE order_no = '".$order_no."' ";
		$line_result = mySQL_query($line_query);
		$line_num = mysql_num_rows($line_result);
	
		$quote_no = $order_no;

?>

<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/back_button_override.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, 'tile_receive.php', 'The quantity to deliver exceeds the quantity received,<br>The entry will be cleared.<br><br>Please enter a valid quantity.');
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>

<script type="text/javascript">
function validate_pallets(input,alerttxt,maxvalue)
{
with (input)
  {
  if (value>maxvalue)
    {
    alertMessage(1, 'tile_receive.php', 'You are to supply more <br> pallets as deposit was paid for!');
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>
</head>

<body onLoad="backButtonOverride()">

<div class="main_frame" >
  <div class="page_head_frame">
        <table width="650" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="483"><label class="label_page_head">Deliver tile order</label></td>
            <td width="167" align="right"><label class="label_page_head_2">Order no <?php echo $quote_no?><br>
<?php echo $branch ?> branch</label></td>
          </tr>
        </table>
  </div><br />
<div class="page_middle_frame">
<div class="wizard_frame">
<?php if ($direct=='yes') { ?> 
<img src="../images/exclamation_mark.png" width="24" height="24">&nbsp;&nbsp;This order is to be delivered directly by Radstone. No tiles were received by Vertex.
<?php } ?>
</div>

<form action="tile_deliver_save.php" method="get">
      <div class="wizard_frame">
        <input type="hidden" name="order_no" id="order_no" value="<?php echo $order_no ?>">
        <input type="hidden" name="cust_id" id="cust_id" value="<?php echo $cust_id ?>">
        <input type="hidden" name="branch" id="branch" value="<?php echo $branch ?>">
        <input type="hidden" name="direct" id="direct" value="<?php echo $direct ?>">
        
<br></div>
<br>


      <div class="wizard_frame">
      
        <table width="652" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="483">Order no <?php echo $order_no ?> to deliver to:</td>
            <td width="169">&nbsp;</td>
          </tr>
        </table>
        <?php 
		include ('../include/customer_block.php');
		?>
         </div><br>
<br>
<div class="wizard_frame">
         <table width="650" id="table_display" >
           <tr>
             <td height="26" colspan="2" align="left" valign="top">Item</td>
             <td width="66" align="center" valign="top">Group</td>
             <td width="36" align="center" valign="top">Unit</td>
             <td width="54" align="center" valign="top">Ordered</td>
             <td width="56" align="center" valign="top"><?php if ($direct!='yes') { echo 'Received';} ?>&nbsp;</td>
             <td width="58" align="center" valign="top">Delivered</td>
             <td width="56" align="center" valign="top">Available to deliver</td>
           </tr>
           <?php
				$i=0;
				
				 while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "order_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
					if ($direct=='yes') {	
					       $a2 = mysql_result($line_result, $i, "quantity") - mysql_result($line_result, $i, "del_quantity");
					}
					else {
						$a2 = mysql_result($line_result, $i, "rec_quantity") - mysql_result($line_result, $i, "del_quantity");
					}
					 $a7 = mysql_result($line_result, $i, "rec_quantity");
					 $a6 = mysql_result($line_result, $i, "quantity");
					 $a5 = mysql_result($line_result, $i, "del_quantity");
				
					 
				 ?>
           <tr>
             <td colspan="2" valign="middle"><?php echo $a1a ?></td>
             <td valign="middle"><?php echo $a4a ?></td>
             <td valign="middle"><?php echo $a3a ?></td>
             <td align="right" valign="middle"><?php echo $a6 ?></td>
             <td align="right" valign="middle"><?php if ($direct!='yes') {echo $a7;} ?></td>
             <td align="right" valign="middle"><?php echo $a5 ?></td>
             <td align="right" valign="middle"><input type="text" name="quantity_text<?php echo $i ?>" id="quantity_text<?php echo $i ?>"  class="text50" value="<?php echo $a2 ?>" onfocus = "this.select();" onkeypress="return numbersonly(this, event)" onKeyUp="validate_required(quantity_text<?php echo $i?>, '', <?php echo $a2 ?>)" style="width:50px; text-align:right" autocomplete="off"></td>
           </tr>
           <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
           <tr>
             <td colspan="2" align="left" valign="middle">Pallets</td>
             <td align="left" valign="middle">&nbsp;<input name="pallets_price_text" type="hidden" value="<?php echo $pallets_price ?>"></td>
             <td align="left" valign="middle">&nbsp;</td>
             <td align="right" valign="middle"><?php echo $pallets ?></td>
             <td align="right" valign="middle">&nbsp;</td>
             <td align="right" valign="middle"><?php echo $del_pallets ?></td>
             <td align="right" valign="middle"><input type="text" name="pallets_text" id="pallets_text"  class="text50" value="<?php echo $available_pallets ?>" onfocus = "this.select();" onkeypress="return numbersonly(this, event)" onKeyUp="validate_pallets(pallets_text, '', <?php echo $available_pallets ?>)" style="width:50px; text-align:right" autocomplete="off"></td>
           </tr>
         </table>
         </div>
         <br>
      <br>


    <table width="642" height="50" align="left" id="table_button_bar">
        <tr>
          <td width="117">&nbsp;</td>
          <td width="115">&nbsp;</td>
          <td width="158" align="right"><input name="p" type="hidden" id="p" value="2" />
            <input name="s" type="hidden" id="s" value="2" />
            </span></td>
          <td width="136" align="right"><input name="cancel_button" type="button" class="imagebutton" id="cancel_button" onClick="needToConfirm = false; cancel_confirmation(5, '../store/store_main.php?date=0&branch=&subCatSelect=Tiles')" value="Cancel" tabindex="3"/></td>
          <td width="92" align="right"><input type="submit" name="deliver_button" id="deliver_button" class="imagebutton" value="Deliver" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" tabindex="1"/></td>
        </tr>
      </table>
</form>
</div>
</div>    
  
</div>


</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php 
    $_SESSION['denied_return'] = "store/store_main.php?date=0&branch=&subCatSelect=Tiles";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>