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

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

print <<< HERE
<HTML>
<HEAD>
<TITLE> Uncounted Items </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");

$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 ($printaccess==0 or $printaccess=='')
echo'<BODY oncontextmenu="return false;">';
else
echo'<BODY>';
  
$querysetup="select grid_color1,grid_color2, DecimalBase, DecimalBase1, DecimalBase2, report_color1, report_color2, ifNull(InventoryRMaskqty,0) As InventoryRMaskqty, Base1, Base2, Company_Name As CompanyName from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultsetup)){
  extract($rows);
}
 



$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);
if (empty($existqty))     $existqty = 0;
if($existqty == 1) { 
 $layout='portrait';
 $tbwidth='680px';
 $descWidth='195';
 } else {
 $layout='landscape';
 $tbwidth='100%';
 $descWidth='400';
}
print <<< HERE
<table width="$tbwidth" border="0" align="left" >
HERE;
	//echo "<thead><tr><td align='left'>";
	
	//ShowReportHeader('Inventory',$layout, $connection);
	
	//echo"</td></tr></thead><tbody>";
 
	ShowReportHeader('Uncounted Report','portrait', $connection);
 

if ($cur == 'currency1'){
   $cur='null';  
   $displaycur = '';
}   
else {
   $displaycur = $cur;
   $cur="'".$cur."'";
}  

// var_dump($_GET);
$SelectedOptions = "Filter by: <br>";
if ($fromdate != '')      	$SelectedOptions .= "-> Date From: ". $fromdate . "  To: ". $todate ."<br>";	    
 
if (!empty($fromdate))   $fromdate = explodeword($fromdate);
if (!empty($todate))     $todate = explodeword($todate);  

   
$fromdate	   = GetSQLValueString($fromdate, 'date');
$todate        = GetSQLValueString($todate, 'date');    

print <<<HERE

<tr><td>
<table class="report-master"  border="0" align="left" style='table-layout:fixed;clear:left;'>
<col width=100>
<tr><td>&nbsp;</td>
  <td  valign='top' width=100%><b>$SelectedOptions</b></td>
</tr>
<tr height='5'><td><h5></td></tr>
</table></td></tr>

HERE;


echo "<tr><td><table  border='0' width='' class='report-master' style='clear:left;' align='left' cellpadding='0' cellspacing='0'>";
echo"<thead><tr><td>";	

echo "<table  border='0' width='320' align='left' class='master' style='table-layout:fixed' cellspacing=0>";
	echo"<col width=100>"; // item_code #
	echo"<col width=200>"; // item_desc
	echo"<col width=200>"; // Existing quantity  
echo"</thead>";
//echo"<tr><td><hr width='100%' color='black' size='2'></td></tr>";
 
$query = "SELECT
			item_code,
			Item_Description,
			ifnull( get_quantityexists ( item_code, '', now(), NULL, '', '', '' ), 0 ) AS X 
		FROM
			items
		where   
			item_code NOT IN ( SELECT DISTINCT item_code FROM stocktakedt WHERE stocktake_date BETWEEN concat($fromdate,' 00:00:00') AND concat($todate, ' 23:59:59') )
		HAVING
			X > 0";

  //echo "<BR>".$query;exit;
$col= 0;
$col1= 0;
$col2= 0;
$result=mysql_query($query, $connection) or die(mysql_error());

while($rows=mysql_fetch_array($result)){
	 
		if($col2%2==0){
			$colorX = "style='background-color:".$report_color1."'";
		}else{
			$colorX = "style='background-color:".$report_color2."'";
		}
	 
	echo"<tr $colorX>";
    echo"<td  align = 'left'> <span class='style1'>". $rows['item_code']  ."</span></td>";   
    echo"<td  align = 'left'> <span class='style1'>". $rows['Item_Description'] ."</span></td>"; 
    echo"<td  align = 'left'> <span class='style1'>". $rows['X'] ."</span></td>"; 
    echo"</tr>";
	  
	$col2++; 
	$curType = $rows['CylType'];
}
 

function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}



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

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

?>