<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");


$table_name = $_SESSION['db_prefix']."_stockloss";
$tiles_date_query = "SELECT date FROM $table_name WHERE sub_category = 'Tiles' ORDER BY date DESC LIMIT 1 ";
$tiles_date_result = mySQL_query($tiles_date_query);
$tiles_date_num = mysql_num_rows($tiles_date_result);
if ($tiles_date_num!=0) {
$tiles_stock_date = mysql_result($tiles_date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$tiles_query = "
SELECT
store_item_id,
ABS(SUM((total - quantity)*unit_price)) AS difference_2, 
SUM((total - quantity)*unit_price) AS difference
FROM $table_name 
WHERE sub_category = 'Tiles' 
AND DATE = '".$tiles_stock_date."'
ORDER BY difference_2 DESC
LIMIT 1
"
;

$tiles_result = mySQL_query($tiles_query);
$tiles_num = mysql_num_rows($tiles_result);
if ($tiles_num>0) {
$store_item_id = mysql_result($tiles_result, 0, "store_item_id");
$tiles_difference = mysql_result($tiles_result, 0, "difference");

$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$tiles_name = mysql_result($name_result, 0, "item_name");
}
else {
	$tiles_difference = '0';
	$tiles_name = '';
}
}
else {
	$tiles_difference = '0';
	$tiles_name = '';
	$tiles_stock_date = date("Y-m-d");
}


$table_name = $_SESSION['db_prefix']."_stockloss";
$acc_date_query = "SELECT date FROM $table_name WHERE sub_category = 'Accessories' ORDER BY date DESC LIMIT 1 ";

$acc_date_result = mySQL_query($acc_date_query);
$acc_date_num = mysql_num_rows($acc_date_result);
if ($acc_date_num!=0) {
$acc_stock_date = mysql_result($acc_date_result, 0, "date");

$acc_name = $_SESSION['db_prefix']."_stockloss";
$acc_query = "
SELECT
store_item_id,
ABS(SUM((total - quantity)*unit_price)) AS difference_2, 
SUM((total - quantity)*unit_price) AS difference
FROM $table_name 
WHERE sub_category = 'Accessories' 
AND DATE = '".$acc_stock_date."'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$acc_result = mySQL_query($acc_query);
$acc_num = mysql_num_rows($acc_result);

if ($acc_num>0) {
$store_item_id = mysql_result($acc_result, 0, "store_item_id");
$acc_difference = mysql_result($acc_result, 0, "difference");

$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$acc_name = mysql_result($name_result, 0, "item_name");
}
else { 
$acc_difference = '0';
$acc_name = '';
}
}
else {
	$acc_difference = '0';
	$acc_name = '';
	$acc_stock_date = date("Y-m-d");
}


$table_name = $_SESSION['db_prefix']."_stockloss";
$acc_date_query = "SELECT date FROM $table_name WHERE sub_category = 'Accessories' ORDER BY date DESC LIMIT 1 ";

$acc_date_result = mySQL_query($acc_date_query);
$acc_date_num = mysql_num_rows($acc_date_result);
if ($acc_date_num!=0) {
$acc_stock_date = mysql_result($acc_date_result, 0, "date");

$acc_name = $_SESSION['db_prefix']."_stockloss";
$acc_query = "
SELECT
store_item_id,
ABS(SUM((total - quantity)*unit_price)) AS difference_2, 
SUM((total - quantity)*unit_price) AS difference
FROM $table_name 
WHERE sub_category = 'Accessories' 
AND DATE = '".$acc_stock_date."'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$acc_result = mySQL_query($acc_query);
$acc_num = mysql_num_rows($acc_result);

if ($acc_num>0) {
$store_item_id = mysql_result($acc_result, 0, "store_item_id");
$acc_difference = mysql_result($acc_result, 0, "difference");

$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$acc_name = mysql_result($name_result, 0, "item_name");
}
else { 
$acc_difference = '0';
$acc_name = '';
}
}
else {
	$acc_difference = '0';
	$acc_name = '';
	$acc_stock_date = date("Y-m-d");
}

$table_name = $_SESSION['db_prefix']."_stockloss";
$prod_date_query = "SELECT date FROM $table_name WHERE category = 'Production' ORDER BY date DESC LIMIT 1 ";

$prod_date_result = mySQL_query($prod_date_query);
$prod_date_num = mysql_num_rows($prod_date_result);
if ($prod_date_num!=0) {
$prod_stock_date = mysql_result($prod_date_result, 0, "date");

$prod_name = $_SESSION['db_prefix']."_stockloss";
$prod_query = "
SELECT
store_item_id,
ABS(SUM((total - quantity)*unit_price)) AS difference_2, 
SUM((total - quantity)*unit_price) AS difference
FROM $table_name 
WHERE category = 'Production' 
AND DATE = '".$prod_stock_date."'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$prod_result = mySQL_query($prod_query);
$prod_num = mysql_num_rows($prod_result);

if ($prod_num>0) {
$store_item_id = mysql_result($prod_result, 0, "store_item_id");
$prod_difference = mysql_result($prod_result, 0, "difference");

$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$prod_name = mysql_result($name_result, 0, "item_name");
}
else { 
$prod_difference = '0';
$prod_name = '';
}
}
else {
	$prod_difference = '0';
	$prod_name = '';
	$prod_stock_date = date("Y-m-d");
}


$table_name = $_SESSION['db_prefix']."_stockloss";
$prod_date_query = "SELECT date FROM $table_name WHERE category = 'Production' ORDER BY date DESC LIMIT 1 ";

$prod_date_result = mySQL_query($prod_date_query);
$prod_date_num = mysql_num_rows($prod_date_result);
if ($prod_date_num!=0) {
$prod_stock_date = mysql_result($prod_date_result, 0, "date");

$prod_name = $_SESSION['db_prefix']."_stockloss";
$prod_query = "
SELECT
store_item_id,
ABS(SUM((total - quantity)*unit_price)) AS difference_2, 
SUM((total - quantity)*unit_price) AS difference
FROM $table_name 
WHERE category = 'Production' 
AND DATE = '".$prod_stock_date."'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$prod_result = mySQL_query($prod_query);
$prod_num = mysql_num_rows($prod_result);

if ($prod_num>0) {
$store_item_id = mysql_result($prod_result, 0, "store_item_id");
$prod_difference = mysql_result($prod_result, 0, "difference");

$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$prod_name = mysql_result($name_result, 0, "item_name");
}
else { 
$prod_difference = '0';
$prod_name = '';
}
}
else {
	$prod_difference = '0';
	$prod_name = '';
	$prod_stock_date = date("Y-m-d");
}






$table_name = $_SESSION['db_prefix']."_stockloss";
$date_query = "SELECT date FROM $table_name WHERE sub_category = 'Cleaning materials' ORDER BY date DESC LIMIT 1 ";

$date_result = mySQL_query($date_query);
$date_num = mysql_num_rows($date_result);
if ($date_num!=0) {
$complete_stock_date = mysql_result($date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$complete_query = "
SELECT
store_item_id,
ABS(SUM((total - quantity)*unit_price)) AS difference_2, 
SUM((total - quantity)*unit_price) AS difference
FROM $table_name 
WHERE DATE = '".$complete_stock_date."'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$complete_result = mySQL_query($complete_query);
$complete_num = mysql_num_rows($complete_result);
if ($complete_num>0) {
$store_item_id = mysql_result($complete_result, 0, "store_item_id");
$complete_difference = mysql_result($complete_result, 0, "difference");

$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$complete_name = mysql_result($name_result, 0, "item_name");
}
else {
$complete_difference = '0';
$complete_name = '';
}	
}
else {
$complete_difference = '0';
$complete_name = '';
$complete_stock_date = date("Y-m-d");
}
?>



<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>


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

<div class="main_frame">
<table width="630" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="52" colspan="4" align="left" valign="top"><div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Select stock count report</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
       <br />
<br /><br />
<br />

<div class="page_middle_frame">
<form action="" method="get" >
  
  <div class="page_inside_frame" style="margin-top:15px; width:675px;">
  <br />
  <div class="page_inside_frame" style="width:150px; float:left; text-align:center; height:160px; margin-left:10px;
  ">
    <input name="tiles_button" type="button" class="imagebutton" id="tiles_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Tiles&date=1&date1=<?php echo $tiles_stock_date?>&date2=<?php echo $tiles_stock_date?>');return document.MM_returnValue" value="Tiles" />
    
    <br />
    <br />
     difference recorded:<br />
    P<?php echo number_format($tiles_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php if ($tiles_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($tiles_stock_date));} else { echo 'No reocords';}?>
</div>
  <div class="page_inside_frame" style="width:150px; float:left; text-align:center; margin-left:20px;  height:160px;">
    <input name="acc_button" type="button" class="imagebutton" id="acc_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Accessories&date=1&date1=<?php echo $acc_stock_date?>&date2=<?php echo $acc_stock_date?>');return document.MM_returnValue" value="Accessories" /><br />
    <br />
    difference recorded:<br />
    P<?php echo number_format($acc_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php if ($tiles_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($acc_stock_date));} else { echo 'No reocords';}?>
  </div>

<div class="page_inside_frame" style="width:150px; float:left; text-align:center; height:160px; margin-left:20px;
  ">
  <input name="production_button" type="button" class="imagebutton" id="production_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Production&amp;date=1&amp;date1=<?php echo $prod_stock_date?>&amp;date2=<?php echo $prod_stock_date?>');return document.MM_returnValue" value="Production materials" />
  <br />
  <br />
  difference recorded:<br />
  P<?php echo number_format($prod_difference, 2, '.', ',') ?><br />
  <br />
  <br />
  Last stock take:<br />
  <?php if ($prod_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($prod_stock_date));} else { echo 'No records';}?>
</div>
  </div>
  <br />
  <div class="page_inside_frame" style="margin-top:15px; width:675px;">
    <label class="label_std">Select other stock count reports here:</label>
    <br />
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <select name="list_select" class="select200" id="list_select" onchange="window.location.href= this.form.list_select.options[this.form.list_select.selectedIndex].value">
  <option value="stockLoss.php?subCatSelect=Cleaning materials&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Cleaning materials</option>
    
    <option value="stockLoss.php?subCatSelect=Consumables&date=1&date1=<?php echo $tiles_stock_date?>&date2=<?php echo $tiles_stock_date?>">Consumables</option>
    <option value="stockLoss.php?subCatSelect=Fuel&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Fuel</option>
    <option value="stockLoss.php?subCatSelect=Lubricants&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Lubricants</option>
    <option value="stockLoss.php?subCatSelect=Machine spares&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Machine spares</option>
    <option value="stockLoss.php?subCatSelect=Vortex Hydra spares&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Vortex Hydra spares</option>
    <option value="stockLoss.php?subCatSelect=PPE&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">PPE</option>
    <option value="stockLoss.php?subCatSelect=Tools&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Tools</option>
    <option value="stockLoss.php?subCatSelect=Welding & Engineering&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>">Welding &amp; Engineering</option>
    <option value=" " selected="selected"> </option>
  </select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<br />
<br />
</form>
</div>

    </td>
    </tr>
    </table>
</div>

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


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