<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

if($exp == 1){
	$filename = "Rep_InventoryLite".date('Ymd').".xls";
	header("Content-Disposition:attachement;filename=\"$filename\"");
	header("Content-Type:application/vnd.ms-excel");
}

print <<< HERE
<HTML>
<HEAD>
<TITLE> Lite Inventory Report </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<style type="text/css">
/*
table.params td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                      }				 
table.master td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }
				 
table.master td.sr  { font-size: 10px; 
					  font-style: italic; 
                      font-family:Times-New-Roman;
                    }

table.master td.grouplevel1 { font-size: 14px; 
							  font-weight: bold;
                              font-family:Times-New-Roman;
						      color: #0000FF;
							  background-color: #F0F0F0;
                            }
table.master td.grouplevel2 { font-size: 14px; 
                              font-family:Times-New-Roman;
						      color: #FF0000;
							  background-color: #F0F0F0;
                            }	
table.master td.grouplevel3 { font-size: 13px; 
							  font-style: italic;
                              font-family:Times-New-Roman;
						      color: #336600;
							  background-color: #F0F0F0;
                            }					
					
table.totals tr.summary { font-size: 13px; 
                          font-weight: bold;
                          font-family:Times-New-Roman;
						  background-color: #F0F0F0;
                        }					   

table.totals tr.grouplevel1total { font-size: 14px; 
								   font-weight: bold;
								   font-family:Times-New-Roman;
								   color: #0000FF;
								   background-color: #F0F0F0;
								 }				 
table.totals tr.grouplevel2total { font-size: 14px; 
							       font-family:Times-New-Roman;
							       color: #FF0000;
							       background-color: #F0F0F0;
						         }										 
table.totals tr.grouplevel3total { font-size: 13px; 
							       font-style: italic;
							       font-family:Times-New-Roman;
							       color: #336600;
							       background-color: #F0F0F0;
						          }						   				 
*/
</style>
</HEAD>

HERE;



include("config.inc.php");
include 'function.inc.php';

//Set Time Execution For the Report
//ini_set('max_execution_time', $config['ReportTimeExecution']);
set_time_limit(0);

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
$querylog="SELECT print as printaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

if (!empty($fromdate))   $fromdate = explodeword2($fromdate);


if ($printaccess==0 or $printaccess=='')
echo'<BODY oncontextmenu="return false;">';
else
echo'<BODY>';

echo "<table border='0' width='720px' align='left' class='report-master' style='table-layout:fixed' cellspacing='0'>
		<colgroup> 
			<col width='320px'>
			<col width='200px'>
			<col width='100px'>
			<col width='100px'>
		</colgroup>
		<tr>
			<th>Item code</th>
			<th>Warehouse</th>
			<th>Existing Qty</th>
			<th>Cost</th>
		</tr>";
		
		 

$queryInvLite= "select concat( stktransaction.item_code,' - ',item_description),warehouse_code,sum(quantityproduceIn-Quantityproduceout+quantityentered-quantitydelivered) as QtyExist,
meancostcur(stktransaction.item_code,'$fromdate',1,'NGN','NGN') as Cost
from stktransaction,items  where stktransaction.item_code=items.item_code group by stktransaction.item_Code,warehouse_code ";
//echo "<BR>".$query;
$cs = 0;
$resultInvLite=mysql_query($queryInvLite,$connection) or die(mysql_error());
while($rowsInvLite=mysql_fetch_array($resultInvLite)){
	if ($cs % 2 == 1 ) $bgColor = '#ABD4F1'; else $bgColor = '#FFFFFF';
		echo"
		<tr>
			<td colspan = 4 >
				<table border='0' width='720px' align='left' class= 'group' style ='background-color:$bgColor;'>
					<col width='320px'>
					<col width='200px'>
					<col width='100px'>
					<col width='100px'>
					<tr>
						<td> $rowsInvLite[0]</td>
						<td> $rowsInvLite[1]</td>
						<td> $rowsInvLite[2]</td>
						<td>".number_format($rowsInvLite[3], 2 )."</td>
					</tr>
				</table>
			</td>
		</tr>";
		$cs++;
}
	

if ($printaccess==1)
print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;

?>