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

$store_item_id = $_GET['store_item_id'];
				
$table_name = $_SESSION['db_prefix']."_store_register";
$register_query = "SELECT * FROM $table_name WHERE store_item_id = '".$store_item_id."' ORDER BY store_item_id ";
$register_result = mySQL_query($register_query);
$register_num = mysql_num_rows($register_result);
		    	
?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />


</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">
 
  <div class="page_head_frame">
    <label class="label_page_head">Store Register  </label>
  </div>
 
<div class="page_inside_frame">
<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script> 
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table_1').dataTable( {
					"sScrollY": "410px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "asc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
						 ]
				} );
			} );
		</script>
  <table width="651" id="scroll_table_1" class="data_display">
      <thead>
        <tr>
          <th>Product Name</th>
          <th width="76">Serial no</th>
          <th width="66">Date received</th>
          <th width="56">Job card</th>
          <th width="106">Customer</th>
          <th width="66">Supply date</th>
          <th width="76">Additional<br>
            Supply date</th>
          <th width="58">Return date</th>
          </tr>
      </thead>
      <tbody>
        <?php 
    $i=0;
    while($i < $register_num){
	       $b1 = mysql_result($register_result, $i, "store_item_id");
		   		$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, subCategory, location, minimumStock, maximumStock, price FROM $table_name WHERE store_item_id = '".$b1."'  ";
				$name_result = mySQL_query($name_query);
				$b1a = mysql_result($name_result, 0, "item_name");
				$b1b = mysql_result($name_result, 0, "subCategory");
				$b1c = mysql_result($name_result, 0, "location");
				$b1d = mysql_result($name_result, 0, "minimumStock");
				$b1e = mysql_result($name_result, 0, "maximumStock");
				
				
	       $b2 = mysql_result($register_result, $i, "serial_number");
	       $b3 = mysql_result($register_result, $i, "date_received");
		   $b4 = mysql_result($register_result, $i, "notes");
	       $b5 = mysql_result($register_result, $i, "job_card");
		   $maintenance = mysql_result($register_result, $i, "maintenance");
		   
		   if ($b5!='') {
			   
			    if ($maintenance=='yes') {
					   	$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
					   	$cust_id_query = "SELECT cust_id, project FROM $table_name WHERE maintenance_card_no = '".$b5."' ";
						$cust_id_result = mySQL_query($cust_id_query);
						$cust_id = mysql_result($cust_id_result, 0, "cust_id");
						$b8 = mysql_result($cust_id_result, 0, "project");
				}
				if ($maintenance=='') { 
				   		$table_name = $_SESSION['db_prefix']."_compiled_jobs";
				   		$cust_id_query = "SELECT cust_id, project FROM $table_name WHERE job_card_no = '".$b5."' ";
						$cust_id_result = mySQL_query($cust_id_query);
						$cust_id = mysql_result($cust_id_result, 0, "cust_id");
						$b8 = mysql_result($cust_id_result, 0, "project");
				}
				if ($maintenance=='cash') { 
				   		$table_name = $_SESSION['db_prefix']."_direct_delivery";
				   		$cust_id_query = "SELECT cust_id FROM $table_name WHERE direct_delivery_no = '".$b5."' ";
						$cust_id_result = mySQL_query($cust_id_query);
						$cust_id = mysql_result($cust_id_result, 0, "cust_id");
						$b8 = 'cash supply';
				}
				
				
				
				$table_name2 = $_SESSION['db_prefix']."_customer";
				$customer_query = "SELECT account_type, comp_name, title, name_2, phone, contact_1, cell_1 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") { 
					$b6 = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$b6 = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
				$b9 = mysql_result($customer_result, 0, "phone"); 
				$b10 = mysql_result($customer_result, 0, "contact_1"); 
				$b11 = mysql_result($customer_result, 0, "cell_1"); 
		   		}
		   		else {
		   		$b6='';
				$b8='';
				$b9='';
				$b10='';
				$b11='';
				$cust_id='';
		   		}
				
		        $b7 = mysql_result($register_result, $i, "supply_date");
				$b14 = mysql_result($register_result, $i, "return_date");
				$b15 = mysql_result($register_result, $i, "add_supply_date");
				
				
	
			$itemTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$b1a."</td></tr><tr><td>Group</td><td>".$b1b."</td></tr><tr><td>Location:</td><td>".$b1c."</td></tr><tr><td>Min. stock</td><td>".$b1d."</td></tr><tr><td>Max. stock</td><td>".$b1e."</td></tr></table><br><b>Click for details</b>"; 
			
			$jobTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Job card:</td><td width=175>".$b5."</td></tr><tr><td>Project</td><td>".$b8."</td></tr><tr><td>Install:</td><td>".date('d-m-Y', strtotime($b7))."</td></tr><tr><td>Customer</td><td>".$b6."</td></tr></table><br><b>Click for details</b>";
			
			$customerTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Customer:</td><td width=175>".$b6."</td></tr><tr><td>Phone</td><td>".$b9."</td></tr><tr><td>Contact:</td><td>".$b10."</td></tr><tr><td>Cell</td><td>".$b11."</td></tr></table><br><b>Click for details</b>";  
		      
    ?>
        <tr class="alt">
          <td width="111" align="left"><a href="store_item_display.php?store_item_id=<?php echo $b1 ?> " onMouseover="ddrivetip('<?php echo $itemTT ?>', 260)"; onMouseout="hideddrivetip()"><?php echo $b1a ?></a></td>
          <td align="left"><?php echo $b2 ?>&nbsp;</td>
          <td align="left"><?php echo date("d-m-Y", strtotime($b3)) ?></td>
          <td align="center">
            <?php if ($b5!='') { ?>
            <?php if ($maintenance=='yes') { ?>
            <a href="../maintenance/maintenance_card.php?maintenance_card_no=<?php echo $b5 ?>" onMouseover="ddrivetip('<?php echo $jobTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b5 ?>(M)</a>
            <?php }?>
            <?php if ($maintenance=='') { ?> 
            <a href="../orders/job_card.php?job_card_no=<?php echo $b5 ?>" onMouseover="ddrivetip('<?php echo $jobTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b5 ?>(O)</a>
            <?php } ?>
            <?php if ($maintenance=='cash') { ?> 
            <a href="direct_delivery.php?direct_delivery_no=<?php echo $b5 ?>" onMouseover="ddrivetip('<?php echo $jobTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b5 ?>(D)</a>
            <?php } ?>
            <?php } ?>
          </td>
          <td align="center"><a href="../sales/customer_details.php?cust_id=<?php echo $cust_id ?>" onMouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b6 ?></a></td>
          <td align="center"><?php if ($b7!='0000-00-00') {echo date("d-m-Y", strtotime($b7));} ?></td>
          <td align="center"><?php if ($b15!='0000-00-00') {echo date("d-m-Y", strtotime($b15));} ?></td>
          <td align="center"><?php if ($b14!='0000-00-00') {echo date("d-m-Y", strtotime($b14));} ?></td>
          </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
  </div>  
  </div>
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
