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

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';		

//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();
	
$ShowCostMode  = '';
if($FI_ShowCostPrice == 0)  {
	$ShowCostMode  = 'disabled';	
}
	
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" />
<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">
<!--


all = 0;  // 0 means 'no', 1 means 'yes'


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 settrans(vop){

window.open('List_cashregistertrans.php?op='+vop);

}

function printPrev(printaccess,print)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
	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.groupby.length; i++)
	{
		if (document.form1.groupby[i].checked)
		{
			var vargroupby = document.form1.groupby[i].value;
		}
	}
	
	for (var i=0; i < document.form1.costoption.length; i++)
	{
		if (document.form1.costoption[i].checked)
		{
			var varcostoption = document.form1.costoption[i].value;
		}
	}
	
	for (var i=0; i < document.form1.showpendingslip.length; i++)
	{ 
		if (document.form1.showpendingslip[i].checked)
		{
			var varshowpendingslip = document.form1.showpendingslip[i].value;
		}
	}
	varprintstatus	= 0; 
	if(document.form1.showstatus.checked ) 
		varprintstatus = 1;
		
	varshowdiscount	= 0; 
	if(document.form1.withoutdiscount.checked ) 
		varshowdiscount = 1;
	
	vardetailreport	= 0;
	if (document.form1.detailreport.checked )
		vardetailreport = 1;
		
	varshowsummary	= 0;
	if (document.form1.showsummary.checked )
		varshowsummary = 1;	
	
	
	varshowdetail	= 0;
	if (document.form1.showdetail.checked )
		varshowdetail = 1;
		
	varshowgroups	= 0;
	if (document.form1.showgroups.checked )
		varshowgroups = 1;	
		
	varperwarehouse	= 0;
	if (document.form1.perwarehouse.checked )
		varperwarehouse = 1;	
		
	varsalessummary	= 0;
	if (document.form1.salessummary.checked )
		varsalessummary = 1;
		
	varshowunpost	= 0;
	if (document.form1.showunpost.checked )
		varshowunpost = 1;		
	
	varshowreturn	= 0;
	if (document.form1.showreturn.checked )
		varshowreturn = 1;		
		
	varshowpending = 0;
	if (document.form1.showpending.checked )
		varshowpending = 1;
		
	varshowcost	= 0;
	if (document.form1.showcost.checked )
		varshowcost = 1;	
		
	varcustperitem	= 0;
	if (document.form1.custperitem.checked )
		varcustperitem = 1;
		
	varshowslipdetail	= 0;
	if (document.form1.showslipdetail.checked )
		varshowslipdetail = 1;
		
	varshowslipitems	= 0;
	if (document.form1.showslipitems.checked )
		varshowslipitems = 1;
		
	var paymentmethod = '';
	if (document.getElementById('paymentmethod'))
		paymentmethod = document.getElementById('paymentmethod').value;
	var subgroupitem = 0;
	if (document.getElementById('subgroupitem').checked)
		subgroupitem = 1;
	var grpuserslip = 0;
	if (document.getElementById('grpuserslip').checked)
		grpuserslip = 1;
	
	varfromdate     = document.form1.fromdate.value;
	vartodate       = document.form1.todate.value;
	varfromuser     = document.form1.fromuser.value;
	varfromcashreg  = document.form1.fromcashreg.value;
	varfromcustomer = document.form1.fromcustomer.value;
	vartocustomer   = document.form1.tocustomer.value;
	varfromwrh      = document.form1.fromwarehouse.value;
	varfromprj      = document.form1.fromproject.value;
	vartoprj        = document.form1.toproject.value;
	varfromcst      = document.form1.fromcostcent.value;
	vartocst        = document.form1.tocostcent.value;
	varfromsalesman = document.form1.fromsalesman.value;
	varfromvendor   = document.form1.fromvendor.value;
	vartovendor     = document.form1.tovendor.value;
	varfromcredit   = document.form1.fromcredit.value;
	vartocredit     = document.form1.tocredit.value;
	varfromdriver   = document.form1.fromdriver.value;
	varfromgrp    	= document.form1.fromgroup.value;
	vartogrp      	= document.form1.togroup.value;
	varfromsubgrp 	= document.form1.fromsubgroup.value;
	vartosubgrp   	= document.form1.tosubgroup.value;
	varfromitem   	= document.form1.fromitem.value;
	vartoitem     	= document.form1.toitem.value;
  
	var fromtime 	= document.form1.fromtime.value;
	var totime 	 	= document.form1.totime.value;
	
	var vfromref 	= document.form1.fromref.value;
	var vtoref 	 	= document.form1.toref.value;
	
	
	var itemstatus 	 	= document.form1.itemstatus.value;
	
	vReportName = 'Rep_ListofRetail.php';
	
	if (vargroupby == '100')
	{
		var url = 'Rep_ListofCoupon.php?fromdate='+varfromdate+'&todate='+vartodate+'&print='+print+'&curr='+varcurrency;
		window.open(url);
		return;
		
		 
	}
	if(vargroupby == '13') vReportName = 'Rep_ListofItemStatus.php';
	else if(vargroupby == '12') vReportName = 'Rep_ListofCustomers.php';
	else
	if (vardetailreport == 1) vReportName = 'Rep_ListofRetail_Detailed.php';
	else if (varperwarehouse == 1) vReportName = 'Rep_ListofRetailPerWarehouse.php';
	else if (varsalessummary == 1) vReportName = 'Form_RetailSalesSummary.php';
	
	if(varshowpendingslip == 4 && varsalessummary == 1) vReportName = 'Rep_SalesSummaryDetailed.php';
	if( grpuserslip == 1 && vargroupby == 3) vReportName = 'Rep_ListofRetailByUserSlip.php';
	
	str = vReportName+'?fromdate='+varfromdate+'&todate='+vartodate+'&fromuser='+varfromuser
		 +'&fromcashreg='+varfromcashreg+'&fromcustomer='+varfromcustomer+'&tocustomer='+vartocustomer
		 +'&fromwarehouse='+varfromwrh+'&fromproject='+varfromprj+'&toproject='+vartoprj+'&fromgroup='+varfromgrp+'&togroup='+vartogrp
		 +'&fromsubgroup='+varfromsubgrp+'&tosubgroup='+vartosubgrp+'&fromcostcent='+varfromcst+'&tocostcent='+vartocst
		 +'&curr='+varcurrency+'&fromsalesman='+varfromsalesman+'&fromitem='+varfromitem
         +'&toitem='+vartoitem+'&groupby='+vargroupby+'&showdetail='+varshowdetail+'&showsummary='+varshowsummary+'&varprintstatus='+varprintstatus+'&showgroups='+varshowgroups
		 +'&fromvendor='+varfromvendor+'&tovendor='+vartovendor+'&fromcredit='+varfromcredit+'&tocredit='+vartocredit
		 +'&showunpost='+varshowunpost+'&showreturn='+varshowreturn+'&showcost='+varshowcost+'&costoption='+varcostoption+'&custperitem='+varcustperitem
		 +'&showpending='+varshowpending+'&fromdriver='+varfromdriver+'&print='+print+'&showdiscount='+varshowdiscount+'&paymentmethod='+paymentmethod
		 +'&fromtime='+fromtime+'&totime='+totime+'&itemstatus='+itemstatus+'&subgroupitem='+subgroupitem+'&grpuserslip='+grpuserslip+'&fromref='+vfromref+'&toref='+vtoref;
		 
	str1 = vReportName+'?fromdate='+varfromdate+'&todate='+vartodate+'&fromuser='+varfromuser+'&curr='+varcurrency+'&showpendingslip='+varshowpendingslip
			+'&showslipdetail='+varshowslipdetail+'&showslipitems='+varshowslipitems+'&paymentmethod='+paymentmethod
			+'&fromtime='+fromtime+'&totime='+totime+'&grpuserslip='+grpuserslip;
		   
	if(varshowpendingslip == 4 && varsalessummary == 1)
	window.open(str);
	else
	if (printaccess==1) {
		if (varsalessummary == 1)
			window.open(str1);
		else
			window.open(str);
	} else {
		if (varsalessummary == 1)
			window.open(str1,"Report", "width=350,height=500,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
		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.currency.length; i++)
	{
		if (document.form1.currency[i].checked)
		{
			var varcurrency = document.form1.currency[i].value;
		}
	}
  
	for (var i=0; i < document.form1.groupby.length; i++)
	{
		if (document.form1.groupby[i].checked)
		{
			var vargroupby = document.form1.groupby[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.costoption.length; i++)
	{
		if (document.form1.costoption[i].checked)
		{
			var varcostoption = document.form1.costoption[i].value;
		}
	} 
	 
	vardetailreport	= 0;
	if (document.form1.detailreport.checked )
		vardetailreport = 1;
		
	varshowsummary	= 0;
	if (document.form1.showsummary.checked )
		varshowsummary = 1;	
	
	varshowdetail	= 0;
	if (document.form1.showdetail.checked )
		varshowdetail = 1;
		
	varshowgroups	= 0;
	if (document.form1.showgroups.checked )
		varshowgroups = 1;	
		
	varperwarehouse	= 0;
	if (document.form1.perwarehouse.checked )
		varperwarehouse = 1;
		
	varsalessummary	= 0;
	if (document.form1.salessummary.checked )
		varsalessummary = 1;

	varshowunpost	= 0;
	if (document.form1.showunpost.checked )
		varshowunpost = 1;	
		
	varshowpending = 0;
	if (document.form1.showpending.checked )
		varshowpending = 1;

	varshowcost	= 0;
	if (document.form1.showcost.checked )
		varshowcost = 1;	
		
	varcustperitem	= 0;
	if (document.form1.custperitem.checked )
		varcustperitem = 1;
			
	varshowslipdetail	= 0;
	if (document.form1.showslipdetail.checked )
		varshowslipdetail = 1;
		
	varshowslipitems	= 0;
	if (document.form1.showslipitems.checked )
		varshowslipitems = 1;
	
	varshowdiscount	= 0; 
	if(document.form1.withoutdiscount.checked ) 
		varshowdiscount = 1;
	var paymentmethod = '';
	if (document.getElementById('paymentmethod'))
		paymentmethod = document.getElementById('paymentmethod').value;
	var subgroupitem = 0;
	if (document.getElementById('subgroupitem').checked)
		subgroupitem = 1;
	var grpuserslip = 0;
	if (document.getElementById('grpuserslip').checked)
		grpuserslip = 1;
	
	varfromdate     = document.form1.fromdate.value;
	vartodate       = document.form1.todate.value;
	varfromuser     = document.form1.fromuser.value;
	varfromcashreg  = document.form1.fromcashreg.value;
	varfromcustomer = document.form1.fromcustomer.value;
	vartocustomer   = document.form1.tocustomer.value;
	varfromwrh      = document.form1.fromwarehouse.value;
	varfromprj      = document.form1.fromproject.value;
	vartoprj        = document.form1.toproject.value;
	varfromcst      = document.form1.fromcostcent.value;
	vartocst        = document.form1.tocostcent.value;
	varfromsalesman = document.form1.fromsalesman.value;
	varfromvendor   = document.form1.fromvendor.value;
	vartovendor     = document.form1.tovendor.value;
	varfromcredit   = document.form1.fromcredit.value;
	vartocredit     = document.form1.tocredit.value;
	varfromdriver   = document.form1.fromdriver.value;
    varfromgrp      = document.form1.fromgroup.value;
	vartogrp        = document.form1.togroup.value;
	varfromsubgrp   = document.form1.fromsubgroup.value;
	vartosubgrp     = document.form1.tosubgroup.value;
	
	var fromtime 	= document.form1.fromtime.value;
	var totime 	 	= document.form1.totime.value;
	
	var itemstatus 	 	= document.form1.itemstatus.value;
	
	vReportName = 'Exp_ListofRetail.php';
	if (vardetailreport == 1) vReportName = 'Exp_ListofRetail_Detailed.php';
	//else if (varperwarehouse == 1) vReportName = 'Exp_ListofRetailPerWarehouse.php';
  
  	if(vargroupby == '12') vReportName = 'Rep_ListofCustomers.php';
	if(vargroupby == '13') vReportName = 'Exp_ListofItemStatus.php';
	
	str = vReportName+'?fromdate='+varfromdate+'&todate='+vartodate+'&fromuser='+varfromuser
		 +'&fromcashreg='+varfromcashreg+'&fromcustomer='+varfromcustomer+'&tocustomer='+vartocustomer
		 +'&fromwarehouse='+varfromwrh+'&fromproject='+varfromprj+'&toproject='+vartoprj+'&fromgroup='+varfromgrp+'&togroup='+vartogrp
		 +'&fromsubgroup='+varfromsubgrp+'&tosubgroup='+vartosubgrp
		 +'&fromcostcent='+varfromcst+'&tocostcent='+vartocst+'&curr='+varcurrency+'&fromsalesman='+varfromsalesman
		 +'&groupby='+vargroupby+'&showdetail='+varshowdetail+'&showsummary='+varshowsummary+'&showgroups='+varshowgroups
		 +'&fromvendor='+varfromvendor+'&tovendor='+vartovendor+'&fromcredit='+varfromcredit+'&tocredit='+vartocredit
		 +'&showunpost='+varshowunpost+'&showcost='+varshowcost+'&costoption='+varcostoption+'&custperitem='+varcustperitem
		 +'&showpending='+varshowpending+'&fromdriver='+varfromdriver+'&export=1'+'&showdiscount='+varshowdiscount+'&paymentmethod='+paymentmethod
		 +'&fromtime='+fromtime+'&totime='+totime+'&itemstatus='+itemstatus+'&subgroupitem='+subgroupitem;+'&grpuserslip='+grpuserslip;
		   
		   
	window.open(str);
	
}



function ShowSummary() {
    var x= document.form1;
	
	for (var i=0; i < x.groupby.length; i++)
	{
		if (x.groupby[i].checked)
		{
		  var vargroupby = x.groupby[i].value;
		}
	}
	
	if (x.detailreport.checked) {
		if (vargroupby != 2 && vargroupby != 6) {
			x.showsummary.disabled = false;
		}	
		x.showgroups.disabled = false;
		
		x.showunpost.disabled = true;
		x.showunpost.checked  = false;
		x.custperitem.disabled  = true;
		x.custperitem.checked   = false;
		x.perwarehouse.disabled = true;
		x.perwarehouse.checked  = false;
		x.salessummary.disabled = true;
		x.salessummary.checked  = false;
		
		if (vargroupby == 2) {
			x.showcost.disabled = false;
			
			for (var i=0; i < x.costoption.length; i++)
			{
				x.costoption[i].disabled = false;
			}
		}	
	}  
	else { 
		x.showsummary.disabled = true;
		x.showsummary.checked  = false;
		x.showgroups.disabled = true;
		x.showgroups.checked  = false;
		x.showcost.disabled = true;
		x.showcost.checked  = false;
		x.custperitem.disabled  = false;
		x.custperitem.checked   = false;
		x.perwarehouse.disabled = false;
		x.perwarehouse.checked  = false;
		x.salessummary.disabled  = false;
		x.salessummary.checked   = false;
		
		for (var i=0; i < x.costoption.length; i++)
		{
			x.costoption[i].disabled = true;
		}
		
		if (vargroupby != 2 && vargroupby != 6) {
			x.showunpost.disabled = false;
			x.showunpost.checked  = false;
		}
	}
	
}

function SelectCustomerList() {
	var x= document.form1;

	if (x.custperitem.checked) {
		x.detailreport.disabled = true;
		x.detailreport.checked  = false;
		x.perwarehouse.disabled = true;
		x.perwarehouse.checked  = false;
		x.salessummary.disabled  = true;
		x.salessummary.checked   = false;
	} else {
		x.detailreport.disabled = false;
		x.detailreport.checked  = false;
		x.perwarehouse.disabled = false;
		x.perwarehouse.checked  = false;
		x.salessummary.disabled  = false;
		x.salessummary.checked   = false;
	}
}

function SelectSalesPerWarehouse() {
	var x= document.form1;

	if (x.perwarehouse.checked) {
		x.detailreport.disabled = true;
		x.detailreport.checked  = false;
		x.custperitem.disabled  = true;
		x.custperitem.checked   = false;
		x.salessummary.disabled  = true;
		x.salessummary.checked   = false;
	} else {
		x.detailreport.disabled = false;
		x.detailreport.checked  = false;
		x.custperitem.disabled  = false;
		x.custperitem.checked   = false;
		x.salessummary.disabled  = false;
		x.salessummary.checked   = false;
	}
}

function SelectSalesSummary() {
	var x= document.form1;

	if (x.salessummary.checked) {
		x.detailreport.disabled = true;
		x.detailreport.checked  = false;
		x.custperitem.disabled  = true;
		x.custperitem.checked   = false;
		x.perwarehouse.disabled  = true;
		x.perwarehouse.checked   = false;
		x.showslipdetail.disabled  = false;
		x.showslipitems.disabled  = false;
	} else {
		x.detailreport.disabled = false;
		x.detailreport.checked  = false;
		x.custperitem.disabled  = false;
		x.custperitem.checked   = false;
		x.perwarehouse.disabled  = false;
		x.perwarehouse.checked   = false;
		x.showslipdetail.disabled  = true;
		x.showslipdetail.checked   = false;
		x.showslipitems.disabled  = true;
		x.showslipitems.checked   = false;
	}
}

function ShowGroups() {
	var x= document.form1;
	
	if (x.showgroups.checked) {
	    x.showdetail.disabled = true;
		x.showdetail.checked  = false;
	}  
	else { 
		x.showdetail.disabled = false;
	}

}

function ShowDetail() {
    var x= document.form1;
	
	for (var i=0; i < x.groupby.length; i++)
	{
		if (x.groupby[i].checked)
		{
		  var vargroupby = x.groupby[i].value;
		}
	}
	if(vargroupby == 2) {
		x.subgroupitem.checked = true;
		x.subgroupitem.disabled = false;
	}
	else {
		x.subgroupitem.checked = false;
		x.subgroupitem.disabled = true;
	}
	
	if(vargroupby == 3) {
		x.grpuserslip.disabled = false;
		x.detailreport.checked = true;
	}
	else {
		x.grpuserslip.checked = false;
		x.grpuserslip.disabled = true;
	}
	
	if (vargroupby == 2 || vargroupby == 6 || x.showgroups.checked) { 
	    x.showdetail.disabled = true;
		x.showdetail.checked  = false;
		x.showunpost.disabled = true;
		x.showunpost.checked  = false;
		
		x.detailreport.disabled = false;
		x.perwarehouse.disabled = false;
		x.salessummary.disabled = false;
		x.showgroups.disabled   = false;
		
		
		if (x.detailreport.checked) {
			x.showsummary.disabled = true;
			x.showsummary.checked  = false;
		}  
	}
	else if (vargroupby == 8) { 
		x.showdetail.disabled = true;
		x.showdetail.checked  = false;
		x.showunpost.disabled = false;
		x.showunpost.checked  = false;
		
		x.detailreport.disabled = true;
		x.detailreport.checked  = false;
		x.showgroups.disabled   = true;
		x.showgroups.checked    = false;
		x.showsummary.disabled  = true;
		x.showsummary.checked   = false;
		x.perwarehouse.disabled = true;
		x.perwarehouse.checked  = false;
	}
	else { 
	    x.showdetail.disabled = false;
		x.showdetail.checked  = false;
		
		x.detailreport.disabled = false;
		x.perwarehouse.disabled = false;
		x.salessummary.disabled = false;
		x.showgroups.disabled   = false;
		
		if (x.detailreport.checked) {
			x.showsummary.disabled = false;
			x.showsummary.checked  = true;
		} else {
			x.showunpost.disabled = false;
			x.showunpost.checked  = false;
		}
	}
	
	if (vargroupby == 2 && x.showdetail.checked) {
		x.showcost.disabled = false;
		
		for (var i=0; i < x.costoption.length; i++)
		{
			x.costoption[i].disabled = false;
		}

	} else {
		x.showcost.disabled = true;
		x.showcost.checked  = false;
		
		for (var i=0; i < x.costoption.length; i++)
		{
			x.costoption[i].disabled = true;
		}
	}	
	
}

function SelectSlipItems() {
	var x= document.form1;

	if (x.showslipitems.checked) {
		x.showslipdetail.checked  = true;
	} 
}

function showlistcustomer(str){

	window.open('List_Customers.php?frm=2&item='+str,'List_Customers','width=650,height=450,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistVendors(str){
  
	window.open('List_Vendors.php?frm=4&item='+str,'List_Vendors','width=750,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCreditCard(str){

  window.open('List_CreditCards.php?frm=2&str='+str,'List_CreditCards','width=600,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Retail</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'>List of Retail </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."',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=\"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 height="534" border="0" align="center" valign="top" width="100%" >';


echo" <tr>";	  
echo"   <td width='20%' height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>Date Form/To</span></td> ";
echo"   <td width='55%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>A4 Options</span></td>";
echo"   <td width='25%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Slip Options</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='15%' height='50' valign='top' 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>
<input type='button' name='but1' value='...' onclick='settrans(1)'   onMouseOver=\"style.cursor='pointer'\" >
<br>";
echo"      <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>
<input type='button' name='but1' value='...' onclick='settrans(2)'   onMouseOver=\"style.cursor='pointer'\" >
</td>";

echo"   <td width='55%' rowspan='3' valign='top' bgcolor='#F5F5F5'>";
//echo"  <div id='main' style='position:relative; top:0px; width:590px; height:145px; border:1px solid #999999;'>";
echo"   <div id='left' style='position:relative; top:0px; width:200px; float:left;'>";
echo"	<table border='0' align='center' valign='top' width='100%' cellpadding='0' cellspacing='0'><tr>";
echo"   <td><span class='style8'><label>";
		if ($groupby=="1")
           echo "<input name='groupby' type='radio' value='1' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='1' onClick='ShowDetail();'/>";
		echo "None</label><br>";
		
		
		   echo "<input name='groupby' type='radio' value='100' onClick='ShowDetail();'/>";
		echo "Coupon</label></span></td>";
		
		
		
		
		
echo"   <td><span class='style8'><label>";
		if ($groupby=="4")
           echo "<input name='groupby' type='radio' value='4' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='4' onClick='ShowDetail();'/>";
		echo "CashRegister</label></span></td></tr>";
echo"   <tr><td><span class='style8'><label>";
		if ($groupby=="3")
           echo "<input name='groupby' type='radio' value='3' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='3' onClick='ShowDetail();'/>";
		echo "User</label></span></td>";		

echo"   <td><span class='style8'><label>";
		if ($groupby=="5")
           echo "<input name='groupby' type='radio' value='5' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='5' onClick='ShowDetail();'/>";
		echo "Customer</label></span></td></tr>";		
		
echo"   <tr><td><span class='style8'><label>";
		if ($groupby=="2" || $groupby=="")
           echo "<input name='groupby' type='radio' value='2' checked onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='2' onClick='ShowDetail();'/>";
		echo "Items</label></span></td>";		

echo"   <td><span class='style8'><label>";
		if ($groupby=="6")
           echo "<input name='groupby' type='radio' value='6' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='6' onClick='ShowDetail();'/>";
		echo "Vendor</label></span></td></tr>";		
		
echo"   <tr><td><span class='style8'><label>";
		if ($groupby=="8")
           echo "<input name='groupby' type='radio' value='8' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='8' onClick='ShowDetail();'/>";
		echo "Date</label></span></td>";
		
echo"   <td><span class='style8'><label>";
		if ($groupby=="10")
           echo "<input name='groupby' type='radio' value='10' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='10' onClick='ShowDetail();'/>";
		echo "Driver</label></span></td></tr>";

echo"   <tr><td colspan='2'><span class='style8'><label>";
		if ($groupby=="7")
           echo "<input name='groupby' type='radio' value='7' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='7' onClick='ShowDetail();'/>";
		echo "User/CashRegister</label></span></td></tr>";

echo"   <tr><td colspan='2'><span class='style8'><label>";
		if ($groupby=="9")
           echo "<input name='groupby' type='radio' value='9' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='9' onClick='ShowDetail();'/>";
		echo "SubGroup/Customer</label></span></td></tr>";		
		
echo"   <tr><td colspan='2'><span class='style8'><label>";
		if ($groupby=="11")
           echo "<input name='groupby' type='radio' value='11' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='11' onClick='ShowDetail();'/>";
		echo "Order Type</label></span></td></tr>";		
echo"   <tr><td colspan='2'><span class='style8'><label>";
		if ($groupby=="12")
           echo "<input name='groupby' type='radio' value='12' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='12' onClick='ShowDetail();'/>";
		echo "Customer List</label></span></td></tr>";
		
echo"   <tr><td colspan='2'><span class='style8'><label>";
		if ($groupby=="13")
           echo "<input name='groupby' type='radio' value='13' checked  onClick='ShowDetail();'/>";
		else	
		   echo "<input name='groupby' type='radio' value='13' onClick='ShowDetail();'/>";
		echo "Items With Status List</label></span></td></tr>";		
echo"   </table></div>";
//echo"   </td>";

//echo"  <td width='50%' colspan='2' bgcolor='#F5F5F5' valign='top'><span class='style8'>";
echo"  <span class='style8'>";
echo"   <div id='left' style='position:relative; top:0px; width:190px; float:left;  margin-left:10px;'>";
echo"      <label><input type='checkbox' name='detailreport' id='detailreport' value='1' onClick='ShowSummary();' />Detailed Report</label><br>";
echo"      &nbsp;&nbsp;<label><input type='checkbox' name='showsummary' id='showsummary' value='1' disabled/>Show Summary</label><br>";
echo"      &nbsp;&nbsp;<label><input type='checkbox' name='showgroups' id='showgroups' value='1' onClick='ShowGroups();' disabled/>Show Groups Only</label><br>";
echo"      <label><input type='checkbox' name='custperitem' id='custperitem' value='1' onclick='SelectCustomerList();' />Customers List Per Item</label><br>";
echo"      <label><input type='checkbox' name='perwarehouse' id='perwarehouse' value='1' onclick='SelectSalesPerWarehouse();' />Sales Per Warehouse</label><br>";
echo"      <label><input type='checkbox' name='showstatus' id='showstatus' value='1' />Show Item Status</label><br>";
echo"      <label><input type='checkbox' name='withoutdiscount' id='withoutdiscount' value='1' />With Discount</label>";
echo"   </div>";
echo"   <div id='right' style='position:relative; left:5px; top:0px; width:180px; float:left; margin-left: 10px;  margin-bottom:5px;'>";
echo"      <label><input type='checkbox' name='showdetail' id='showdetail' value='1'  unchecked disabled/>Show Detail(Items)</label><br>";
echo"      <label><input type='checkbox' name='showunpost' id='showunpost' value='1' disabled />Show Unposted Only</label><br>";
echo"      <label><input type='checkbox' name='showpending' id='showpending' value='1' />Show Pending Only</label><br>";
echo"      <label><input name='showcost' type='checkbox' id='showcost' value='1' unchecked disabled />Show Cost</label>";
echo"   <div style='position:relative; left:12px; margin-bottom:5px; width:150px;'>";
echo"   <span class='style8'><label>";
		if ($costoption=="1" || $costoption=="")
           echo "<input name='costoption' type='radio' value='1' checked disabled/>";
		else	
		   echo "<input name='costoption' type='radio' value='1' disabled/>";
		echo "Mean Cost</label></span>";
echo"   <br><span class='style8'><label>";
		if ($costoption=="2")
           echo "<input name='costoption' type='radio' value='2' checked disabled/>";
		else	
		   echo "<input name='costoption' type='radio' value='2' disabled/>";
		echo "LIFO</label></span></div>";
		echo"      <label><input type='checkbox' name='showreturn' id='showreturn' value='1' />Show Return Only</label><br>";
echo"   </div></span>";
echo" </div>";
echo" </td>";

echo"   <td width='30%' rowspan='3' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
//echo"  	<div id='main1' style='position:relative; top:0px; width:250px; height:130px; border:1px solid #999999;'>";
echo"      	<label><input type='checkbox' name='salessummary' id='salessummary' value='1' onclick='SelectSalesSummary();' />Sales Summary Report</label><br>";
echo"		&nbsp;&nbsp;<label><input name='showpendingslip' type='radio' value='1' />Show Pending Only</label><br>";
echo"		&nbsp;&nbsp;<label><input name='showpendingslip' type='radio' value='2' />Show Not Pending</label><br>";
echo"		&nbsp;&nbsp;<label><input name='showpendingslip' type='radio' value='3' checked />Show All</label><br>";
echo"		&nbsp;&nbsp;<label><input name='showpendingslip' type='radio' value='4'  />Show Detailed</label><br>";

echo"      <label><input type='checkbox' name='showslipdetail' id='showslipdetail' value='1' unchecked disabled />Show Details</label><br>";
echo"      <label><input type='checkbox' name='showslipitems' id='showslipitems' value='1' onclick='SelectSlipItems();' unchecked disabled />Show Items</label><br>";
echo"      <label><input type='checkbox' name='subgroupitem' id='subgroupitem' value='1'   />Group Items by Subgroup</label><br>";
echo"      <label><input type='checkbox' name='grpuserslip' id='grpuserslip' value='1'  disabled />Show Group by users in Slip Layout</label><br>";
echo"	</div></span></td>";
echo" </tr>";

// From / To Time
echo" <tr>";
echo"   <td height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>From/To Time</span></td>";
echo" </tr>";
echo" <tr>";
echo"   <td valign='top' height='40' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='fromtime' type='time' style='height: 15px; font-size: 12px; border-radius: 4px;' ><br>";
echo"  		<input name='totime' type='time' style='height: 15px; font-size: 12px; border-radius: 4px;' ></td>";
echo" </tr>";




echo" <tr>";
echo"   <td height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>Currency</span></td>";
echo"   <td height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>Status</span></td>";
echo" </tr>";
echo" <tr>";
echo"   <td valign='top' height='40' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[0]' checked='checked'>$rowsetup[0]</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[1]'>$rowsetup[1]</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currency' type='radio' value=''>All</label></span></td>";
echo "<td><select name='itemstatus' style='width:100px;'>
			<option value=''></option>
			<option value='1'>Gift</option>
			<option value='2'>Void</option>
		  </select></td>";
echo" </tr>";

echo" <tr>";
echo"   <td height='19' colspan='2' align='left' bgcolor='#F5F5F5'>
			<span class='style8'>From Reference</span> <input type='text' name='fromref' id='fromref'> 
			<br>
			<span class='style8'>To Reference&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input type='text' name='toref' id='toref'>
	 </td>"; 
echo" </tr>";
/*
echo" <tr>";
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>";
echo"   <td colspan='3' bgcolor='#F5F5F5'>";
echo"	<table border='0' align='center' valign='top' width='100%' cellpadding='0' cellspacing='0'><tr>";
 
echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5' valign='top'><span class='style8'>Customer Code / Description </span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input type='text' name='fromcustomer' id='fromcustomer' size='15' value='".$fromcustomer."' style='width:100px;'/>
        <input type='text' name='fromcustomerdesc' id='fromcustomerdesc' size='35' value='".$fromcustomerdesc."' style='width:250px;' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Customer From ' 
             onClick='showlistcustomer(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

//echo"   <td colspan='2'  align='right' bgcolor='#F5F5F5' >&nbsp;</td>";
echo"   <td width='10%' align='right' bgcolor='#F5F5F5' ><span class='style8'>Warehouse</span></td>";			 		
echo"   <td width='40%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromwarehouse' id='fromwarehouse' style='width:300px'>";
		echo"<option></option>";
		while($wrhf=mysql_fetch_row($resultfromwarehouse)){
		echo"<option ";
			if ($fromwarehouse==$wrhf[0])
				echo " selected ";
		echo" value='$wrhf[0]'>$wrhf[0] / $wrhf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";	
echo" </tr>";
  
echo" <tr>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='45%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input type='text' name='tocustomer' id='tocustomer' size='15' value='".$tocustomer."' style='width:100px;'/>
        <input type='text' name='tocustomerdesc' id='tocustomerdesc' size='35' value='".$tocustomerdesc."' style='width:250px;'/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Customer To ' 
             onClick='showlistcustomer(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

echo"   <td width='10%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>Salesman</span></td>";
echo"   <td width='40%'  bgcolor='#F5F5F5' ><span class='style8'><select name='fromsalesman' id='fromsalesman' style='width:300px'>";
		echo"<option></option>";
		while($salesmanf=mysql_fetch_row($resultsalesman)){
		echo"<option ";
			if ($fromsalesman==$salesmanf[0])
				echo " selected ";
			echo" value='$salesmanf[0]'>$salesmanf[0] | $salesmanf[1]</option>";
		}
		echo"</select>";
echo"</span></td>";	
echo" </tr>";

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

echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Project </span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>CostCenter</span></td>";
echo" </tr>";

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
	    <td width='45%' bgcolor='#F5F5F5'> <span class='style8'><select name='fromproject' id='fromproject' style='width:365px'>";
		echo"<option></option>";
		while($prj=mysql_fetch_row($resultfromproject)){
		echo"<option ";
		    if (($fromproject==$prj[0]) || ($defaultproject==$prj[0]))
				echo " selected ";
		echo" value='$prj[0]'>$prj[0] / $prj[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";

echo"	<td width='10%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
		<td width='40%' align='left' bgcolor='#F5F5F5' ><span class='style8'>
		<select name='fromcostcent' id='fromcostcent' style='width:300px'>";
		echo"<option></option>";
		while($cstf=mysql_fetch_row($resultfromcostcent)){
		echo"<option ";
			if (($fromcostcent==$cstf[0]) || ($defaultcostcent==$cstf[0]))
				echo " selected ";
		echo" value='$cstf[0]'>$cstf[0] / $cstf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";	
echo" </tr>";

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
	    <td width='45%' bgcolor='#F5F5F5'> <span class='style8'><select name='toproject' id='toproject' style='width:365px'>";
		echo"<option></option>";
		while($prj=mysql_fetch_row($resulttoproject)){
		echo"<option ";
		    if (($toproject==$prj[0]) || ($defaultproject==$prj[0]))
				echo " selected ";
		echo" value='$prj[0]'>$prj[0] / $prj[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";

echo"	<td width='10%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
		<td width='40%' align='left' bgcolor='#F5F5F5' ><span class='style8'>
		<select name='tocostcent' id='tocostcent' style='width:300px'>";
		echo"<option></option>";
		while($cstt=mysql_fetch_row($resulttocostcent)){
		echo"<option ";
			if (($tocostcent==$cstt[0]) || ($defaultcostcent==$cstt[0]))
				echo " selected ";
		echo" value='$cstt[0]'>$cstt[0] / $cstt[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";	
echo" </tr>";

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

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
	    <td width='45%' bgcolor='#F5F5F5'> <span class='style8'>";
echo"   <label>
        <input type='text' name='fromvendor' id='fromvendor' size='15' value='".$fromvendor."' style='width:100px;'/>
        <input type='text' name='fromvendordesc' id='fromvendordesc' size='35' value='".$fromvendordesc."' style='width:250px;' />
        </label>
        </span>
        <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Vendor From ' 
             onClick='showlistVendors(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
			 

echo"   <td width='10%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>User Account</span></td>";
echo"   <td width='40%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromuser' id='fromuser' style='width:300px'>";
		echo"<option></option>";
		while($userf=mysql_fetch_row($resultusers)){
		echo"<option ";
			if ($fromuser==$userf[0])
				echo " selected ";
			echo" value='$userf[0]'>$userf[0] | $userf[1]</option>";
		}
		echo"</select>";
echo"</span></td>";
echo" </tr>";

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
	    <td width='45%' bgcolor='#F5F5F5'> <span class='style8'>";
echo"   <label>
        <input type='text' name='tovendor' id='tovendor' size='15' value='".$tovendor."' style='width:100px;'/>
        <input type='text' name='tovendordesc' id='tovendordesc' size='35' value='".$tovendordesc."' style='width:250px;'/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Vendor To ' 
             onClick='showlistVendors(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
		
echo"   <td width='10%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>Cashregister</span></td>";
echo"   <td width='40%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromcashreg' id='fromcashreg' style='width:300px'>";
		echo"<option></option>";
		while($cashregf=mysql_fetch_row($resultcashregister)){
		echo"<option ";
			if ($fromcashreg==$cashregf[0])
				echo " selected ";
			echo" value='$cashregf[0]'>$cashregf[0] | $cashregf[1]</option>";
		}
		echo"</select>";
echo"</span></td>";
echo" </tr>";

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

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
	    <td width='45%' bgcolor='#F5F5F5'> <span class='style8'>";
echo"   <label>
        <input type='text' name='fromcredit' id='fromcredit' size='15' value='".$fromcredit."' style='width:100px;'/>
        <input type='text' name='fromcreditdesc' id='fromcreditdesc' size='35' value='".$fromcreditdesc."' style='width:250px;' />
        </label>
        </span>
        <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Credit From ' 
             onClick='showlistCreditCard(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

//echo"   <td colspan='2' align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo"   <td width='10%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>Driver</span></td>";
echo"   <td width='40%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromdriver' id='fromdriver' style='width:300px'>";
		echo"<option></option>";
		while($driverf=mysql_fetch_row($resultdrivers)){
		echo"<option ";
			if ($fromdriver==$driverf[0])
				echo " selected ";
			echo" value='$driverf[0]'>$driverf[0] | $driverf[1]</option>";
		}
		echo"</select>";
echo"</span></td>";
echo" </tr>";

echo" <tr>
	    <td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
	    <td width='45%' bgcolor='#F5F5F5'> <span class='style8'>";
echo"   <label>
        <input type='text' name='tocredit' id='tocredit' size='15' value='".$tocredit."' style='width:100px;'/>
        <input type='text' name='tocreditdesc' id='tocreditdesc' size='35' value='".$tocreditdesc."' style='width:250px;'/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Credit To ' 
             onClick='showlistCreditCard(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
		
echo"   <td colspan='2' align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr height='25px'>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Item Group</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Item SubGroup</span></td>";
echo" </tr>";


echo" <tr height='35px'>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'   bgcolor='#F5F5F5' ><span class='style8'><select name='fromgroup' id='fromgroup' style='width:365px'>";
		echo"<option></option>";
		while($grpf=mysql_fetch_row($resultfromgroup)){
		echo"<option ";
			if ($fromgroup==$grpf[0])
				echo " selected ";
		echo" value='$grpf[0]'>$grpf[0] | $grpf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";					 

echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  bgcolor='#F5F5F5' ><span class='style8'><select name='fromsubgroup' id='fromsubgroup' style='width:300px'>";
		echo"<option></option>";
		while($subgrpf=mysql_fetch_row($resultfromsubgroup)){
		echo"<option ";
			if ($fromsubgroup==$subgrpf[0])
				echo " selected ";
		echo" value='$subgrpf[0]'>$subgrpf[0] | $subgrpf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";		
		
echo" </tr>";

echo" <tr height='15px'>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='45%'  bgcolor='#F5F5F5' ><span class='style8'><select name='togroup' id='togroup' style='width:365px'>";
		echo"<option></option>";
		while($grpt=mysql_fetch_row($resulttogroup)){
		echo"<option ";
			if ($togroup==$grpt[0])
				echo " selected ";
		echo" value='$grpt[0]'>$grpt[0] | $grpt[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";
		
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='45%'  bgcolor='#F5F5F5' ><span class='style8'><select name='tosubgroup' id='tosubgroup' style='width:300px'>";
		echo"<option></option>";
		while($subgrpt=mysql_fetch_row($resulttosubgroup)){
		echo"<option ";
			if ($tosubgroup==$subgrpt[0])
				echo " selected ";
		echo" value='$subgrpt[0]'>$subgrpt[0] | $subgrpt[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";		

echo" </tr>";


echo" <tr height='25px'>";
echo"   <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>Item Code / Description</span></td>";

echo" </tr>";

echo" <tr height='15px'>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  colspan='1' valign='middle' 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>      ";
	 
	echo"</td>";
	$querypm = "select payment_account, payment_description from PaymentMethods order by payment_account";
	$respm = mysql_query($querypm, $connection);
	echo"   <td  bgcolor='#F5F5F5'><span class='style8'>Payment Methods</span></td>";
	echo "<td><select name='paymentmethod' id ='paymentmethod' >";
	echo "<option value=''></option>";
	echo "<option value='COUPON'>Coupon</option>";
	echo "<option value='CASH'>Cash</option>";
	echo "<option value='CUSTOMER'>Customer</option>";
	while($rwpm = mysql_fetch_array($respm)){
		echo "<option value='$rwpm[0]'>$rwpm[1]</option>";
	}
	echo "</select></td>";
echo" </tr>";


echo" <tr height='15px'>";	  
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>      ";

echo"   <td width='50%' colspan='2' align='right' bgcolor='#F5F5F5' >&nbsp;</td>";			 
echo" </tr>";



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

echo" <tr>";
echo"   <td height='20' colspan='3' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </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");
}
	  
?>