<!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");
	
	include('../include/period_select_date.php');	
	
	$endsearch = date('Y-m-d', strtotime('+1 day', strtotime($end)));

	$store_item_id =  $_GET['store_item_id'];	 
	
		  
	$table_name1 = $_SESSION['db_prefix']."_item_history";
	$table_name2 = $_SESSION['db_prefix']."_store_items";
	  
		$displayQuery = "SELECT $table_name1.history_id, $table_name1.store_item_id, $table_name1.details, $table_name1.entry, $table_name1.reference, $table_name1.quantity, $table_name1.total, $table_name1.date, $table_name1.entryDate,  $table_name1.userId, $table_name2.store_item_id, $table_name2.item_name FROM $table_name1, $table_name2 WHERE $table_name2.store_item_id=$store_item_id AND  $table_name2.store_item_id = $table_name1.store_item_id AND $table_name1.entryDate >= '$start' AND $table_name1.entryDate <= '$endsearch' ";


		$displayResult = execsql($displayQuery);
		$i = 0;
		$num = mysql_num_rows($displayResult);
		if ($num==0) {
		  $message="No records to show"; 
		   }
		else  {
		  $message="End of list";
		  }
	
	$table_name3 = $_SESSION['db_prefix']."_store_items";
    $item_query = "SELECT item_name, subCategory, location, quantity, minimumStock, price FROM $table_name3 WHERE store_item_id = '".$store_item_id."'  ";
    $item_result = mySQL_query($item_query);
    $b2 = mysql_result($item_result, 0, "item_name");
	$b3 = mysql_result($item_result, 0, "subCategory");
	$b4 = mysql_result($item_result, 0, "location");
	$b5 = mysql_result($item_result, 0, "quantity");
	$b6 = mysql_result($item_result, 0, "minimumStock");
	$b7 = mysql_result($item_result, 0, "price");
	
	$itemTT =
		   "<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$b2."</td></tr><tr><td>Category</td><td>".$b3."</td></tr><tr><td>Location</td><td>".$b4."</td></tr><tr><td>stock qty</td><td>".$b5."</td></tr><tr><td>Min. stock</td><td>".$b6."</td></tr><tr><td>Price</td><td>".$b7."</td></tr></table><br><b>Click for details</b>";
	
	?>
<!--style sheets-->
<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>
<div class="main_frame">
  <div class="page_head_frame">
    <label class="label_page_head">Store Item History</label>
    &nbsp;&nbsp;
    <label class="label_page_head_2"> &nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="store_item_display.php?store_item_id=<?php echo $store_item_id ?> " onMouseover="ddrivetip('<?php echo $itemTT ?>', 260)"; onMouseout="hideddrivetip()"> <?php echo $b2 ?></a></label>
  </div>
  <br />
  <br />
  <br />
  <br />
  <br />
  <?php
$page='store_item_history.php';
$reference_name='store_item_id';
$reference=$store_item_id;
include('../include/period_select_block.php');
?>
  <br />
  <br />
  <div class="scroll_frame_long">
    <table width="660" id="table_list" class="sortable-onload-0r rowstyle-alt no-arrow "  >
      <thead>
        <tr>
          <th colspan="2" class="sortable-numeric">Entry </th>
          <th width="468" >Details </th>
          <th width="42" align="center" > qty <br />
            in/out </th>
          <th width="41" align="center"> stock qty</th>
          <th width="38" align="center" >Date</th>
        </tr>
      </thead>
      <tbody>
        <?php
    $i=0;
	$receiveTT = "";
	$TT="";
	$link="";
	while($i < $num){
		$b1 = mysql_result($displayResult, $i, "history_id");
		$b2 = mysql_result($displayResult, $i, "details");
		$b3 = mysql_result($displayResult, $i, "quantity");
		$b4 = mysql_result($displayResult, $i, "date");
		$b5 = mysql_result($displayResult, $i, "store_item_id");
		$b7 = mysql_result($displayResult, $i, "total");
		$b8 = mysql_result($displayResult, $i, "reference");
		
		
		$b10 = mysql_result($displayResult, $i, "entry");
		$b12="";
		
		if ($b10==5) {if ($b3>0) {$b3='+'.$b3;} }
		if (($b10==20) ){$b3='+'.$b3;}
		if (($b10==21) ) {$b3='-'.$b3;}
		
		
		//stock count
		if ($b10==5) { 
		$b10a = "Stock count";
		$stockCountTT = "stock count";
		}
		
				
		switch ($b10) {
		case 5:
			//stock count
			$b10a = "Stock count";
			$stockCountTT = "stock count";
		break;	
		case 10:
		    //new item added	
			$table_name = $_SESSION['db_prefix']."_store_items";
			$item_query = "SELECT item_name, category, subCategory, location, minimumStock FROM $table_name WHERE store_item_id = '".$b5."' ";
			$item_result = mySQL_query($item_query);
			$m1 = mysql_result($item_result, 0, "item_name");
			$m2 = mysql_result($item_result, 0, "category");
			$m3 = mysql_result($item_result, 0, "subCategory");
			$m4 = mysql_result($item_result, 0, "location");
			$m5 = mysql_result($item_result, 0, "minimumStock");
			
			$itemTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$m1."</td></tr><tr><td>Category</td><td>".$m2."</td></tr><tr><td>Sub category</td><td>".$m3."</td></tr><tr><td>Location:</td><td>".$m4."</td></tr><tr><td>Min. stock</td><td>".$m5."</td></tr></table><br><b>Click for details</b>";	
		break;
			
    	case 20:	           
		//tiles & acc received		
			$table_name5 = $_SESSION['db_prefix']."_tile_receive_lines";
            $receive_query = "SELECT receive_line_id, receive_no, order_no  FROM $table_name5 WHERE receive_no = '".$b8."'  ";
			
			$receive_result = mySQL_query($receive_query);
            $c1 = 'Radstone';
			$c3  = mysql_result($receive_result, 0, "receive_no");		
		    $c2 = 'Radstone';
			$c4 = mysql_result($receive_result, 0, "order_no");
				
			$recnoteTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Receive note:</td><td width=175>".$c3."</td></tr></table><b>Click for details</b>";	
			$supplierTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Supplier:</td><td width=175>".$c2."</td></tr></table>";
			$orderTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Order no:</td><td width=175>".$c4."</td></tr></table><b>Click for details</b>";
		 break;
		 
		 case 21:	           
		//tiles & acc delivered		
			$table_name5 = $_SESSION['db_prefix']."_tile_deliver_lines";
            $deliver_query = "SELECT delivery_line_id, delivery_no, order_no  FROM $table_name5 WHERE delivery_no = '".$b8."'  ";
			$deliver_result = mySQL_query($deliver_query);
            $c1 = 'Radstone';
			$c3  = mysql_result($deliver_result, 0, "delivery_no");		
		    $c2 = 'Radstone';
			$c4 = mysql_result($deliver_result, 0, "order_no");	
			$delnoteTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Delivery note:</td><td width=175>".$c3."</td></tr></table><b>Click for details</b>";	
			$supplierTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Supplier:</td><td width=175>".$c2."</td></tr></table>";
			$orderTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Order no:</td><td width=175>".$c4."</td></tr></table><b>Click for details</b>";
		 break;
		 
		 case 30:	           
		//internal supply	
			
		 break;
		}
		
		
		
		
		$b9 = mysql_result($displayResult, $i, "entryDate");
		$b20 = mysql_result($displayResult, $i, "userId");

		
		$entryTT="<label class=tip_text_label_bold>Entered on: ". date('d-m-Y  --- H:i', strtotime($b9)) . " by: ". $b20."</label>";
		
		
		?>
        <tr class="alt">
          <td width="20"><a href=""onmouseover="ddrivetip('<?php echo $entryTT ?>', 250)" onMouseOut="hideddrivetip()";><?php echo $b1?></a></td>
          <td width="23"><a href=""onmouseover="ddrivetip('<?php echo $entryTT ?>', 250)" onMouseOut="hideddrivetip()";><?php echo date("d-m-Y", strtotime($b9));?></a></td>
          <td>
          <?php
            switch ($b10) {
			case 5:	           
		    //new item	?>
            Stock count<a href="" onMouseOver="ddrivetip('<?php echo $stockCountTT ?>' , 200)" onMouseOut="hideddrivetip()";></a>
            <?php
			break;	
			case 10:	           
		    //new item	?>
            <a href="store_item_display.php?store_item_id=<?php echo $b5?>" onMouseOver="ddrivetip('<?php echo $itemTT ?>' , 200)" onMouseOut="hideddrivetip()";>Item added to store</a>
            <?php
			break;	
    	    case 20:	           
		    //tiles & acc received	?>
            Received, receive note no: <a href="tile_receive_display.php?receive_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $recnoteTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $c3 ?></a> for order <a href="../sales/tile_order_display.php?order_no=<?php echo $c4?>" onMouseOver="ddrivetip('<?php echo $orderTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $c4 ?></a> - supplier: <a href="" onMouseOver="ddrivetip('<?php echo $supplierTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $c2 ?></a>
            <?php
			break;
			case 21:	           
		    //tiles & acc delivered	?>
            Delivered, delivery note no: <a href="tile_deliver_display.php?delivery_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $delnoteTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $c3 ?></a> for order <a href="../sales/tile_order_display.php?order_no=<?php echo $c4?>" onMouseOver="ddrivetip('<?php echo $orderTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $c4 ?></a> - supplier: <a href="" onMouseOver="ddrivetip('<?php echo $supplierTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $c2 ?></a>
            <?php
			break;
			case 30:	           
		    //tiles & acc delivered	?>
            Supplied to <b><?php echo $b8?></b>
            <?php
			break;
			 } ?>
              
            
            </td>
          <td align="right"><?php echo $b3?></td>
          <td align="right"><?php echo $b7?></td>
          <td><?php echo date("d-m-Y", strtotime($b4));?></td>
        </tr>
        <?php
		$i++;
		  
	}
	
	?>
      </tbody>
    </table>
  </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'); ?>
