<?php


session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


$querylog="SELECT RA_StatisticsReport as loginaccess, ExporttoExcel, Print from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['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';
	

$printaccess=$Print;


$querysetup ="select base1, base2, if(DefaultBase=1, base1, base2) as defaultcurr from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);
$defaultcurr = $rowsetup[2];


// Setting Initial Values For Parameters
$querydate=" Select Date_Format(Min(Journal_date),'%d/%m/%Y') As DefaultFromDate, ".
           " Date_Format(Max(Journal_date),'%d/%m/%Y') As DefaultToDate, Date_Format(NOW(),'%d/%m/%Y') As DefaultAgingDate ".
		   " From JournalDt ";
$resultdate=mysql_query($querydate,$connection) or die(mysql_error());
$rowdate=mysql_fetch_row($resultdate);

if (!isset($fromdate))  $fromdate = $rowdate[0];
if (!isset($todate))    $todate = $rowdate[1];
if (!isset($agingdate)) $agingdate = $rowdate[2];
  

	

print <<< HERE
<!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=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<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)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
	
	var x = document.form1;
  	
	for (var i=0; i < x.currency.length; i++)
	{
		if (x.currency[i].checked)
		{
			var varcurrency = x.currency[i].value;
		}
	}
  
	varprtrecords = 0;
	if (x.prtrecords.checked)  varprtrecords = 1;
 
	varfromdate     = x.fromdate.value;
	vartodate       = x.todate.value;
	
	varTransPV = 0; varTransRV = 0; varTransDV = 0; varTransCV = 0; 
	varTransSI = 0; varTransSR = 0; varTransJS = 0; varTransJP = 0;
	varTransPI = 0; varTransPR = 0;
	if (x.TransPV.checked)  varTransPV = 1;
	if (x.TransRV.checked)  varTransRV = 1;
	if (x.TransDV.checked)  varTransDV = 1;
	if (x.TransCV.checked)  varTransCV = 1;
	if (x.TransSI.checked)  varTransSI = 1;
	if (x.TransSR.checked)  varTransSR = 1;
	if (x.TransJS.checked)  varTransJS = 1;
	if (x.TransJP.checked)  varTransJP = 1;
	if (x.TransPI.checked)  varTransPI = 1;
	if (x.TransPR.checked)  varTransPR = 1;
	
  
	varreport = '';
	varreport = 'Rep_StatisticsReport.php';
	
	str = varreport +'?fromdate='+varfromdate+'&todate='+vartodate+'&curr='+varcurrency+'&TransPV='+varTransPV+'&TransRV='+varTransRV
					+'&TransDV='+varTransDV+'&TransCV='+varTransCV+'&TransSI='+varTransSI+'&TransSR='+varTransSR+'&TransJS='+varTransJS
					+'&TransJP='+varTransJP+'&TransPI='+varTransPI+'&TransPR='+varTransPR+'&prtrecords='+varprtrecords;
				 
	if (printaccess==1) 
		window.open(str);
	else
		window.open(str,"Report", "width=900,height=600,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
}


function ExportExcel()
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
	
	var x = document.form1;
  	
	for (var i=0; i < x.currency.length; i++)
	{
		if (x.currency[i].checked)
		{
			var varcurrency = x.currency[i].value;
		}
	}
  
  
    varprtrecords = 0;
	if (x.prtrecords.checked)  varprtrecords = 1;
	
	varfromdate     = x.fromdate.value;
	vartodate       = x.todate.value;
	
	varTransPV = 0; varTransRV = 0; varTransDV = 0; varTransCV = 0; 
	varTransSI = 0; varTransSR = 0; varTransJS = 0; varTransJP = 0;
	varTransPI = 0; varTransPR = 0;
	if (x.TransPV.checked)  varTransPV = 1;
	if (x.TransRV.checked)  varTransRV = 1;
	if (x.TransDV.checked)  varTransDV = 1;
	if (x.TransCV.checked)  varTransCV = 1;
	if (x.TransSI.checked)  varTransSI = 1;
	if (x.TransSR.checked)  varTransSR = 1;
	if (x.TransJS.checked)  varTransJS = 1;
	if (x.TransJP.checked)  varTransJP = 1;
	if (x.TransPI.checked)  varTransPI = 1;
	if (x.TransPR.checked)  varTransPR = 1;
	
	varreport = '';
	varreport = 'Exp_StatisticsReport.php';
	
	str = varreport +'?fromdate='+varfromdate+'&todate='+vartodate+'&curr='+varcurrency+'&TransPV='+varTransPV+'&TransRV='+varTransRV
					+'&TransDV='+varTransDV+'&TransCV='+varTransCV+'&TransSI='+varTransSI+'&TransSR='+varTransSR+'&TransJS='+varTransJS
					+'&TransJP='+varTransJP+'&TransPI='+varTransPI+'&TransPR='+varTransPR+'&prtrecords='+varprtrecords;

	window.open(str);

}


function SelectTransOptions()
{
	var x = document.form1;
	
	if (x.alltrans.checked) {
		x.TransPV.checked= true;
		x.TransRV.checked= true;
		x.TransDV.checked= true;
		x.TransCV.checked= true;
		x.TransSI.checked= true;
		x.TransSR.checked= true;
		x.TransJS.checked= true;
		x.TransJP.checked= true;
		x.TransPI.checked= true;
		x.TransPR.checked= true;
	} else {
		x.TransPV.checked= false;
		x.TransRV.checked= false;
		x.TransDV.checked= false;
		x.TransCV.checked= false;
		x.TransSI.checked= false;
		x.TransSR.checked= false;
		x.TransJS.checked= false;
		x.TransJP.checked= false;
		x.TransPI.checked= false;
		x.TransPR.checked= false;
	}
}

function ClearPage() {
	x = document.form1;
	
	window.location ='Form_StatisticsReport.php';
	
}



-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Statistics Report</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='templateid' value='$templateid'>";
		
echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
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'>Statistics Report</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
		
	echo" <button type='reset' id='btnClear' name='btnClear'  title='Clear'><span><span>Clear</span></span></button>";
		echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"PrintPrev('".$printaccess."')\"; title='Preview'><span><span>Preview</span></span></button>";

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

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

		
echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";						
	
echo '  <table border="0" align="center" valign="top" width="100%">';


echo" <tr>";	  
echo"   <td width='20%' height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <label><input type='checkbox' name='alltrans' id='alltrans' value='1' onclick='SelectTransOptions();' checked/>All Movement Option</label></span></td>";
echo"   <td width='20%' height='19' colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></td>";
echo"   <td width='15%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'> Currency</span></td>";
echo"   <td width='45%' height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>Options </span></td>";
echo" </tr>";

echo" <tr height='25'>";	  
echo"   <td width='20%' rowspan='3' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <label><input type='checkbox' name='TransPV' id='TransPV' value='PV' checked/>Payment</label><br>";
echo"      <label><input type='checkbox' name='TransRV' id='TransRV' value='RV' checked/>Receipt</label><br>";
echo"      <label><input type='checkbox' name='TransDV' id='TransDV' value='DV' checked/>Debit Note</label><br>";
echo"      <label><input type='checkbox' name='TransCV' id='TransCV' value='CV' checked/>Credit Note</label><br>";
echo"      <label><input type='checkbox' name='TransSI' id='TransSI' value='SI' checked/>Sales</label><br>";
echo"      <label><input type='checkbox' name='TransSR' id='TransSR' value='SR' checked/>Return Sales</label><br>";
echo"      <label><input type='checkbox' name='TransJS' id='TransJS' value='JS' checked/>Sales JV</label><br>";
echo"      <label><input type='checkbox' name='TransJP' id='TransJP' value='JP' checked/>Purchase JV</label><br>";
echo"      <label><input type='checkbox' name='TransPI' id='TransPI' value='PI' checked/>Purchase</label><br>";
echo"      <label><input type='checkbox' name='TransPR' id='TransPR' value='PR' checked/>Return Purchase</label>";
echo"	</span></td>";

echo"   <td width='5%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='15%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"      <input type='text' name='fromdate' value='$fromdate' maxlength='10' size='10'>";
echo"      <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></td>";

echo"   <td width='15%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[0]' "; if($defaultcurr == $rowsetup[0]) echo "checked"; echo">$rowsetup[0]</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[1]' "; if($defaultcurr == $rowsetup[1]) echo "checked"; echo">$rowsetup[1]</label></span></td>";


echo"   <td width='45%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <label><input type='checkbox' name='prtrecords' id='prtrecords' value='1' />Print Total Records</label>";
echo"   </span></td>";
echo" </tr>";

echo" <tr height='25'>";
echo"   <td width='5%' valign='top' bgcolor='#F5F5F5'><span class='style8'>To</span></td>";
echo"   <td width='15%' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <input type='text' name='todate' value='$todate'  maxlength='10' size='10'>";
echo"      <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></td>";
echo" </tr>";
    
echo" <tr height='120'>";
echo"   <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";	
echo" </tr>";
/*
echo" 
    <tr height='30'>
      <td colspan='6' align='center' bgcolor='#F5F5F5'>
	  <input type='button' name='btnClear' value='Clear' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"ClearPage()\"; />
	  <input type='button' name='btnPreview' id='btnPreview' value='Preview' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"PrintPrev('".$printaccess."')\"; />
	  <input type='".$ExporttoExcelStatus."' name='btnExcel' id='btnExcel' value='Export Excel' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"ExportExcel()\";/>	  
      </td>
    </tr>*/
		echo"   </table></td></tr>"; 
	echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>"; 
 echo" </table>
 
</form>
</body>
</html>";

?>