<!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.reference_2,  $table_name1.reference_3, $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 =
		   "<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");
		$b8a = mysql_result($displayResult, $i, "reference_2");
		$b8b = mysql_result($displayResult, $i, "reference_3");
		
		$b10 = mysql_result($displayResult, $i, "entry");
		$b12="";
		
		
		
		
		//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 11:
		    //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 13:
		    //deliver tiles/acc	
			$table_name = $_SESSION['db_prefix']."_tile_deliver";
			$cust_id_query = "SELECT cust_id FROM $table_name WHERE delivery_no = '".$b8."'  ";
			$cust_id_result = mySQL_query($cust_id_query);
			$cust_id = mysql_result($cust_id_result, 0, "cust_id");
			
			$table_name2 = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
			$customer_result = mySQL_query($customer_query);
			$customer_num = mysql_num_rows($customer_result);	
			$cust_name = mysql_result($customer_result, 0, "comp_name"); 
						
			$deliveryTT = "Delivery on note ".$b8." for:<br>".$cust_name."<br>Batch codes: ".$b8a."<br><b>Click for details</b>";	
		break;
		case 14:
		    //supply employee
			$table_name2 = $_SESSION['db_prefix']."_employee";
			$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$b8."' ";
			$employee_result = mySQL_query($employee_query);
			$employee_num = mysql_num_rows($employee_result);	
			$emp_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
			$employee_supplyTT = "Supply employee on no ".$b8b." for:<b>".$emp_name."</b>.";	
		break;
		
		case 15:
		    //supply department
			$department_supplyTT = "Supply department on no ".$b8b." for:<b>".$b8."</b>.";	
		break;
		
		case 16:
		    //return employee
			$table_name2 = $_SESSION['db_prefix']."_employee";
			$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$b8."' ";
			$employee_result = mySQL_query($employee_query);
			$employee_num = mysql_num_rows($employee_result);	
			$emp_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
			$employee_supplyTT = "Return from employee on no ".$b8b." for:<b>".$emp_name."</b>.";	
		break;
		
		case 18:
		    //deliver tiles/acc	
			$table_name = $_SESSION['db_prefix']."_order_return";
			$cust_id_query = "SELECT cust_id FROM $table_name WHERE order_return_no = '".$b8b."'  ";
			$cust_id_result = mySQL_query($cust_id_query);
			$cust_id = mysql_result($cust_id_result, 0, "cust_id");
			
			$table_name2 = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
			$customer_result = mySQL_query($customer_query);
			$customer_num = mysql_num_rows($customer_result);	
			$cust_name = mysql_result($customer_result, 0, "comp_name"); 
						
			$order_returnTT = "Returns on note ".$b8b." for:<br>".$cust_name."<br><br><b>Click for details</b>";	
		break;
		
		case 19:
		    //supply department
			$company_supplyTT = "Supply company on no ".$b8b." for:<b>".$b8."</b>.";	
		break;
			
    	case 20:
		   	
			$table_name = $_SESSION['db_prefix']."_production_plan";
			$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no = '".$b8."' ";
			$production_result = mySQL_query($production_query);
			$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
			
			$production_noTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Production no:</td><td width=175>".$b8."</td></tr><tr><td>Product:</td><td>".$mix_design_name."</td></tr></table><br><b>Click for details</b>";	
		break;
		 
		 case 21:	           
		   //from production		
			$table_name5 = $_SESSION['db_prefix']."_production_plan_lines";
            $production_query = "SELECT production_no, mix_design_name, quantity, action_date  FROM $table_name5 WHERE production_no = '".$b8."'  ";
			$production_result = mySQL_query($production_query);
			$c2 = mysql_result($production_result, 0, "action_date");
            $c3  = mysql_result($production_result, 0, "production_no");		
		    $c4 = mysql_result($production_result, 0, "mix_design_name");	
			$productionTT = "<table id=table_tool_tip width=250 ><tr><td  width=90>Production date:</td><td width=175>".date("d-m-Y", strtotime($c2))."</td></tr><tr><td  width=90>Batch code:</td><td width=175>".$b8a."</td></tr></table><b>Click for details</b>";	
			
		 break;
		 
		case 22:
		   	//edit skips in production
			$table_name = $_SESSION['db_prefix']."_production_plan";
			$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no = '".$b8."' ";
			$production_result = mySQL_query($production_query);
			$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
			
			$production_noTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Production no:</td><td width=175>".$b8."</td></tr><tr><td>Product:</td><td>".$mix_design_name."</td></tr></table><br><b>Click for details</b>";	
		break;
		
		case 23:
		   	//edit pallets in production
			$table_name = $_SESSION['db_prefix']."_production_plan";
			$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no = '".$b8."' ";
			$production_result = mySQL_query($production_query);
			$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
			
			$production_noTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Production no:</td><td width=175>".$b8."</td></tr><tr><td>Product:</td><td>".$mix_design_name."</td></tr></table><br><b>Click for details</b>";	
		break; 
		
		case 24:
		   	//edit pallets in production
			$table_name = $_SESSION['db_prefix']."_tile_deliver";
			$cust_query = "SELECT order_no, order_reference, cust_id FROM $table_name WHERE delivery_no = '".$b8."' ";
			$cust_result = mySQL_query($cust_query);
			$order_no = mysql_result($cust_result, 0, "order_no");
			$order_reference = mysql_result($cust_result, 0, "order_reference");			
			$cust_id = mysql_result($cust_result, 0, "cust_id");
			
			$table_name2 = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
			$customer_result = mySQL_query($customer_query);
			$customer_num = mysql_num_rows($customer_result);	
			$cust_name = mysql_result($customer_result, 0, "comp_name"); 
			
			
			$palletsTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Delivery no:</td><td width=175>".$b8."</td></tr><tr><td>Order no:</td><td>".$order_no."</td></tr><tr><td>Account:</td><td>".$cust_name."</td></tr></table><br><b>Click for details</b>";	
		break; 
		
	  case 25:
		   	//edit depalleted
			
			$depalletTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Production no:</td><td width=175>".$b8."</td></tr><tr><td>Adjustment qty:</td><td>".number_format($b3, 0, '.', ',')."</td></tr></table><br><b>Click for details</b>";	
		break; 	
		
		case 30:
		   	//edit pallets in production
			$table_name = $_SESSION['db_prefix']."_vehicle";
			$vehicle_query = "SELECT registration_no, make, model FROM $table_name WHERE vehicle_id = '".$b8."' ";
			$vehicle_result = mySQL_query($vehicle_query);
			$registration_no = mysql_result($vehicle_result, 0, "registration_no");
			$make = mysql_result($vehicle_result, 0, "make");
			$model = mysql_result($vehicle_result, 0, "model");
			
			$fuel_deliveryTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Registration no:</td><td width=175>".$registration_no."</td></tr><tr><td>Vehicle</td><td>".$make." ".$model."</td></tr></table><br><b>Click for details</b>";	
		break;
		
		case 35:
		    //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; 
		 
		
		}
		
		
		
		
		$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:	           
		    	?>
            	Stock count<a href="" onMouseOver="ddrivetip('<?php echo $stockCountTT ?>' , 200)" onMouseOut="hideddrivetip()";></a>
            <?php
			break;	
			case 10:	           
		    	?>
            <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 11:	           
		    	?>
            <a href="receive_note.php?receive_id=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $itemTT ?>' , 200)" onMouseOut="hideddrivetip()";>Stock received</a>
            <?php
			break;
			case 13:	           
		    	?>
            Delivered on <a href="../store/tile_deliver_display.php?delivery_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $deliveryTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $b8 ?></a> for <a href="account_details.php?cust_id=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $deliveryTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $cust_name ?></a>, batch codes: <?php echo $b8a ?>
            <?php
			break;
			case 14:	           
		    	?>
            Supplied on no <a href="employee_supply.php?emp_supply_no=<?php echo $b8b?>" onMouseOver="ddrivetip('<?php echo $employee_supplyTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $b8b ?></a> to <a href="../hr_module/employee_details.php?emp_id=<?php echo $b8?>" onMouseOver="ddrivetip('Click for details' , 200)" onMouseOut="hideddrivetip()";><b><?php echo $emp_name?></b></a>.
            <?php
			break;
			case 15:	           
		    	?>
            Supplied on no <a href="department_supply.php?dep_supply_no=<?php echo $b8b?>" onMouseOver="ddrivetip('<?php echo $department_supplyTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $b8b ?></a> for <?php echo $b8?>, issued to: <?php echo $b8a ?>
            <?php
			break;
			case 16:	           
		    	?>
            Returned on no <a href="employee_return.php?emp_supply_no=<?php echo $b8b?>" onMouseOver="ddrivetip('<?php echo $employee_supplyTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $b8b ?></a> from <a href="../hr_module/employee_details.php?emp_id=<?php echo $b8?>" onMouseOver="ddrivetip('Click for details' , 200)" onMouseOut="hideddrivetip()";><b><?php echo $emp_name?></b></a>.
            <?php
			break;
			case 18:	           
		    	?>
            Returned on no <a href="order_return.php?order_return_no=<?php echo $b8b?>" onMouseOver="ddrivetip('<?php echo $order_returnTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $b8b ?></a> for <a href="account_details.php?cust_id=<?php echo $cust_id?>" onMouseOver="ddrivetip('<?php echo $order_returnTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $cust_name ?></a>.
            <?php
			break;
			case 19:	           
		    	?>
            Supplied on no <a href="company_supply.php?dep_supply_no=<?php echo $b8b?>" onMouseOver="ddrivetip('<?php echo $company_supplyTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo $b8b ?></a> for <?php echo $b8?>, issued to: <?php echo $b8a ?>
            <?php
			break;
			case 20:	           
		    	?>
            Used in production, production no: <a href="../production/day_production_display.php?production_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $production_noTT ?>' , 200)" onMouseOut="hideddrivetip()";><b><?php echo $b8?></b></a>: <?php echo $mix_design_name ?>
            <?php
			break;	
			case 21:	           
		    	?>
            New stock from production, date: <a href="../production/day_production_display.php?production_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $productionTT ?>' , 200)" onMouseOut="hideddrivetip()";><?php echo date("d-m-Y", strtotime($c2)) ?></a>, batch code: <?php echo $b8a ?>
            <?php
			break;
			case 22:	           
		    	?>
            Used in production, production no: <a href="../production/day_production_display.php?production_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $production_noTT ?>' , 200)" onMouseOut="hideddrivetip()";><b><?php echo $b8?></b></a>: <?php echo $mix_design_name ?>
            <?php
			break;	
			case 23:	           
		    	?>
            Used in production packing, production no: <a href="../production/day_production_display.php?production_no=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $production_noTT ?>' , 200)" onMouseOut="hideddrivetip()";><b><?php echo $b8?></b></a>: <?php echo $mix_design_name ?>
            <?php
			break;
			case 24:	           
		    	?>
            Pallets returned from delivery note <a href="../store/tile_deliver_display.php?delivery_no=<?php echo $b8 ?>" onMouseover="ddrivetip('<?php echo $palletsTT ?>', 200)"; onMouseout="hideddrivetip()"><b><?php echo $b8 ?></b></a> on order <a href="order.php?order_reference=<?php echo $order_reference ?>"><b><?php echo $order_no ?></b></a> from <a href="account_details.php?cust_id=<?php echo $cust_id ?>"><b><?php echo $cust_name ?></b></a>.
            <?php
			break;
			case 25:	           
		    	?>
            Depallet quantity for production no <a href="../production/production_plan.php?production_no=<?php echo $b8?>" onMouseover="ddrivetip('<?php echo $depalletTT ?>', 200)"; onMouseout="hideddrivetip()"><b><?php echo $b8 ?></b></a> adjusted with <?php echo number_format($b3, 0, '.', ',') ?></a>.
            <?php
			break;
			case 30:	           
		    	?>
            Diesel delivery to: <a href="../store/vehicle_details.php?vehicle_id=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $fuel_deliveryTT ?>' , 200)" onMouseOut="hideddrivetip()";><b><?php echo $registration_no?></b></a> <?php echo $make.' '.$model ?>
            <?php
			break;
			case 35:	           
		    	?>
            Adjustment on receive note<a href="receive_note.php?receive_id=<?php echo $b8?>" onMouseOver="ddrivetip('<?php echo $itemTT ?>' , 200)" onMouseOut="hideddrivetip()";> <b><?php echo $b8 ?></b></a>
            <?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'); ?>
