<!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_gab_date_query = "SELECT date FROM $table_name WHERE sub_category = 'Tiles' AND branch = 'Gaborone'  ORDER BY date DESC LIMIT 1 ";
$tiles_gab_date_result = mySQL_query($tiles_gab_date_query);
$tiles_gab_date_num = mysql_num_rows($tiles_gab_date_result);
if ($tiles_gab_date_num!=0) {
$tiles_gab_stock_date = mysql_result($tiles_gab_date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$tiles_gab_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_gab_stock_date."'
AND branch = 'Gaborone'

ORDER BY difference_2 DESC
LIMIT 1
"
;

$tiles_gab_result = mySQL_query($tiles_gab_query);
$tiles_gab_num = mysql_num_rows($tiles_gab_result);
if ($tiles_gab_num>0) {
$store_item_id = mysql_result($tiles_gab_result, 0, "store_item_id");
$tiles_gab_difference = mysql_result($tiles_gab_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_gab_name = mysql_result($name_result, 0, "item_name");
}
else {
	$tiles_gab_difference = '0';
	$tiles_gab_name = '';
}
}
else {
	$tiles_gab_difference = '0';
	$tiles_gab_name = '';
	$tiles_gab_stock_date = date("Y-m-d");
}


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

$acc_gab_date_result = mySQL_query($acc_gab_date_query);
$acc_gab_date_num = mysql_num_rows($acc_gab_date_result);
if ($acc_gab_date_num!=0) {
$acc_gab_stock_date = mysql_result($acc_gab_date_result, 0, "date");

$acc_gab_name = $_SESSION['db_prefix']."_stockloss";
$acc_gab_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_gab_stock_date."'
AND branch = 'Gaborone'

ORDER BY difference_2 DESC
LIMIT 1
"
;
$acc_gab_result = mySQL_query($acc_gab_query);
$acc_gab_num = mysql_num_rows($acc_gab_result);

if ($acc_gab_num>0) {
$store_item_id = mysql_result($acc_gab_result, 0, "store_item_id");
$acc_gab_difference = mysql_result($acc_gab_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_gab_name = mysql_result($name_result, 0, "item_name");
}
else { 
$acc_gab_difference = '0';
$acc_gab_name = '';
}
}
else {
	$acc_gab_difference = '0';
	$acc_gab_name = '';
	$acc_gab_stock_date = date("Y-m-d");
}



$table_name = $_SESSION['db_prefix']."_stockloss";
$tiles_ftw_date_query = "SELECT date FROM $table_name WHERE sub_category = 'Tiles' AND branch = 'Francistown'  ORDER BY date DESC LIMIT 1 ";
$tiles_ftw_date_result = mySQL_query($tiles_ftw_date_query);
$tiles_ftw_date_num = mysql_num_rows($tiles_ftw_date_result);
if ($tiles_ftw_date_num!=0) {
$tiles_ftw_stock_date = mysql_result($tiles_ftw_date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$tiles_ftw_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_ftw_stock_date."'
AND branch = 'Francistown'

ORDER BY difference_2 DESC
LIMIT 1
"
;

$tiles_ftw_result = mySQL_query($tiles_ftw_query);
$tiles_ftw_num = mysql_num_rows($tiles_ftw_result);
if ($tiles_ftw_num>0) {
$store_item_id = mysql_result($tiles_ftw_result, 0, "store_item_id");
$tiles_ftw_difference = mysql_result($tiles_ftw_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_ftw_name = mysql_result($name_result, 0, "item_name");
}
else {
	$tiles_ftw_difference = '0';
	$tiles_ftw_name = '';
}
}
else {
	$tiles_ftw_difference = '0';
	$tiles_ftw_name = '';
	$tiles_ftw_stock_date = date("Y-m-d");
}


$table_name = $_SESSION['db_prefix']."_stockloss";
$acc_ftw_date_query = "SELECT date FROM $table_name WHERE sub_category = 'Accessories' AND branch = 'Francistown'  ORDER BY date DESC LIMIT 1 ";
$acc_ftw_date_result = mySQL_query($acc_ftw_date_query);
$acc_ftw_date_num = mysql_num_rows($acc_ftw_date_result);
if ($acc_ftw_date_num!=0) {
$acc_ftw_stock_date = mysql_result($acc_ftw_date_result, 0, "date");

$acc_ftw_name = $_SESSION['db_prefix']."_stockloss";
$acc_ftw_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_ftw_stock_date."'
AND branch = 'Francistown'

ORDER BY difference_2 DESC
LIMIT 1
"
;
$acc_ftw_result = mySQL_query($acc_ftw_query);
$acc_ftw_num = mysql_num_rows($acc_ftw_result);

if ($acc_ftw_num>0) {
$store_item_id = mysql_result($acc_ftw_result, 0, "store_item_id");
$acc_ftw_difference = mysql_result($acc_ftw_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_ftw_name = mysql_result($name_result, 0, "item_name");
}
else { 
$acc_ftw_difference = '0';
$acc_ftw_name = '';
}
}
else { 
$acc_ftw_difference = '0';
$acc_ftw_name = '';
$acc_ftw_stock_date = date("Y-m-d");
}


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

$gab_date_result = mySQL_query($gab_date_query);
$gab_date_num = mysql_num_rows($gab_date_result);
if ($gab_date_num!=0) {
$gab_complete_stock_date = mysql_result($gab_date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$gab_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 = '".$gab_complete_stock_date."'
AND branch = 'Gaborone'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$gab_complete_result = mySQL_query($gab_complete_query);
$gab_complete_num = mysql_num_rows($gab_complete_result);
if ($gab_complete_num>0) {
$store_item_id = mysql_result($gab_complete_result, 0, "store_item_id");
$gab_complete_difference = mysql_result($gab_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);
$gab_complete_name = mysql_result($name_result, 0, "item_name");
}
else {
$gab_complete_difference = '0';
$gab_complete_name = '';
}	
}
else {
$gab_complete_difference = '0';
$gab_complete_name = '';
$gab_complete_stock_date = date("Y-m-d");
}

$table_name = $_SESSION['db_prefix']."_stockloss";
$ftw_date_query = "SELECT date FROM $table_name WHERE branch = 'Francistown' ORDER BY date DESC LIMIT 1 ";
$ftw_date_result = mySQL_query($ftw_date_query);
$ftw_date_num = mysql_num_rows($ftw_date_result);
if ($ftw_date_num!=0) {
$ftw_complete_stock_date = mysql_result($ftw_date_result, 0, "date");

$table_name = $_SESSION['db_prefix']."_stockloss";
$ftw_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 = '".$ftw_complete_stock_date."'
AND branch = 'Francistown'
ORDER BY difference_2 DESC
LIMIT 1
"
;
$ftw_complete_result = mySQL_query($ftw_complete_query);
$ftw_complete_num = mysql_num_rows($ftw_complete_result);
if ($ftw_complete_num>0) {
$store_item_id = mysql_result($ftw_complete_result, 0, "store_item_id");
$ftw_complete_difference = mysql_result($ftw_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);
$ftw_complete_name = mysql_result($name_result, 0, "item_name");
}
else {
$ftw_complete_difference = '0';
$ftw_complete_name = '';
}	
}
else {
$ftw_complete_difference = '0';
$ftw_complete_name = '';
$ftw_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;">
  <div style="float:left; margin-left:140px;">Gaborone</div><div style="float:left;margin-left:275px;">Francistown</div>
  <br />
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; height:160px; margin-left:10px;
  ">
    <input name="tiles_gab_button" type="button" class="imagebutton" id="tiles_gab_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Tiles&branch=Gaborone&date=1&date1=<?php echo $tiles_gab_stock_date?>&date2=<?php echo $tiles_gab_stock_date?>&ftw_last_stock_date=<?php echo $tiles_ftw_stock_date?>');return document.MM_returnValue" value="Tiles" />
    
    <br />
    <br />
     difference recorded:<br />
    P<?php echo number_format($tiles_gab_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php if ($tiles_gab_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($tiles_gab_stock_date));} else { echo 'No reocords';}?>
  </div>
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; margin-left:20px;  height:160px;">
    <input name="acc_gab_button" type="button" class="imagebutton" id="acc_gab_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Accessories&branch=Gaborone&date=1&date1=<?php echo $acc_gab_stock_date?>&date2=<?php echo $acc_gab_stock_date?>&ftw_last_stock_date=<?php echo $acc_ftw_stock_date?>');return document.MM_returnValue" value="Accessories" /><br />
    <br />
    difference recorded:<br />
    P<?php echo number_format($acc_gab_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php if ($tiles_gab_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($acc_gab_stock_date));} else { echo 'No reocords';}?>
  </div>
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; height:160px; margin-left:20px;">
    <input name="tiles_ftw_button" type="button" class="imagebutton" id="tiles_ftw_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Tiles&branch=Francistown&date=1&date1=<?php echo $tiles_ftw_stock_date?>&date2=<?php echo $tiles_ftw_stock_date?>&gab_last_stock_date=<?php echo $tiles_gab_stock_date?>');return document.MM_returnValue" value="Tiles" />
    <br />
    <br />
     difference recorded:<br />
    P<?php echo number_format($tiles_ftw_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php if ($tiles_ftw_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($tiles_ftw_stock_date));} else { echo 'No reocords';}?>
  </div>
  
  <div class="page_inside_frame" style="width:125px; float:left; text-align:center; margin-left:20px;  height:160px;">
    <input name="acc_ftw_button" type="button" class="imagebutton" id="acc_ftw_button" onclick="MM_goToURL('parent','stockLoss.php?subCatSelect=Accessories&branch=Francistown&date=1&date1=<?php echo $acc_ftw_stock_date?>&date2=<?php echo $acc_ftw_stock_date?>&gab_last_stock_date=<?php echo $acc_gab_stock_date?>');return document.MM_returnValue" value="Accessories" /><br />
    <br />
    difference recorded:<br />
    P<?php echo number_format($acc_ftw_difference, 2, '.', ',') ?><br />
    <br /><br />
Last stock take:<br />
<?php if ($tiles_ftw_stock_date!='0000-00-00') {echo date("d-m-Y", strtotime($acc_ftw_stock_date));} else { echo 'No reocords';}?>
  </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;Gaborone:  &nbsp;&nbsp;
  <select name="gab_list_select" class="select200" id="gab_list_select" onchange="window.location.href= this.form.gab_list_select.options[this.form.gab_list_select.selectedIndex].value">
  <option value="stockLoss.php?subCatSelect=Cleaning materials&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">Cleaning materials</option>
    
    <option value="stockLoss.php?subCatSelect=Consumables&branch=Gaborone&date=1&date1=<?php echo $tiles_gab_stock_date?>&date2=<?php echo $tiles_gab_stock_date?>&ftw_last_stock_date=<?php echo $tiles_ftw_stock_date?>">Consumables</option>
    <option value="stockLoss.php?subCatSelect=Fuel&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">Fuel</option>
    <option value="stockLoss.php?subCatSelect=Lubricants&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">Lubricants</option>
    <option value="stockLoss.php?subCatSelect=Machine spares&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">Machine spares</option>
    <option value="stockLoss.php?subCatSelect=PPE&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">PPE</option>
    <option value="stockLoss.php?subCatSelect=Tools&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">Tools</option>
    <option value="stockLoss.php?subCatSelect=Welding & Engineering&branch=Gaborone&date=1&date1=<?php echo $gab_complete_stock_date?>&date2=<?php echo $gab_complete_stock_date?>&ftw_last_stock_date=<?php echo $ftw_complete_stock_date?>">Welding &amp; Engineering</option>
    <option value=" " selected="selected"> </option>
  </select>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Francistown:&nbsp;&nbsp;&nbsp;&nbsp;
<select name="ftw_list_select" class="select200" id="ftw_list_select" onchange="window.location.href= this.form.ftw_list_select.options[this.form.ftw_list_select.selectedIndex].value">
  <option value="stockLoss.php?subCatSelect=Cleaning materials&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Cleaning materials</option>
    
    <option value="stockLoss.php?subCatSelect=Consumables&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Consumables</option>
    <option value="stockLoss.php?subCatSelect=Fuel&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Fuel</option>
    <option value="stockLoss.php?subCatSelect=Lubricants&&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Lubricants</option>
    <option value="stockLoss.php?subCatSelect=Machine spares&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Machine spares</option>
    <option value="stockLoss.php?subCatSelect=PPE&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">PPE</option>
    <option value="stockLoss.php?subCatSelect=Tools&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Tools</option>
    <option value="stockLoss.php?subCatSelect=Welding & Engineering&branch=Francistown&date=1&date1=<?php echo $ftw_complete_stock_date?>&date2=<?php echo $ftw_complete_stock_date?>&gab_last_stock_date=<?php echo $gab_complete_stock_date?>">Welding &amp; Engineering</option>
    <option value=" " selected="selected"> </option>
  </select>
</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>