<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
$_SESSION['current_page']  = "production";
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>

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

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

<body>
<?php 

$store_item_id = $_GET['store_item_id'];
$table_name = $_SESSION['db_prefix']."_store_items";
$item_query = "SELECT * FROM $table_name WHERE store_item_id ='".$store_item_id."'";
$item_result = execsql($item_query);


	$f1=mysql_result($item_result,0,"item_name");
	$f2=mysql_result($item_result,0,"supplier_id");
	$f3=mysql_result($item_result,0,"category");
	$f4=mysql_result($item_result,0,"subCategory");
	$f5=mysql_result($item_result,0,"unit");
	$f6=mysql_result($item_result,0,"returnable");
	$f7=mysql_result($item_result,0,"quantity");
	$f8=mysql_result($item_result,0,"price");
	$f10=mysql_result($item_result,0,"date");
	$f11=mysql_result($item_result, 0, "store_item_id");
	$f12=mysql_result($item_result, 0, "location");
	$f13=mysql_result($item_result, 0, "minimumStock");
	$f14=mysql_result($item_result, 0, "productSpecs");
	$f15=mysql_result($item_result,0,"purchase_price");
		
	$table_name2 = $_SESSION['db_prefix']."_suppliers";
	if($f2!=0) {
    $suppliers_query = "SELECT account_name, post_address, post_place, phone, contact1, cell1 FROM $table_name2 WHERE supplier_id = '".$f2."' ";
	$suppliers_result = mySQL_query($suppliers_query);
    $suppliers_num = mysql_num_rows($suppliers_result);
	if ($suppliers_num!=0) {
       $a1 = mysql_result($suppliers_result, 0, "account_name");
	   $a2 = mysql_result($suppliers_result, 0, "post_address");
	   $a3 = mysql_result($suppliers_result, 0, "post_place");
	   $a4 = mysql_result($suppliers_result, 0, "phone");
	   $a5 = mysql_result($suppliers_result, 0, "contact1");
	   $a6 = mysql_result($suppliers_result, 0, "cell1");
	}
	else {
		$a1='';
		$a2='';
		$a3='';
		$a4='';
		$a5='';
		$a6='';
	}
	}
	else {
		$a1='';
		$a2='';
		$a3='';
		$a4='';
		$a5='';
		$a6='';
	}
	
	
	$supplierTT =
		   "<table id=table_tool_tip width=250 ><tr><td  width=75>Name:</td><td width=175>".$a1."</td></tr><tr><td>Address:</td><td>".$a2."</td></tr><tr><td></td><td>".$a3."</td></tr><tr><td>Contact:</td><td>".$a5."</td></tr><tr><td>Phone:</td><td>".$a4."</td></tr><tr><td>Cell:</td><td>".$a6."</td></tr></table><br><b>Click for details</b>";
		   
$table_name3 = $_SESSION['db_prefix']."_item_history";
$history_query = "SELECT entry, quantity, total, date FROM $table_name3 WHERE store_item_id = '".$store_item_id."' ORDER BY history_id DESC LIMIT 10";
$history_result = mySQL_query($history_query);
$history_num = mysql_num_rows($history_result); 
		
$historyTT_body	='';  
$k=0;
while ($k<$history_num) {
          $h1 = mysql_result($history_result, $k, "date");
		  $h2 = mysql_result($history_result, $k, "entry");
		  $h2a='';
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='item added to store';}
		  if ($h2=="11") {$h2a='stock received';}
		  if ($h2=="13") {$h2a='order delivered';}
		  if ($h2=="18") {$h2a='return from order';}
		  if ($h2=="19") {$h2a='company supplied';}
		  if ($h2=="20") {$h2a='used in production';}
		  if ($h2=="21") {$h2a='from production';}
		  if ($h2=="22") {$h2a='skip no edited';}
		  if ($h2=="23") {$h2a='pallets no edited';}
		  if ($h2=="24") {$h2a='pallets returned';}
		  if ($h2=="35") {$h2a='adjustment receive note';}
		  
		  $h3 = mysql_result($history_result, $k, "quantity");
		  if ($h2==5) {if ($h3>0) {$h3='+'.$h3;} }
		  if (($h2==11) OR ($h2==18) OR ($h2==21) OR ($h2==24) ) {$h3='+'.$h3;}
		  if ( ($h2==13) OR ($h2==19) ) {$h3='-'.$h3;}
		  $h4 = mysql_result($history_result, $k, "total");
		  
		  if (($h2=="22") OR ($h2=="23")) { 
		  			if ($h3<0) {$h3='+'.abs($h3);}
					else {$h3='-'.abs($h3);}
		  }

$historyTT_body=$historyTT_body.'<tr><td>'.date("d-m-Y", strtotime($h1)) .'</td><td>'.$h2a.'</td><td align=right>'.number_format($h3, 2, '.', ',').'</td><td align=right>'.number_format($h4, 2, '.', ',').'</td></tr>'; 
$k++;
}

$historyTT_head='<b>Recent history:</b><br><br><table id=table_tool_tip width=400 border=1 cellspacing=0 cellpadding=0><tr><td width=75>date</td><td width=75>action</td><td width=50>qty</td><td width=50>stock qty</td></tr>';
$historyTT_foot='</table><br><b>Click for full history</b>';		   
$historyTT = $historyTT_head.$historyTT_body.$historyTT_foot; 	 
?>
<!--reference to main.css removed-->

 
<div class="main_frame">
<div class="page_head_frame">
	<label class="label_page_head">Store Item Details</label>
    &nbsp;&nbsp;&nbsp;&nbsp;
<label class="label_page_head_2"><?php echo $f1 ?></label>
  </div>
<table width="700" align="left" id="tableMain"> <!--begin of tableMain-->
    <tr>
      <td valign="top" ><br />
        <br />


<div class="page_middle_frame">
<table width="649" align="left"  id="table_display">
      <tr>
        <td width="137">Item Name:</td>
        <td colspan="3">
          <a href="store_item_history.php?store_item_id=<?php echo $store_item_id ?>&date=0" onMouseover="ddrivetip('<?php echo $historyTT ?>', 400)"; onMouseout="hideddrivetip()"><?php echo $f1; ?></a>  
        </td>
        </tr>
      <tr>
        <td>Location:</td>
        <td width="223">
          <?php echo $f12?>
          </td>
        <td width="126">Suppliers Name:</td>
        <td width="143"><a href="displaySupplier.php?supplier_id=<?php echo $f2 ?>" onMouseover="ddrivetip('<?php echo $supplierTT ?>', 200)"; onMouseout="hideddrivetip()"><?php echo $a1; ?></a></td>
      </tr>
      <tr>
        <td>Category:</td>
        <td><a href="store_items_list.php?subCatSelect=<?php echo $f4;?>" onMouseOver="ddrivetip('Click to see stores list for <?php echo $f4;?>', 200)"; onMouseOut="hideddrivetip()"><?php echo $f3;?></a></td>
        <td>Sub category:</td>
        <td><a href="store_items_list.php?subCatSelect=<?php echo $f4;?>" onMouseOver="ddrivetip('Click to see stores list for <?php echo $f4;?>', 200)"; onMouseOut="hideddrivetip()"><?php echo $f4;?></a></td>
      </tr>
      <tr>
        <td>Unit:</td>
        <td><?php echo $f5; ?></td>
        <td>Returnable:</td>
        <td><?php echo $f6; ?></td>
      </tr>
      <tr>
        <td>Quantity in stock: </td>
        <td><?php echo number_format($f7); ?></td>
        <td>Minimum Stock:</td>
        <td>
        <?=number_format($f13)?>
        </td>
      </tr>
      <tr>
        <td>Price:</td>
        <td><?php echo number_format($f8, 2, '.', ','); ?></td>
        <td>Last purchase price:</td>
        <td><?php echo number_format($f15, 2, '.', ','); ?></td>
      </tr>
      <tr>
        <td>Date added:</td>
        <td><?php echo date("d-m-Y", strtotime($f10 )); ?></td>
        <td>&nbsp;</td>
        <td></td>
      </tr>
      <tr>
        <td>Product specifiations</td>
        <td colspan="3"><?php echo $f14; ?></td>
        </tr>
    </table>
    
    <br />
    
    	
</div>




    </td>
</tr>

</table><!--end of tableMain-->


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

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


</html>
