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

	$date = $_GET['date'];
	$sub_cat = $_GET['subCatSelect'];
	
	include('../include/period_select_date.php');		
	
	
	if ($sub_cat=="Complete") {
	$table_name = $_SESSION['db_prefix']."_stockloss";
	$stock_query = "SELECT * FROM $table_name WHERE date BETWEEN '".$start."' AND '".$end."'";
	$stock_result = execsql($stock_query);
	$stock_num = mysql_num_rows($stock_result);
	}
	else {
	$table_name = $_SESSION['db_prefix']."_stockloss";
	$stock_query = "SELECT * FROM $table_name WHERE sub_category = '".$sub_cat."' AND  date BETWEEN '".$start."' AND '".$end."'";
	$stock_result = execsql($stock_query);
	$stock_num = mysql_num_rows($stock_result);
	}
	
	
	?> 
 
<!--style sheets-->
<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">Stock Count Report <?php echo $sub_cat?> </label></div><br />
<br /><br />
<br />
<div class="page_middle_frame">
<?php
$page='stockLoss.php';
$reference_name='subCatSelect';
$reference=$sub_cat;
include('../include/period_select_block.php');
?>

<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').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bVisible": false},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
 
<table width="662" id="scroll_table" class="data_display">
    <thead>
      <tr>
        <th width="76">Date</th>
        <th width="32">&nbsp;</th>
        <th width="71">Stock</th>
        <th width="75">Count</th>
        <th width="64" align="center">+/-</th>
        <th width="195">Product Name</th>
        <th width="117">Sub category</th>
      </tr>
    </thead>
    <tbody>
    
    <?php
$i = 0;
$amount=0;
	while ($i < $stock_num) {
		$b1 = mysql_result($stock_result, $i, "store_item_id");
		  $table_name = $_SESSION['db_prefix']."_store_items";
		  $item_query = "SELECT item_name,category, subcategory FROM $table_name WHERE store_item_id ='".$b1."' ";
	      $item_result = execsql($item_query);
		  $b1a = mysql_result($item_result, 0, "item_name");
		  $b1b = mysql_result($item_result, 0, "category");
		  $b1c = mysql_result($item_result, 0, "subcategory");
		$b2 = mysql_result($stock_result, $i, "amount");
		$b3 = mysql_result($stock_result, $i, "date");
		$b4 = mysql_result($stock_result, $i, "quantity");
		$b5 = mysql_result($stock_result, $i, "total");
		
		//$amount += $b2;
?>
     <tr class="alt">
        <td><?php echo date("d-m-Y", strtotime($b3 )) ?></td>
        <td><?php echo $b3 ?>&nbsp;</td>
        <td align="right"><?php echo $b4?></td>
       <td align="right"><?php echo $b5?></td>
        <td align="right"><?php echo $b2?></td>
        <td>&nbsp;&nbsp;<a href="store_item_history.php?store_item_id=<?php echo $b1 ?>&date=0" onMouseover="ddrivetip('<?php           
$table_name3 = $_SESSION['db_prefix']."_item_history";
$history_query = "SELECT entry, quantity, total, date FROM $table_name3 WHERE store_item_id = '".$b1."' ORDER BY history_id DESC LIMIT 10";
$history_result = mySQL_query($history_query);
$history_num = mysql_num_rows($history_result); 
?><b>Recent history:</b><br><br><table id=table_tool_tip width=250 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><?php
$k=0;
$h2="0";
$h2a="";
while ($k<$history_num) {
          $h1 = mysql_result($history_result, $k, "date");
		  $h2 = mysql_result($history_result, $k, "entry");
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='new';}
		  if ($h2=="20") {$h2a='received';}
		  if ($h2=="30") {$h2a='delivered';}
		  $h3 = mysql_result($history_result, $k, "quantity");
		  $h4 = mysql_result($history_result, $k, "total");?>
<tr><td><?php echo date("d-m-Y", strtotime($h1)) ?></td><td><?php echo $h2a ?></td><td><?php echo $h3 ?></td><td><?php echo $h4 ?></td><?php 
$k++;
}
?></tr></table><br><b>Click for full history</b>', 260)"; onMouseout="hideddrivetip()"> <?php  echo $b1a?></a></td>
        <td><?php echo $b1c ?></td>
       
      </tr> 
 

    <?php
    $i++;
		
	}?>
	</tbody>
  </table>

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

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


