<?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 RI_SalesOrderReport as loginaccess, Print, ExporttoExcel 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;


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

HERE;
//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);
}


$querysalessetup="select Salesttc from salessetup";
$resultsalessetup=mysql_query($querysalessetup,$connection) or die(mysql_error());
while($rowssalessetup=mysql_fetch_array($resultsalessetup)){
  extract($rowssalessetup);
}

$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];


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

print <<< HERE

<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 MoveLevel12(option) {
	var ob = document.form1.availgroupby;
	var leng = ob.options.length;
	
	var vSelectedOptionValue='';
	var vSelectedOptionName='';
	var vSelectedCount=0;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	while (ob.selectedIndex != -1)
    {
        if (ob.selectedIndex != -1) {
			vSelectedCount = vSelectedCount + 1;
			vSelectedOptionName  = ob.options[ob.selectedIndex].text;
			vSelectedOptionValue = ob.options[ob.selectedIndex].value;
		}	
        ob.options[ob.selectedIndex].selected = false;
    }

	if (vSelectedCount == 1) {
		if (option == 1) {
			document.form1.groupbylevel1name.value  = vSelectedOptionName;
			document.form1.groupbylevel1value.value = vSelectedOptionValue;
		}	
		else {
			document.form1.groupbylevel2name.value  = vSelectedOptionName;
			document.form1.groupbylevel2value.value = vSelectedOptionValue;
		}	
	}	
	else
		alert ('Not allowed multi selection for Level 1 and 2');
		
	
}

function RemoveLevel12(option) {
	var x = document.form1;
	
	if (option == 1) {
		x.groupbylevel1name.value = '';
		x.groupbylevel1value.value = '';
	}	
	else {
		x.groupbylevel2name.value = '';
		x.groupbylevel2value.value = '';
	}	
}

function MoveLevel3() {
	var ob = document.form1.availgroupby;
	var leng = ob.options.length;
	var TargetElement = document.form1.assigngroupby.options;
	
	var vExists = 0;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	if(TargetElement[0] != null) {
		if (TargetElement[0].value=='') 
			TargetElement[0] = null;
	}	

		
	while (ob.selectedIndex != -1)
    {  
        if (ob.selectedIndex != -1) {
		
			vExists = 0;
			for(i=0; i < TargetElement.length; i++) {
				if (TargetElement[i].value == ob.options[ob.selectedIndex].value)
					vExists = 1;
			}
			
			if (vExists == 0)
				TargetElement[TargetElement.length] = new Option(ob.options[ob.selectedIndex].text, ob.options[ob.selectedIndex].value);
		}	  

		ob.options[ob.selectedIndex].selected = false;
    }

	
}

function RemoveLevel3() {
	var ob = document.form1.assigngroupby;
	var leng = ob.options.length;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	while (ob.selectedIndex != -1)
    {  
        if (ob.selectedIndex != -1) 
			  ob.options[ob.selectedIndex] = null;
    }
	
}



function PrintPrev(printaccess)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
  
	for (var i=0; i < document.form1.masterby.length; i++)
	{
		if (document.form1.masterby[i].checked)
		{
			var varmasterby = document.form1.masterby[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.currency.length; i++)
	{
		if (document.form1.currency[i].checked)
		{
			var varcurrency = document.form1.currency[i].value;
		}
	}
	
	for (var i=0; i < document.form1.confirm.length; i++)
	{
		if (document.form1.confirm[i].checked)
		{
			var varconfirm = document.form1.confirm[i].value;
		}
	}
  
  
    
	//Getting Group By Levels 1 and 3
	vargroupby1   = document.form1.groupbylevel1value.value;
	vargroupby2   = document.form1.groupbylevel2value.value;
  
	//Getting Assigngroupby Values for level 3
	var ob = document.form1.assigngroupby;
	var vargroupby3 = '';
	for (var i = 0; i < ob.options.length; i++) {
		if (vargroupby3.length > 0)
			vargroupby3 += ",";
			
		vargroupby3 += ob.options[i].value;
	}
  
	// If No Group By Option Selected
	if (vargroupby3 == '') vargroupby3 = 1;

	 
	varprtdt = 0;
	if (document.form1.prtdt.checked)
		varprtdt = 1;		
	
	//If No Group By Option Selected	
	if (vargroupby3 == 1 && vargroupby1 == '' && vargroupby2 == '')
		varprtdt = 1;
	
	varprtsubdt = 0;
	if (document.form1.prtsubdt.checked)
		varprtsubdt = 1;			
	
	varprtpend = 0;
	if (document.form1.prtpend.checked)
		varprtpend = 1;

	varpricettc = 0;
	if(document.getElementById('pricettc')){
		if (document.form1.pricettc.checked )
			varpricettc = 1;
	}
	

  
	varfromdate   = document.form1.fromdate.value;
	vartodate     = document.form1.todate.value;
	varfromitem   = document.form1.fromitem.value;
	vartoitem     = document.form1.toitem.value;
	varfromgrp    = document.form1.fromgroup.value;
	vartogrp      = document.form1.togroup.value;
	varfromsubgrp = document.form1.fromsubgroup.value;
	vartosubgrp   = document.form1.tosubgroup.value;
	varfromprj    = document.form1.fromproject.value;
	varfromcst    = document.form1.fromcostcent.value;
	varfromclient    = document.form1.fromclient.value;
	vartoclient      = document.form1.toclient.value;
	varfromsalesman  = document.form1.fromsalesman.value;
	vartosalesman    = document.form1.tosalesman.value;
	varfromwarehouse = document.form1.fromwarehouse.value;
  
  str =  'Rep_SalesOrder.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromitem='+varfromitem+'&toitem='+vartoitem
        +'&fromclient='+varfromclient+'&toclient='+vartoclient+'&fromsalesman='+varfromsalesman+'&tosalesman='+vartosalesman
		+'&fromgroup='+varfromgrp+'&togroup='+vartogrp+'&fromsubgroup='+varfromsubgrp+'&tosubgroup='+vartosubgrp
		+'&fromproject='+varfromprj+'&fromcostcent='+varfromcst+'&fromwarehouse='+varfromwarehouse+'&curr='+varcurrency
		+'&groupby1='+vargroupby1+'&groupby2='+vargroupby2+'&groupby3='+vargroupby3+'&masterby='+varmasterby
		+'&prtdt='+varprtdt+'&prtsubdt='+varprtsubdt+'&prtpend='+varprtpend+'&pricettc='+varpricettc+'&confirm='+varconfirm;
		   
  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='';
  	
	for (var i=0; i < document.form1.masterby.length; i++)
	{
		if (document.form1.masterby[i].checked)
		{
			var varmasterby = document.form1.masterby[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.currency.length; i++)
	{
		if (document.form1.currency[i].checked)
		{
			var varcurrency = document.form1.currency[i].value;
		}
	}
  
	for (var i=0; i < document.form1.confirm.length; i++)
	{
		if (document.form1.confirm[i].checked)
		{
			var varconfirm = document.form1.confirm[i].value;
		}
	}
    
	//Getting Group By Levels 1 and 3
	vargroupby1   = document.form1.groupbylevel1value.value;
	vargroupby2   = document.form1.groupbylevel2value.value;
  
	//Getting Assigngroupby Values for level 3
	var ob = document.form1.assigngroupby;
	var vargroupby3 = '';
	for (var i = 0; i < ob.options.length; i++) {
		if (vargroupby3.length > 0)
			vargroupby3 += ",";
			
		vargroupby3 += ob.options[i].value;
	}
  
	// If No Group By Option Selected
	if (vargroupby3 == '') vargroupby3 = 1;

	 
	varprtdt = 0;
	if (document.form1.prtdt.checked)
		varprtdt = 1;		
	
	//If No Group By Option Selected	
	if (vargroupby3 == 1 && vargroupby1 == '' && vargroupby2 == '')
		varprtdt = 1;
	
	varprtsubdt = 0;
	if (document.form1.prtsubdt.checked)
		varprtsubdt = 1;			
	
	varprtpend = 0;
	if (document.form1.prtpend.checked)
		varprtpend = 1;

	varpricettc = 0;
	if(document.getElementById('pricettc')){
		if (document.form1.pricettc.checked)
			varpricettc = 1;
	}
	

  
	varfromdate   = document.form1.fromdate.value;
	vartodate     = document.form1.todate.value;
	varfromitem   = document.form1.fromitem.value;
	vartoitem     = document.form1.toitem.value;
	varfromgrp    = document.form1.fromgroup.value;
	vartogrp      = document.form1.togroup.value;
	varfromsubgrp = document.form1.fromsubgroup.value;
	vartosubgrp   = document.form1.tosubgroup.value;
	varfromprj    = document.form1.fromproject.value;
	varfromcst    = document.form1.fromcostcent.value;
	varfromclient    = document.form1.fromclient.value;
	vartoclient      = document.form1.toclient.value;
	varfromsalesman  = document.form1.fromsalesman.value;
	vartosalesman    = document.form1.tosalesman.value;
	varfromwarehouse = document.form1.fromwarehouse.value;
    
	str =   'Exp_SalesOrder.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromitem='+varfromitem+'&toitem='+vartoitem
           +'&fromclient='+varfromclient+'&toclient='+vartoclient+'&fromsalesman='+varfromsalesman+'&tosalesman='+vartosalesman
		   +'&fromgroup='+varfromgrp+'&togroup='+vartogrp+'&fromsubgroup='+varfromsubgrp+'&tosubgroup='+vartosubgrp
		   +'&fromproject='+varfromprj+'&fromcostcent='+varfromcst+'&fromwarehouse='+varfromwarehouse+'&curr='+varcurrency
		   +'&groupby1='+vargroupby1+'&groupby2='+vargroupby2+'&groupby3='+vargroupby3+'&masterby='+varmasterby
		   +'&prtdt='+varprtdt+'&prtsubdt='+varprtsubdt+'&prtpend='+varprtpend+'&pricettc='+varpricettc+'&confirm='+varconfirm;
		   
	window.open(str);
  
}




function CheckPrintDetail() {
    var x= document.form1;
	if (x.prtdt.checked == true) {
	    x.prtsubdt.disabled = false;
		x.prtsubdt.checked  = true;
	}  
	else { 
	    x.prtsubdt.disabled = true;
		x.prtsubdt.checked  = false;
	}
}

function LoadOptions() {
	x = document.form1;
    win = window.open('List_ReportsOptionsTemplates.php?formname=salesorder', 'List_ReportsOptionsTemplates', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1040,height=450,top=100,left=0');		
	win.creator = self;
	win.focus();		

}

function SelectOptions() {
	x = document.form1;
	vTemplateId = x.templateid.value;
	
    win = window.open('Form_ReportsOptions.php?isseloption=1&templateid='+vTemplateId+'&formname=salesorder', 'Form_ReportsOptions', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1200,height=550,top=50,left=0');		
	win.creator = self;
	win.focus();		

}



function ClearPage() {
	x = document.form1;
	
	//x.templateid.value = '';
	//x.action='Form_SorderReport.php';
	//x.submit();
	
	window.location ='Form_SorderReport.php';
	
}

function AddOption(selectId, text, value) {
	var ob = document.form1.assigngroupby;
	var i = ob.options.length;
	var o = new Option(text,value);
	ob.options[i] = o;
	
}

function RemoveOption(selectId) {
	var ob = document.form1.assigngroupby;
	
	//Empty Assigngroupby Values
	for (var k=0; k < ob.options.length; k++) {
		ob.options[k].selected = true;
	}
	
	while (ob.selectedIndex != -1)
	{  
		if (ob.selectedIndex != -1) 
		  ob.options[ob.selectedIndex] = null;
	}
	

}


-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sales Order 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=''>
		<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'>Sales Order 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='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' 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" <button type='button' id='btnLoadOptions' name='btnLoadOptions' onClick=\"LoadOptions()\"; title='Load Template'><span><span>Load Options</span></span></button>";  
	echo" <button type='button' id='btnSelectOptions' name='btnSelectOptions' onClick=\"SelectOptions()\"; title='Select Options'><span><span>Select Options</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 height="534" border="0" align="center" width="100%">';


//Load Reports Options Template
if ($templateid != '') {
	$querytemplate = " Select Groupby_Level1Value, Groupby_Level2Value, Groupby_Level3Value, Groupby_Level1Name, Groupby_Level2Name, Groupby_Level3Name, ".
					 " JournalType_alltypes, JournalType_exclude, JournalType_types,  FromLedger_Number, ToLedger_Number, FromClient_Code, ToClient_Code, ".
					 " FromSupplier_Code, ToSupplier_Code, FromSalesman_Code, ToSalesman_Code, FromItem_Code, ToItem_Code, FromWarehouse_Code, ToWarehouse_Code, ".
					 " FromGroup_Code, ToGroup_Code, FromSubgroup_Code, ToSubgroup_Code, FromProject_Code, ToProject_Code, FromMasterProject_Code, ToMasterProject_Code, ".
					 " FromCostcent_Code, ToCostcent_Code, FromMasterCostcent_Code, ToMasterCostcent_Code, FromArea_Code, ToArea_Code  ".
					 " From ReportsOptions_Templates ".
					 " Where ReportsOptions_Templates.User_Account = '".$HTTP_SESSION_VARS['useraccount']."' ".
					 " And   Template_Id = '".$templateid."'";
	//echo $querytemplate;			   
	$resulttemplate=mysql_query($querytemplate,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resulttemplate)){
	  extract($rows);
	}			   
	
	$groupbylevel1value = $Groupby_Level1Value;
	$groupbylevel2value = $Groupby_Level2Value;
	$groupbylevel3value = $Groupby_Level3Value;
	$groupbylevel1name  = $Groupby_Level1Name;
	$groupbylevel2name  = $Groupby_Level2Name;
	$groupbylevel3name  = $Groupby_Level3Name;
	
	$fromitem     = $FromItem_Code;
	$toitem       = $ToItem_Code;
	$fromgroup    = $FromGroup_Code;
	$togroup      = $ToGroup_Code;
	$fromsubgroup = $FromSubgroup_Code;
	$tosubgroup   = $ToSubgroup_Code;
	$fromproject  = $FromProject_Code;
	$fromcostcent = $FromCostcent_Code;
	
	$fromclient    = $FromClient_Code;
	$toclient      = $ToClient_Code;
	$fromsalesman  = $FromSalesman_Code;
	$tosalesman    = $ToSalesman_Code;
	$fromwarehouse = $FromWarehouse_Code;

	//$reportoptions = "Group by: ".$Groupby_Level1Name.",".$Groupby_Level2Name.",".$Groupby_Level3Name ."\n" . "Filter by: \n";
	$reportoptions = "Group by:  ";
	if ($Groupby_Level1Name != '' ) $reportoptions = $reportoptions . $Groupby_Level1Name.", ";
	if ($Groupby_Level2Name != '' ) $reportoptions = $reportoptions . $Groupby_Level2Name.", ";
	if ($Groupby_Level3Name != '' ) $reportoptions = $reportoptions . $Groupby_Level3Name.", ";
	$reportoptions = substr($reportoptions, 0, strlen($reportoptions)-2) . "\n" . "Filter by: \n";
	
	if ($FromItem_Code != '')      $reportoptions .= "-> Item From: ". $FromItem_Code . "  To: ". $ToItem_Code ."\n";
	if ($FromGroup_Code != '')     $reportoptions .= "-> Group From: ". $FromGroup_Code . "  To: ". $ToGroup_Code ."\n";
	if ($FromSubgroup_Code != '')  $reportoptions .= "-> SubGroup From: ". $FromSubgroup_Code . "  To: ". $ToSubgroup_Code ."\n";
	if ($FromProject_Code != '')   $reportoptions .= "-> Project From: ". $FromProject_Code . "\n";
	if ($FromCostcent_Code != '')  $reportoptions .= "-> Costcent From: ". $FromCostcent_Code . "\n";
	if ($FromClient_Code != '')    $reportoptions .= "-> Client From: ". $FromClient_Code . "  To: ". $ToClient_Code ."\n";
	if ($FromSalesman_Code != '')  $reportoptions .= "-> Salesman From: ". $FromSalesman_Code . "  To: ". $ToSalesman_Code ."\n";
	if ($FromWarehouse_Code != '') $reportoptions .= "-> Warehouse From: ". $FromWarehouse_Code . "\n";
	
}
echo" <tr>";	  
echo"   <td width='17%' height='19' colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></td> ";
echo"   <td width='10%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Currency</span></td>";
echo"   <td width='10%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Master By </span></td>";
echo"   <td width='15%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>&nbsp; </span></td>";
echo"   <td width='48%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Options </span></td>";
echo" </tr>";

echo" <tr height='15px'>";	  
echo"   <td width='5%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='12%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"      <input type='text' name='fromdate' value='$fromdate' maxlength='10' size='8'>";
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='10%' valign='top' rowspan='2' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='currency1'>Currency</label></span>";
echo"   <br><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='10%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
		if ($masterby=="1" || $masterby=="")
           echo "<input name='masterby' type='radio' value='1' checked />";
		else	
		   echo "<input name='masterby' type='radio' value='1' />";
		echo "Client</label></span>";
echo"   <br><span class='style8'><label>";
		if ($masterby=="2")
           echo "<input name='masterby' type='radio' value='2' checked />";
		else	
		   echo "<input name='masterby' type='radio' value='2' />";
		echo "Item</label></span>";	

echo"   </td>";


echo"   <td width='15%' rowspan='2' valign='top' bgcolor='#F5F5F5'>";
echo"   <span class='style8'><label>";
echo"      <input name='prtdt' type='checkbox' id='prtdt' value='1' onClick='CheckPrintDetail();' checked disabled/>Print Detail</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='prtsubdt' type='checkbox' id='prtsubdt' value='1' checked />Print Subdetail</label></span>";		

echo"   </td>";

		
echo"   <td width='48%' rowspan='6' valign='top' bgcolor='#F5F5F5'>";
echo"   <div id='main' style='position:relative; left:5px; top:0px; width:450px; height:90px;'>";
echo"   <div id='left' style='position:relative; top:0px; width:200px; float:left; '>";
echo"   <span class='style8'><label>";
echo"      <input type='checkbox' name='prtpend' id='prtpend' value='1' />Show Pending Sorder Only</label></span>";

if($Salesttc==1){
	echo"   <br><span class='style8'><label>";
	echo"      <input type='checkbox' name='pricettc' id='pricettc' value='1' "; 
		   if($Salesttc==1) echo "checked"; else echo '';  
	echo"     />Sales TTC</label></span>";
}

echo"   <br><br><span class='style8'><label><input name='confirm' type='radio' value='1' checked />Show Confirmed Orders</label></span>";
echo"   <br><span class='style8'><label><input name='confirm' type='radio' value='2' />Show Not Confirmed Orders</label></span>";
echo"   <br><span class='style8'><label><input name='confirm' type='radio' value='3' />Show All Orders</label></span>";
		


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

echo" <tr>";
echo"   <td width='5%' valign='top' bgcolor='#F5F5F5'><span class='style8'>To</span></td>";
echo"   <td width='12%' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <input type='text' name='todate' value='$todate'  maxlength='10' size='8'>";
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='15px'>";
echo"   <td colspan='5' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='52%' colspan='5' align='left' bgcolor='#F5F5F5'><span class='style8'>Group By</span></td> ";
//echo"   <td width='20%' align='left' bgcolor='#F5F5F5'><span class='style8'>Profit Margin By & Cost</span></td>";
//echo"   <td width='35%' align='left' bgcolor='#F5F5F5'><span class='style8'>Others</span></td>";
echo" </tr>";

echo" <tr height='150px'>";
echo"   <td width='52%' colspan='5' valign='top' bgcolor='#F5F5F5'>";
echo" 	<table border='0' align='left' width='100%' cellpadding=0 cellspacing=1>";
echo"   <tr><td width='30%' valign='top' bgcolor='#F5F5F5'>";
echo"		<select name='availgroupby' multiple='multiple' size='8'>    
				<option value='3' name='Salesman'>Salesman</option>
				<option value='20' name='Transaction Project(Parent)'>Transaction Project(Parent)</option>
				<option value='4' name='Transaction Project(Detail)'>Transaction Project(Detail)</option>
				<option value='21' name='Archieve Project(Parent)'>Archieve Project(Parent)</option>
				<option value='5' name='Archieve Project(Detail)'>Archieve Project(Detail)</option>
				<option value='22' name='Transaction Costcenter(Parent)'>Transaction Costcenter(Parent)</option>
				<option value='6' name='Transaction Costcenter(Detail)'>Transaction Costcenter(Detail)</option>
				<option value='23' name='Archieve Costcenter(Parent)'>Archieve Costcenter(Parent)</option>
				<option value='7' name='Archieve Costcenter(Detail)'>Archieve Costcenter(Detail)</option>
				<option value='24' name='Warehouse(Parent)'>Warehouse(Parent)</option>
				<option value='8' name='Warehouse(Detail)'>Warehouse(Detail)</option>
				<option value='25' name='Group(Parent)'>Group(Parent)</option>
				<option value='10' name='Group(Detail)'>Group(Detail)</option>
				<option value='26' name='Subgroup(Parent)'>Subgroup(Parent)</option>
				<option value='11' name='Subgroup(Detail)'>Subgroup(Detail)</option>
				<option value='12' name='Category'>Category</option>
			</select>";
echo"   </td>";

echo"   <td width='30%' valign='middle' bgcolor='#F5F5F5'>";
echo"   	<div style='text-align: center;' class='style8'>Level 1 <input type='button' name='btnSelLevel1' value=' > ' onClick='MoveLevel12(1);' title='Add'>  <input type='button' name='btnUnSelLevel1' value=' < ' onClick='RemoveLevel12(1);' title='Remove'></div><br>";
echo"   	<div style='text-align: center;' class='style8'>Level 2 <input type='button' name='btnSelLevel2' value=' > ' onClick='MoveLevel12(2);' title='Add'>  <input type='button' name='btnUnSelLevel2' value=' < ' onClick='RemoveLevel12(2);' title='Remove'></div><br>";
echo"   	<div style='text-align: center;' class='style8'>Level 3 <input type='button' name='btnSelLevel3' value=' > ' onClick='MoveLevel3();'   title='Add'>  <input type='button' name='btnUnSelLevel3' value=' < ' onClick='RemoveLevel3();'   title='Remove'></div>";
echo"   </td>";

echo"   <td width='40%' valign='top' bgcolor='#F5F5F5'>";
echo"   	<span class='style8'><input type='hidden' name='groupbylevel1value' value='$groupbylevel1value' style='width:165px;'></span>";
echo"   	<span class='style8'><input type='hidden' name='groupbylevel2value' value='$groupbylevel2value' style='width:165px;'></span>";
echo"   	<span class='style8'><input type='text' name='groupbylevel1name' value='$groupbylevel1name' style='width:165px;' readonly></span><br>";
echo"   	<span class='style8'><input type='text' name='groupbylevel2name' value='$groupbylevel2name' style='width:165px;' readonly></span><br>";
echo"   	<span class='style8'>
			<select name='assigngroupby' multiple='multiple' size='5' style='width:171px; height=150px;'>  ";  
			if ($groupbylevel3value !=''){
				$level3values = explode(",", $groupbylevel3value);
				$level3names  = explode(",", $groupbylevel3name);
				
				$k = 0;
				foreach ($level3values as $level3value) {
					$level3names  = explode(",", $groupbylevel3name);
					echo"<option value='$level3value' name='$level3names[$k]'>$level3names[$k]</option>";
					
					$k = $k + 1;
				}

			
			}
			else
				echo"<option value='' name=''></option>";
				
echo"		</select></span>";
echo"   </td></tr>";
echo"   </table></td>";

echo" </tr>";


/*
echo" <tr>";
echo"   <td colspan='5' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";*/

echo" <tr>";
echo"   <td colspan='6' bgcolor='#F5F5F5'><span class='style8'>Selected Options</span></td>";
//echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";


echo" <tr >";	  
echo"   <td colspan='6' valign='top' bgcolor='#F5F5F5' ><span class='style8'>";
echo"  		<textarea name='reportoptions' rows='6' cols='100' readonly >".htmlspecialchars(str_replace("<br>", "\n", $reportoptions), ENT_QUOTES)."</textarea>
			</span>";

echo"   	<input type='hidden' name='fromitem' id='fromitem' style='width:120px' value='".$fromitem."' />
			<input type='hidden' name='toitem' id='toitem' style='width:120px' value='".$toitem."' />
			<input type='hidden' name='fromclient' id='fromclient' style='width:120px' value='".$fromclient."' />
			<input type='hidden' name='toclient' id='toclient' style='width:120px' value='".$toclient."' />
			<input type='hidden' name='fromsalesman' id='fromsalesman' style='width:120px' value='".$fromsalesman."' />
			<input type='hidden' name='tosalesman' id='tosalesman' style='width:120px' value='".$tosalesman."' />
			<input type='hidden' name='fromgroup' id='fromgroup' style='width:120px' value='".$fromgroup."' />
			<input type='hidden' name='togroup' id='togroup' style='width:120px' value='".$togroup."' />
			<input type='hidden' name='fromsubgroup' id='fromsubgroup' style='width:120px' value='".$fromsubgroup."' />
			<input type='hidden' name='tosubgroup' id='tosubgroup' style='width:120px' value='".$tosubgroup."' />
			<input type='hidden' name='fromproject' id='fromproject' style='width:120px' value='".$fromproject."' />
			<input type='hidden' name='fromcostcent' id='fromcostcent' style='width:120px' value='".$fromcostcent."' />
			<input type='hidden' name='fromwarehouse' id='fromwarehouse' style='width:120px' value='".$fromwarehouse."' />
        </td>";
echo" </tr>";
   

echo" <tr>";
echo"   <td colspan='7' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
   /* <tr>
      <td colspan='9' 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()\";/>	  
	  <input type='button' name='btnLoadOptions' id='btnLoadOptions' value='Load Options' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"LoadOptions()\"; title='Load Template' />
	  <input type='button' name='btnSelectOptions' id='btnSelectOptions' value='Select Options' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"SelectOptions()\"; title='Select Options' />
      </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>";

//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");
}

	  
?>