<!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");
//$today = date("Y-m-d");
//$start_date = strtotime(date("Y-m-d", strtotime($today)) . " -30 day");
//$start_date = date("Y-m-d", $start_date);

$table_name = $_SESSION['db_prefix']."_stockloss";
$date_query = "SELECT date FROM $table_name WHERE sub_category = 'Timber'  ORDER BY date DESC LIMIT 1 ";
$date_result = mySQL_query($date_query);
$date_num = mysql_num_rows($date_result);
$timber_stock_date = mysql_result($date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$timber_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 = 'Timber' 
AND DATE = '".$timber_stock_date."'

ORDER BY difference_2 DESC
LIMIT 1
"
;



$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);
if ($timber_num>0) {
$store_item_id = mysql_result($timber_result, 0, "store_item_id");
$timber_difference = mysql_result($timber_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);
$timber_name = mysql_result($name_result, 0, "item_name");
}
else {
	$timber_difference = '0';
	$timber_name = '';
}



$table_name = $_SESSION['db_prefix']."_stockloss";
$date_query = "SELECT date FROM $table_name WHERE sub_category = 'Mitek'  ORDER BY date DESC LIMIT 1 ";
$date_result = mySQL_query($date_query);
$date_num = mysql_num_rows($date_result);
$mitek_stock_date = mysql_result($date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$mitek_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 = 'Mitek' 
AND DATE = '".$mitek_stock_date."'

ORDER BY difference_2 DESC
LIMIT 1
"
;
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);

if ($mitek_num>0) {
$store_item_id = mysql_result($mitek_result, 0, "store_item_id");
$mitek_difference = mysql_result($mitek_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);
$mitek_name = mysql_result($name_result, 0, "item_name");
}
else { 
$mitek_difference = '0';
$mitek_name = '';
}


$table_name = $_SESSION['db_prefix']."_stockloss";
$date_query = "SELECT date FROM $table_name WHERE sub_category = 'Sundries'  ORDER BY date DESC LIMIT 1 ";
$date_result = mySQL_query($date_query);
$date_num = mysql_num_rows($date_result);
$sundries_stock_date = mysql_result($date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$sundries_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 = 'Sundries' 
AND DATE = '".$sundries_stock_date."'

ORDER BY difference_2 DESC
LIMIT 1
"
;
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);
if ($sundries_num>0) {
$store_item_id = mysql_result($sundries_result, 0, "store_item_id");
$sundries_difference = mysql_result($sundries_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);
$sundries_name = mysql_result($name_result, 0, "item_name");
}
else {
$sundries_difference = '0';
$sundries_name = '';
}


$table_name = $_SESSION['db_prefix']."_stockloss";
$date_query = "SELECT date FROM $table_name  ORDER BY date DESC LIMIT 1 ";
$date_result = mySQL_query($date_query);
$date_num = mysql_num_rows($date_result);
$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 = '';
}
	
?>



<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 />
<br />
<br />

<div class="page_middle_frame">
<form action="" method="get" >
  <p><br />
    <br />
  </p>
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; height:160px;">
    <input name="timber_button" type="button" class="imagebutton" id="job_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Timber&date=1&date1=<?php echo $timber_stock_date?>&date2=<?php echo $timber_stock_date?>');return document.MM_returnValue" value="Timber" />
    <br />
    <br />
     difference recorded:<br />
    P<?php echo number_format($timber_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php echo date("d-m-Y", strtotime($timber_stock_date))?>
  </div>
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; margin-left:20px;  height:160px;">
    <input name="mitek_button" type="button" class="imagebutton" value="Mitek products" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Mitek&amp;date=1&date1=<?php echo $mitek_stock_date?>&date2=<?php echo $mitek_stock_date?>');return document.MM_returnValue"/><br />
    <br />
    difference recorded:<br />
    P<?php echo number_format($mitek_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php echo date("d-m-Y", strtotime($mitek_stock_date))?>
  </div>
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; margin-left:20px;  height:160px;">
    <input name="sundries_button" type="button" class="imagebutton" value="Sundries" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Sundries&date=1&date1=<?php echo $sundries_stock_date?>&date2=<?php echo $sundries_stock_date?>');return document.MM_returnValue"/>
    <br />
    <br />
     difference recorded:<br />
    P<?php echo number_format($sundries_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php echo date("d-m-Y", strtotime($sundries_stock_date))?>
  </div>
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; margin-left:20px;  height:160px;">
    <input name="complete_button" type="button" class="imagebutton" id="cutting_bill_button2" value="Complete" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Complete&date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>');return document.MM_returnValue"/>
    <br />
    <br />
     difference recorded:<br />
	P<?php echo number_format($complete_difference, 2, '.', ',') ?><br />
	<br /><br />
Last stock take:<br />
<?php echo date("d-m-Y", strtotime($complete_stock_date))?>
  </div>
  <br />
  <div class="page_inside_frame" style="margin-top:15px;">
    <label class="label_std">Select other store lists here:</label>
  &nbsp;&nbsp;<span class="wizard_frame">
  <select name="job_no_select" class="select200" id="store_list_select" onchange="window.location.href= this.form.store_list_select.options[this.form.store_list_select.selectedIndex].value">
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Cleaning materials">Cleaning materials</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Consumables">Consumables</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Fuels">Fuel</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Lubricants">Lubricants</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Machine spares">Machine spares</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=PPE">PPE</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Tools">Tools</option>
    <option value="stockLoss.php?date=1&date1=<?php echo $complete_stock_date?>&date2=<?php echo $complete_stock_date?>&subCatSelect=Welding and Engineering">Welding &amp; Engineering</option>
    <option value=" " selected="selected"> </option>
  </select>
</span></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>