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


$additional_supply_no = $_GET['additional_supply_no'];

$table_name = $_SESSION['db_prefix']."_maintenance_additional_supply";
$additional_query = "SELECT maintenance_card_no  FROM $table_name WHERE additional_supply_no = '".$additional_supply_no."' ";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);
$maintenance_card_no = mysql_result($additional_result, 0, "maintenance_card_no");
$job_card_no = $maintenance_card_no;

$quote='no';
$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
$job_query = "SELECT * FROM $table_name WHERE maintenance_card_no = '".$maintenance_card_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");	
$maintenance_no = mysql_result($job_result, 0, "maintenance_no");

$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
			
$table_name = $_SESSION['db_prefix']."_maintenance_additional_supply";
$supply_id_query = "SELECT additional_supply_id, additional_supply_no, maintenance_card_no, issue_date, issued_to FROM $table_name WHERE  maintenance_card_no = '".$maintenance_card_no."' AND additional_supply_no = '".$additional_supply_no."' ";
$supply_id_result = mySQL_query($supply_id_query);
$supply_id_num = mysql_num_rows($supply_id_result);
$additional_supply_id = mysql_result($supply_id_result, 0, "additional_supply_id");
$supply_job_no = mysql_result($supply_id_result, 0, "maintenance_card_no");
$supply_date = mysql_result($supply_id_result, 0, "issue_date");
$forman_name = 	mysql_result($supply_id_result, 0, "issued_to");		
			
$table_name = $_SESSION['db_prefix']."_maintenance_additional_supply_lines";
$item_query = "SELECT store_reg_id, store_item_id, item_name, quantity FROM $table_name WHERE  additional_supply_no = '".$additional_supply_no."' ";
$item_result = mySQL_query($item_query);
$item_num = mysql_num_rows($item_result);

?>

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

<!--jscript-->
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

</head>
<body>
<?php
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>
<div class="main_frame" style="height:auto;">
 <div class="page_head_frame">
     <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Additional supply maintenance job</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2">&nbsp;&nbsp;&nbsp; <?php echo $name ?></label></td>
            <td width="208">Job card no.:<label style="font-size:24px; color:#209949;"><?php echo $maintenance_card_no ?></label></td>
            </tr>
        </table>
      </div>
 <div class="page_middle_frame">
 
<div class="page_inside_frame"> 
<?php 
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/maintenance_job_block.php')
		?>
</div>

<div class="page_inside_frame">
<font size=+1;>Supply to : <?php echo $forman_name ?></font><br>
Maintenance additional supply no: <?php echo $additional_supply_no ?>&nbsp;&nbsp;&nbsp;&nbsp;Supply date: <?php echo date("d-m-Y", strtotime($supply_date)) ?>
<table width="650" id="table_details_display">
  <tr>
    <td width="448">Item</td>
    <td width="89" align="center">Supply</td>
    <td width="92" align="center">unit</td>
  </tr>
  <?php
  $i=0;
  while ($i<$item_num) {
	  $store_item_id = mysql_result($item_result, $i, "store_item_id");
	  $spec_name = mysql_result($item_result, $i, "item_name");
	  $store_reg_id = mysql_result($item_result, $i, "store_reg_id");
	  
	  		if (($store_item_id!=0) AND ($store_item_id<100000)) {
	       		$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, register, unit FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
				$name_result = mySQL_query($name_query);
				$store_item_name = mysql_result($name_result, 0, "item_name");
				$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 FROM $table_name WHERE special_store_item_id = '".$store_item_id."'  ";
				$name_result = mySQL_query($name_query);
				$store_item_name = mysql_result($name_result, 0, "item_name");
				$register = '';
				$unit='';
			}
			
			if ($store_item_id==0) {
					   $store_item_name = $spec_name;
					 }
					 
			if ($register=='yes') {
				  	$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number FROM $table_name WHERE store_register_id = '".$store_reg_id."' ";
					$register_result = mySQL_query($register_query);
					$serial = mysql_result($register_result, 0, "serial_number");
			}
			
	  $delivered = mysql_result($item_result, $i, "quantity");
	  ?>
  <tr>
    <td><?php echo $store_item_name ?> <?php if ($register=='yes') { echo 'serial no: '.$serial ; }?> </td>
    <td align="center"><?php if ($unit!='no') {echo number_format($delivered, 2, '.', ',');} else { echo number_format($delivered, 0, '.', ','); } ?></td>
    <td align="center"><?php echo $unit ?>&nbsp;</td>
  </tr>
  <?php
  $i++;
  }
  ?>
</table>

</div>

<div class="page_inside_frame">
<a href="maintenance_additional_supply_print.php?additional_supply_no=<?php echo $additional_supply_no  ?>" target="_blank"><input name="print_button" type="button" class="imagebutton" value="Print issue sheet"></a>
</div>

</div>
</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else {
$_SESSION['denied_return'] = "store/store_main.php";	
include ("../navigation/store_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>
</html>