<?php
header("Content-type: text/html; charset=windows-1256");

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

include("config.inc.php");

$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 FC_RetailReport as loginaccess, print as printaccess, ExporttoExcel 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 ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
if ($ExporttoExcel==1)
	$ExporttoExcelStatus= 'button';
else
	$ExporttoExcelStatus= 'hidden';		


class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
	
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			echo "$jsClear";
			
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.clientdt[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}	

//Item Groups List
$querygroup=" select distinct group_code,group_name ".
			" from grouping where group_code in (select group_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
			" order by group_code";
$resultgroup = mysql_query($querygroup,$connection) or die(mysql_error());
$groupexist   = mysql_num_rows($resultgroup);
if ($groupexist == 0)
	$querygroup="select distinct group_code,group_name from grouping order by group_code";
$resultfromgroup=mysql_query($querygroup,$connection) or die(mysql_error());
$resulttogroup=mysql_query($querygroup,$connection) or die(mysql_error());

//Item SubGroups List
$querysubgroup= " select distinct subgroup_code, subgroup_name ".
				" from subgroup where subgroup_code in (select subgroup_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
				" order by subgroup_code";
$resultsubgroup = mysql_query($querysubgroup,$connection) or die(mysql_error());
$subgroupexist   = mysql_num_rows($resultsubgroup);
if ($subgroupexist == 0)
	$querysubgroup="select distinct subgroup_code,subgroup_name from subgroup order by subgroup_code";
$resultfromsubgroup=mysql_query($querysubgroup,$connection) or die(mysql_error());
$resulttosubgroup=mysql_query($querysubgroup,$connection) or die(mysql_error());



print <<< HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HERE;



//User Accounts List
$queryusers=" select distinct user_account, user_name ".
			" from ".$_SESSION['dbLabel'].".users ".
			" order by user_account ";
$resultusers = mysql_query($queryusers,$connection) or die(mysql_error());


//CashRegister List
$querycashregister= " select distinct cashregister_name as code, cashregister_name as name ".
					" from cashregister ".
					" order by cashregister_name ";
$resultcashregister = mysql_query($querycashregister,$connection) or die(mysql_error());

//Salesmen List
$querysalesman= " select distinct ledger_number as code, ledger_name as name ".
				" from salesmen ".
				" order by ledger_number ";
$resultsalesman = mysql_query($querysalesman,$connection) or die(mysql_error());

//Drivers List
$querydrivers= " select distinct ledger_number as code, ledger_name as name ".
			   " from clients where upper(client_type) = 'DRIVER' ".
			   " order by ledger_name ";
$resultdrivers = mysql_query($querydrivers,$connection) or die(mysql_error());


$querysetup ="select base1, base2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter ".
             " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter, ".
		  " ifNull(FI_RepRestrictWarehouse,0) As FI_RepRestrictWarehouse, ifNull(FI_ShowCostPrice,0) As FI_ShowCostPrice ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."') ";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Projects List
$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%') ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);	
if ($projectexist == 0 || $FI_RepRestrictProject == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";	  

$resultfromproject=mysql_query($queryproject,$connection) or die(mysql_error());
$resulttoproject  =mysql_query($queryproject,$connection) or die(mysql_error());


//Costcenter List
$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%') ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  
if ($costcentexist == 0 || $FI_RepRestrictCostcenter == 0)
    $querycostcent=" select distinct costcent_code, costcent_name from costcent order by costcent_code ";			  
	
$resultfromcostcent=mysql_query($querycostcent,$connection) or die(mysql_error());
$resulttocostcent  =mysql_query($querycostcent,$connection) or die(mysql_error());


//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}


//Warehouse List
$querywarehouse=" select distinct warehouse.warehouse_code, warehouse_name ".
				" from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk ".
				"                                         where user_account='".$_SESSION['useraccount']."' ".
				"                                         and (loginstk.warehouse_code is not null and loginstk.warehouse_code != '') ) ".
				" order by warehouse.warehouse_code";
$resultwh = mysql_query($querywarehouse,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);
if ($whexist == 0 || $FI_RepRestrictWarehouse == 0)
	$querywarehouse="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
	
$resultfromwarehouse=mysql_query($querywarehouse,$connection) or die(mysql_error());
//$resulttowarehouse  =mysql_query($querywarehouse,$connection) or die(mysql_error());


if ((!isset($fromproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1)
	$fromproject = $defaultproject;
if ((!isset($toproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1)
	$toproject = $defaultproject;
if ((!isset($fromcostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	$fromcostcent = $defaultcostcent;	
if ((!isset($tocostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	$tocostcent = $defaultcostcent;


if (empty($fromdate))	
	$fromdate = displayToday();
if (empty($todate))	
	$todate = displayToday();

if (empty($fromdate2))	
	$fromdate2 = displayToday();
if (empty($todate2))	
	$todate2 = displayToday();

if(empty($nbritems))
	$nbritems = 10;
	
print <<< HERE

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<script type="text/javascript" language="javascript">

function printPrev(printaccess,print){
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
	var vReportName = '';
  	
	var fromdate = document.form1.fromdate.value;
	var todate = document.form1.todate.value;
	var fromitem = document.form1.fromitem.value;
	var toitem = document.form1.toitem.value;
	var fromgroup = document.form1.fromgroup_code.value;
	var togroup = document.form1.togroup_code.value;
	var fromsubgroup = document.form1.fromsubgroup_code.value;
	var tosubgroup = document.form1.tosubgroup_code.value;
	var fromcategory = document.form1.fromcategory_code.value;
	var tocategory = document.form1.tocategory_code.value;
	
	var nbritems = document.form1.nbritems.value;
	
	for (var i=0; i < document.form1.printfile.length; i++)
	{
		if (document.form1.printfile[i].checked)
		{
			var fileval = document.form1.printfile[i].value;
		}
	}
	
	if(fileval == 1)
	vReportName = 'Rep_Sellingpricehistory.php';
	else if(fileval == 2)
	vReportName = 'Rep_MostSellingItems.php';
	else if(fileval == 3)
	vReportName = 'Rep_UnmovedItems.php';
	
	str = vReportName+'?fromdate='+fromdate+'&todate='+todate+'&fromitem='+fromitem+'&toitem='+toitem+'&fromgroup='+fromgroup+'&togroup='+togroup+'&fromsubgroup='+fromsubgroup
					+'&tosubgroup='+tosubgroup+'&fromcategory='+fromcategory+'&tocategory='+tocategory
					+'&nbritems='+nbritems+'&printaccess='+printaccess+'&print='+print;
	window.open(str);
}

function printExcel(){
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
	var vReportName = '';
  	
	var fromdate = document.form1.fromdate.value;
	var todate = document.form1.todate.value;
	var fromitem = document.form1.fromitem.value;
	var toitem = document.form1.toitem.value;
	var fromgroup = document.form1.fromgroup_code.value;
	var togroup = document.form1.togroup_code.value;
	var fromsubgroup = document.form1.fromsubgroup_code.value;
	var tosubgroup = document.form1.tosubgroup_code.value;
	
	var nbritems = document.form1.nbritems.value;
	
	for (var i=0; i < document.form1.printfile.length; i++)
	{
		if (document.form1.printfile[i].checked)
		{
			var fileval = document.form1.printfile[i].value;
		}
	}
	
	if(fileval == 1)
	vReportName = 'Exp_Sellingpricehistory.php';
	else if(fileval == 2)
	vReportName = 'Exp_MostSellingItems.php';
	else if(fileval == 3)
	vReportName = 'Exp_UnmovedItems.php';
	
	str = vReportName+'?fromdate='+fromdate+'&todate='+todate+'&fromitem='+fromitem+'&toitem='+toitem+'&fromgroup='+fromgroup+'&togroup='+togroup+'&fromsubgroup='+fromsubgroup+'&tosubgroup='+tosubgroup
					+'&nbritems='+nbritems;
	window.open(str);
}

function showlistitem(str){
	window.open('select_item.php?item='+str,'mywindow','width=900,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistgroups(str){
	window.open('List_Grouping.php?str='+str,'List_Grouping','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistsubgroups(str){
	window.open('List_SubGroup.php?str='+str,'List_SubGroup','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showlistcategory(str){
	window.open('List_Categories.php?str='+str,'List_SubGroup','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function printPrev2(printaccess,print){
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
	var vReportName = '';
  	
	var fromdate = document.form1.fromdate2.value;
	var todate = document.form1.todate2.value;
	var fromclient = document.form1.fromclient.value;
	var toclient = document.form1.toclient.value;
		
	var fileval = document.form1.printfile2.value;
	var topnbr = document.getElementById('topnbr').value;
	
	var fromproject = document.form1.fromproject.value;
	
	if(fileval == 1 || fileval == 2)
	vReportName = 'Rep_NoInvoiceClients.php';
		
	str = vReportName+'?fromdate='+fromdate+'&todate='+todate+'&fromclient='+fromclient+'&toclient='+toclient+'&fileval='+fileval+'&topnbr='+topnbr+'&fromproject='+fromproject+'&printaccess='+printaccess+'&print='+print;
	window.open(str);
}
function printExcel2(){
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
	var vReportName = '';
  	
	var fromdate = document.form1.fromdate2.value;
	var todate = document.form1.todate2.value;
	var fromclient = document.form1.fromclient.value;
	var toclient = document.form1.toclient.value;
		
	var fileval = document.form1.printfile2.value;
	var topnbr = document.getElementById('topnbr').value;
	
	var fromproject = document.form1.fromproject.value;
	
	if(fileval == 1 || fileval == 2)
	vReportName = 'Exp_NoInvoiceClients.php';
		
	str = vReportName+'?fromdate='+fromdate+'&todate='+todate+'&fromclient='+fromclient+'&toclient='+toclient+'&fileval='+fileval+'&topnbr='+topnbr+'&fromproject='+fromproject;
	window.open(str);
	
}
function showlistclient(str){

  window.open('select_client.php?item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistProject(){
	 window.open('List_SorProject.php?frm=38&item=1','mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function cgr7(){
x=document.form1;
document.form1.action="select_client.php?item=1";
document.form1.btncode1.submit();

}
function cgr8(){
x=document.form1;
document.form1.action="select_client.php?item=2";
document.form1.btncode2.submit();

}

function clearpage(i){
	var x = document.form1;
	if(i == 1){
		x.fromdate.value='';
		x.todate.value='';
		x.fromitem.value='';
		x.fromitemdesc.value='';
		x.toitem.value='';
		x.toitemdesc.value='';
		x.fromgroup_code.value='';
		x.fromgroup_name.value='';
		x.togroup_code.value='';
		x.togroup_name.value='';
		x.fromsubgroup_code.value='';
		x.fromsubgroup_name.value='';
		x.tosubgroup_code.value='';
		x.tosubgroup_name.value='';
		
		x.fromcategory_code.value='';
		x.fromcategory_name.value='';
		x.tocategory_code.value='';
		x.tocategory_name.value='';
		
		x.nbritems.value='';
		
	} else if(i == 2) {
		x.fromdate2.value='';
		x.todate2.value='';
		x.fromclient.value='';
		x.fromdesc.value='';
		x.toclient.value='';
		x.todesc.value='';
	}
	x.submit();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sales Viewer</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	color: #FF0000;
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
body {
	margin-top: 0px;
}
-->
</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
	<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
</head>
<body>
HERE;

echo "<form id='form1' name='form1' method='post' action='$_SERVER[PHP_SELF]'>
		<input type='hidden' name='HideMenu' value='$HideMenu'>";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
if ($HideMenu != 1) include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Sales Statistics </span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";


echo"<tr>
		<td  height='10'  valign='top' id='content-top2'> ";
		
echo "	<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='10'>&nbsp;</td>
				<td valign='middle' height='10' width='720px' align='left'>";
	

echo"	</td></tr></table>";
echo"</td></tr>";				

		
echo"<tr><td id='content-body'> ";
$tabs = new tabs("Stat");	
$tabs->start("Selling Items");
echo "<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		
echo '  <table height="200" border="0" align="center" valign="top" width="100%" ><tr height="20px"><td colspan="3">';

	echo" <button type='button' id='btnClear' name='btnClear' title='Clear'  onClick=\"clearpage(1);\"><span><span>Clear</span></span></button>";
	echo" <button type='button' id='btnPreview' name='btnPreview'  onClick=\"printPrev('".$printaccess."',0)\"; title='Preview'><span><span>Preview</span></span></button>";
	echo" <button type='button' id='btnPrint' name='btnPrint'  onClick=\"printPrev('".$printaccess."',1)\"; title='Print'><span><span>Print</span></span></button>";

	if ($ExporttoExcel==1){
		echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"printExcel()\"; title='Export Excel'><span><span>Export Excel</span></span></button>";

	}
echo "</td></tr>";	
//from to date
echo" <tr height='15'>";	  
echo"   <td width='5%' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></td> ";
echo" </tr>";
echo" <tr>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5'><span class='style8'>Form</span></td> ";
echo"   <td width='10%' bgcolor='#F5F5F5' ><span class='style8'>";
echo"      <input type='text' name='fromdate' value='$fromdate' maxlength='20' size='15'>";
echo"&nbsp;<A HREF=\"#\" onClick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>";
echo "<td width='50%' height='30px' rowspan='2' align='left' bgcolor='#F5F5F5'>
		<table><tr><td><span class='style8'><input type='radio' name='printfile' value='1' checked> Selling Price History</span></td></tr>
			  <tr><td><span class='style8'><input type='radio' name='printfile' value='2'> Top Selling Items 
				<input type='text' name='nbritems' id='nbritems' value='$nbritems' style='width:30px;' onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46) || (event.charCode >= 0 && event.charCode <= 31)'
					></span></td></tr>
			<tr><td><span class='style8'><input type='radio' name='printfile' value='3'> Unmoved Items</span></td></tr></table></td>";
echo" </tr>";

echo"<tr>";
echo"    <td  ><span class='style8'>To</span></td><td >  <input type='text' name='todate' value='$todate'  maxlength='20' size='15' style='margin-top:2px;'>";
echo"&nbsp;<A HREF=\"#\" onClick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>";
echo"</td></tr>";

echo" <tr>";
//item code
echo"   <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>Item Code / Description</span></td>";
echo "</tr>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  colspan='3' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromitem' type='text' id='fromitem' size='15' value='".$fromitem."' />
        <input name='fromitemdesc' type='text' id='fromitemdesc' size='35' value='".$fromitemdesc."' />
        <input name='btncode1' type='hidden' id='btncode1' value='...'  style='width:20px; height:20px; border:thin;' title='Select Item From' />
        </label>
		</span>
		<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' 
             onClick='showlistitem(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 
		</td>";
echo "</tr>";		
echo" <tr>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='toitem' type='text' id='toitem' size='15' value='".$toitem."' />
        <input name='toitemdesc' type='text' id='toitemdesc' size='35' value='".$toitemdesc."' />
        <input name='btncode2' type='hidden' id='btncode2' value='...'  style='width:20px; height:20px; border:thin;' title='Select Item To' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item To ' 
             onClick='showlistitem(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
echo" </tr>";

//group code
echo" <tr>";
echo"   <td colspan='3' bgcolor='#F5F5F5' align='left'><span class='style8'>Group Code</span></td>";
echo" </tr>";
echo" <tr>";
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  colspan='3' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
       <input type='text' name='fromgroup_code' id='fromgroup_code' value='$fromgroup_code' readonly size='15' >
        <input type='text' name='fromgroup_name' id='fromgroup_name' value='$fromgroup_name' readonly size='28' >
        <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" 
		onClick='showlistgroups(7); '  /></span></label>
		</td>";	
echo "</tr>";


echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
	    <td width='45%' colspan='3' bgcolor='#F5F5F5'> <span class='style8'><input type='text' name='togroup_code' id='togroup_code' value='$togroup_code' readonly size='15' >
		<input type='text' name='togroup_name' id='togroup_name' value='$togroup_name' readonly size='28' ></span>
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" 
		onClick='showlistgroups(8); '  /></span></label></td>";
echo "</tr>";

//subgroup code
echo" <tr>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Subgroup</span></td>";
echo" </tr>";	

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
	    <td width='45%' colspan='3' bgcolor='#F5F5F5'> <span class='style8'><input type='text' name='fromsubgroup_code' id='fromsubgroup_code' value='$fromsubgroup_code' readonly size='15' >
		<input type='text' name='fromsubgroup_name' id='fromsubgroup_name' value='$fromsubgroup_name' readonly size='25' ></span>
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" 
		onClick='showlistsubgroups(5); '  /></span></label></td>";
	
echo "</tr>";
echo" <tr>
	  <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
	    <td width='45%' colspan='3' bgcolor='#F5F5F5'> <span class='style8'><input type='text' name='tosubgroup_code' id='tosubgroup_code' value='$tosubgroup_code' readonly size='15' >
		<input type='text' name='tosubgroup_name' id='tosubgroup_name' value='$tosubgroup_name' readonly size='25' ></span>
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" 
		onClick='showlistsubgroups(6); '  /></span></label></td>";
echo "</tr>";

// jp category

//Category code
echo" <tr>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Category</span></td>";
echo" </tr>";	

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
	    <td width='45%' colspan='3' bgcolor='#F5F5F5'> <span class='style8'><input type='text' name='fromcategory_code' id='fromcategory_code' value='$fromcategory_code' readonly size='15' >
		<input type='text' name='fromcategory_name' id='fromcategory_name' value='$fromcategory_name' readonly size='25' ></span>
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" 
		onClick='showlistcategory(13); '  /></span></label></td>";
	
echo "</tr>"; 

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>to</span></td>
	    <td width='45%' colspan='3' bgcolor='#F5F5F5'> <span class='style8'><input type='text' name='tocategory_code' id='tocategory_code' value='$tocategory_code' readonly size='15' >
		<input type='text' name='tocategory_name' id='tocategory_name' value='$tocategory_name' readonly size='25' ></span>
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" 
		onClick='showlistcategory(14); '  /></span></label></td>";
	
echo "</tr>"; 
// End JP category
	
echo "</table></td></tr></table>";

$tabs->end();

$tabs->start("Clients List");

echo "<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		
echo '  <table height="200" border="0" align="center" valign="top" width="100%" ><tr height="20px"><td colspan="3">';

	echo" <button type='button' id='btnClear2' name='btnClear2' title='Clear' onClick=\"clearpage(2);\"><span><span>Clear</span></span></button>";
	echo" <button type='button' id='btnPreview2' name='btnPreview2'  onClick=\"printPrev2('".$printaccess."',0)\"; title='Preview'><span><span>Preview</span></span></button>";
	echo" <button type='button' id='btnPrint2' name='btnPrint2'  onClick=\"printPrev2('".$printaccess."',1)\"; title='Print'><span><span>Print</span></span></button>";

	if ($ExporttoExcel==1){
		echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"printExcel2()\"; title='Export Excel'><span><span>Export Excel</span></span></button>";

	}
echo "</td></tr>";	
//from to date
echo" <tr height='15'>";	  
echo"   <td width='5%' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></td> ";
echo" </tr>";
echo" <tr>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5'><span class='style8'>Form</span></td> ";
echo"   <td width='10%' bgcolor='#F5F5F5' ><span class='style8'>";
echo"      <input type='text' name='fromdate2' value='$fromdate2' maxlength='20' size='15'>";
echo"&nbsp;<A HREF=\"#\" onClick=\"displayCalendar(document.form1.fromdate2,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>";
echo "<td width='50%' height='30px' rowspan='2' align='left' bgcolor='#F5F5F5'>
		<table><tr><td><span class='style8'>
				<input type='radio' name='printfile2' value='1' checked> Show With No Invoices <br>
				<input type='radio' name='printfile2' value='2' > Top <input type='text' name='topnbr' id='topnbr' style='width:40px;'> Clients
			</span></td></tr>
		</table></td>";
echo" </tr>";

echo"<tr>";
echo"    <td  ><span class='style8'>To</span></td><td >  <input type='text' name='todate2' value='$todate2'  maxlength='20' size='15' style='margin-top:2px;'>";
echo"&nbsp;<A HREF=\"#\" onClick=\"displayCalendar(document.form1.todate2,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>";
echo"</td></tr>";
 
// client code
echo "<tr> <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Client Code/Description </span></td> </tr>";
echo "<tr height='15px'>
      <td align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
      <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>
        <label>
        <input name='fromclient' type='text' id='fromclient' size='15' value='$fromclient' >
		<input name='fromdesc' type='text' id='fromdesc' size='30' value='$fromdesc' >
		<input name='btncode1' type='hidden' id='btncode1' value='...' onclick='cgr7()' style='width:20px; height:20px; border:thin;' title='Select Client From' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client From ' 
             onClick='showlistclient(1);' ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>      
     </td>
	</tr> ";
echo "<tr height='15px'>
	   <td align='right' bgcolor='#F5F5F5'><span class='style8'><span class='style8'>To</span></td>
       <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>
        <label>
        <input name='toclient' type='text' id='toclient' size='15' value='$toclient' >
		<input name='todesc' type='text' id='todesc' size='30' value='$todesc' >
		<input name='btncode2' type='hidden' id='btncode2' value='...' onclick='cgr8()' style='width:20px; height:20px; border:thin;' title='Select Client To' />
        </label></span>
        <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client To ' 
        onClick='showlistclient(2);' ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>
	</tr>"; 
echo "<tr height='30px'> <td colspan='2' bgcolor='#F5F5F5'></td> </tr>";
// Project	
echo "<tr> <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Project Code/Description </span></td> </tr>";
echo "<tr height='15px'>
      <td align='right' bgcolor='#F5F5F5'><span class='style8'>Project</span></td>
      <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>
        <label>
        <input name='fromproject' type='text' id='fromproject' size='15' value='$fromproject' >
		<input name='fromprojectname' type='text' id='fromprojectname' size='30' value='$fromprojectname' >
		</label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client From ' 
             onClick='showlistProject();' ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>      
     </td>
	</tr> ";	
echo "</table></td></tr></table>";

$tabs->end();	
	
$tabs->run();
echo"   <tr height='30'><td align='center' id='content-bottom' ></td></tr>"; 
 echo"</table>
 
</form>
</body>
</html>";


//Return Date in DD/MM/YYYY format
function displayFromDate($data){
	return "01/01/".substr($data, 6, 4);		
}
//Return Today's Date in DD/MM/YYYY format
function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}
	  
?>