<?php


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

include("config.inc.php");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");



$querylog="SELECT print as printaccess, ifNull(FI_Grn,0) As FI_Grn, ifNull(FI_Purchases,0) As FI_Purchases, 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);
}



$querylog="SELECT RI_transfer as loginaccess 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");
	
	

$querylog="select * from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."'";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
extract($rows);

}


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

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

}

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(loginstk.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());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";			  
$resultproject=mysql_query($queryproject,$connection) or die(mysql_error());


$querysordertype="select Sorder_Type, Sorder_TypeName from sordertype where FormType = 'Sorder' order by Sorder_Type";
$resultsordertype=mysql_query($querysordertype,$connection) or die(mysql_error());

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

print <<< HERE


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

<html>
<head>
<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>
<script type="text/javascript" language="javascript">

function showlistitem(str){
	window.open('select_item.php?item='+str+'&index=&PItem_Code=&ItemType=All&TransDate=&vcurr=','List_Warehouses','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showlistwarehouse(str){
	window.open('List_Warehouses.php?str='+str,'List_Warehouses','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

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


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


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


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

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

function PrintPrev(exp)
{
	var str='';
  	var x = document.transForm;
	
	var fromdate 	= x.fromdate.value;
	var todate 		= x.todate.value;
	
	var fromitem 	= x.fromitem.value;
	var toitem 		= x.toitem.value;
	
	var fromgroup 	= x.fromgroup.value;
	var togroup 	= x.togroup.value;
	
	var fromsubgroup 	= x.fromsubgroup.value;
	var tosubgroup 		= x.tosubgroup.value;
		
	var fromcategory 	= x.fromcategory.value;
	var tocategory 		= x.tocategory.value;
	
	var fromproject		= x.fromproject.value;
	var toproject		= x.toproject.value;
	
	var fromcostcent	= x.fromcostcent.value;
	var tocostcent		= x.tocostcent.value;
	
	var fromwh		= x.fromwarehouse_code.value;
	var towh		= x.towarehouse_code.value;
	
	var chkdetail = 0;
	if (document.getElementById('chk_detail').checked)
		chkdetail = 1;
	
	var grpused = document.getElementById('grpused').value;
	
	if (exp == 0) str = "rep_listoftransfer2.php";
	else if (exp == 1) str = "Exp_ListofTransfer2.php";
	
	str = str + "?fromdate="+fromdate+"&todate="+todate+"&fromitem="+fromitem+"&toitem="+toitem+"&fromgroup="+fromgroup+"&togroup="+togroup+
				"&fromsubgroup="+fromsubgroup+"&tosubgroup="+tosubgroup+"&fromcategory="+fromcategory+"&tocategory="+tocategory+"&fromproject="+fromproject+"&toproject="+toproject+
				"&fromcostcent="+fromcostcent+"&tocostcent="+tocostcent+"&fromwh="+fromwh+"&towh="+towh+"&chkdetail="+chkdetail+"&grpused="+grpused;
	
	window.open(str,"Report");
		
 
}

function clearPage(){
	var x = document.transForm;
	
	x.fromdate.value 	= '';
	x.todate.value 		= '';
	
	x.fromitem.value 	= '';
	x.toitem.value 		= '';
	
	x.fromgroup.value	= '';
	x.togroup.value		= '';
	
	x.fromsubgroup.value= '';
	x.tosubgroup.value	= '';
		
	x.fromcategory.value= '';
	x.tocategory.value	= '';
	
	x.fromproject.value	= '';
	x.toproject.value	= '';
	
	x.fromcostcent.value= '';
	x.tocostcent.value	= '';
	
	x.fromwarehouse_code.value  = '';
	x.towarehouse_code.value	= '';
	
	x.chk_detail.value = '';
	x.grpused.value = 1;
	x.action = "Form_ListofTransfer.php";
	x.submit();
}
	
</script>


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

<title>List of Transfer</title>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20101112" media="screen"></link>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20100118"></script>

</head>
<body>
HERE;

echo "<form id='transForm' name='transForm' method='post' action='$_SERVER[PHP_SELF]'>";

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'>  Transfer List</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'  title='Clear Page' onClick=\"clearPage()\"><span><span>Clear</span></span></button>";
     

	 echo" <button type='button' id='preview' name='preview' onClick=\"PrintPrev('0')\"; title='Preview'><span><span>Preview</span></span></button>";
	

if ($ExporttoExcel==1){
	 echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"PrintPrev('1')\"; 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' width='1100px'>";

// sub-table 1
echo "<tr><td><table border='0' align='center' width='1100px'>";
echo "<col width=100px><col width=200px><col width=400px><col width=400px>";

echo "<tr height='30px'>
		<td colspan='2' align='left'><span class='style8'>Date</span></td>
		<td></td>
		<td align='center'><span class='style8'>Group By</span></td>
	  </tr>";
	  
echo "<tr height='30px'>
		<td align='left'><span class='style8'>From</span></td>
		<td align='left'><input type='text' name='fromdate' value='$fromdate' maxlength='10' size='10'>
			 <a href='#' onClick=\"displayCalendar(document.transForm.fromdate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><image src='./img/cal.gif' border=0 align=center></image></a>
		</td>
		<td><input type='checkbox' name='chk_detail' id='chk_detail' value='0'><span class='style8'>Show Details</span></td>
		<td align='center' rowspan='3'><select name='grpused' id='grpused' multiple style='width:200px;height: 120px;'>
			<option value='1' selected>None</option>
			<option value='21'>From Project</option>
			<option value='22'>To Project</option>
			<option value='31'>From Costcenter</option>
			<option value='32'>To Costcenter</option>
			<option value='41'>From Warehouse</option>
			<option value='42'>To Warehouse</option>
			<option value='5'>Item Code</option>
			<option value='6'>Group</option>
			<option value='7'>Sub Group</option>
			<option value='8'>Category</option>			
		</select></td>
	  </tr>";
echo "<tr height='30px'>
		<td align='left'><span class='style8'>To</span></td>
		<td align='left'><input type='text' name='todate' value='$todate' maxlength='10' size='10'>
			 <a href='#' onClick=\"displayCalendar(document.transForm.todate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><image src='./img/cal.gif' border=0 align=center></image></a>
		</td>
		<td></td>
	</tr>";	
echo "<tr height='20px'><td colspan='4'></td></tr>";	
echo "</table></td></tr>";

// sub-table 2
echo "<tr><td><table border='0' align='center' width='1100px'>";
echo "<col width=100px><col width=400px><col width=100px><col width=100px><col width=400px>";

// Item Code and Group
echo "<tr height='20px'><td colspan='2'><span class='style8'>Item Code/Description</span></td><td><td></td><td colspan='2'><span class='style8'>Group </span></td></tr>";
echo "<tr height='15px'>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromitem' value='$fromitem' style='width:120px'> <input type='text' name='fromitemdesc' value='$fromitemdesc' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistitem('17');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromgroup' id='fromgroup' value='$fromgroup' style='width:120px'> <input type='text' name='fromgroupname' id='fromgroupname' value='$fromgroupname' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistgroups('14');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
	</tr>";

echo "<tr height='15px'>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='toitem' value='$toitem' style='width:120px'> <input type='text' name='toitemdesc' value='$toitemdesc' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistitem('18');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='togroup' id='togroup' value='$togroup' style='width:120px'> <input type='text' name='togroupname' id='togroupname' value='$togroupname' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistgroups('15');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
	</tr>";
echo "<tr height='20px'><td colspan='5'></td></tr>";	
	
// Subgroup and Category
echo "<tr height='20px'><td colspan='2'><span class='style8'>Subgroup</span></td><td><td></td><td colspan='2'><span class='style8'>Category </span></td></tr>";
echo "<tr height='15px'>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromsubgroup' id='fromsubgroup' value='$fromsubgroup' style='width:120px'> <input type='text' name='fromsubgroup_name' id='fromsubgroup_name' value='$fromsubgroup_name' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistsubgroups('9');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromcategory' id='fromcategory' value='$fromcategory' style='width:120px'> <input type='text' name='fromcategory_name' id='fromcategory_name' value='$fromcategory_name' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistcategory('7');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
	</tr>";

echo "<tr height='15px'>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='tosubgroup' id='tosubgroup' value='$tosubgroup' style='width:120px'> <input type='text' name='tosubgroup_name' id='tosubgroup_name' value='$tosubgroup_name' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistsubgroups('10');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='tocategory' id='tocategory' value='$tocategory' style='width:120px'> <input type='text' name='tocategory_name' id='tocategory_name' value='$tocategory_name' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistcategory('8');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
	</tr>";
echo "<tr height='20px'><td colspan='5'></td></tr>";

// Project and Costcenter
echo "<tr height='20px'><td colspan='2'><span class='style8'>Project</span></td><td><td></td><td colspan='2'><span class='style8'>Costcenter </span></td></tr>";
echo "<tr height='15px'>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromproject' id='fromproject' value='$fromproject' style='width:120px'> <input type='text' name='fromprojectdesc' id='fromprojectdesc' value='$fromprojectdesc' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistProject('1');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromcostcent' id='fromcostcent' value='$fromcostcent' style='width:120px'> <input type='text' name='fromcostcentdesc' id='fromcostcentdesc' value='$fromcostcentdesc' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistCostcenter('1');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
	</tr>";

echo "<tr height='15px'>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='toproject' id='toproject' value='$toproject' style='width:120px'> <input type='text' name='toprojectdesc' id='toprojectdesc' value='$toprojectdesc' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistProject('3');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='tocostcent' id='tocostcent' value='$tocostcent' style='width:120px'> <input type='text' name='tocostcentdesc' id='tocostcentdesc' value='$tocostcentdesc' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistCostcenter('4');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
	</tr>";
echo "<tr height='20px'><td colspan='5'></td></tr>";	

// Warehouse
echo "<tr height='20px'><td colspan='2'><span class='style8'>Warehouse</span></td><td><td></td><td colspan='2'><span class='style8'> </span></td></tr>";
echo "<tr height='15px'>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromwarehouse_code' id='fromwarehouse_code' value='$fromwarehouse_code' style='width:120px'> <input type='text' name='fromwarehouse_name' id='fromwarehouse_name' value='$fromwarehouse_name' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistwarehouse('10');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td></td>
		<td></td>
	</tr>";

echo "<tr height='15px'>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='towarehouse_code' id='towarehouse_code' value='$towarehouse_code' style='width:120px'> <input type='text' name='towarehouse_name' id='towarehouse_name' value='$towarehouse_name' style='width:200px'>
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' onClick=\"showlistwarehouse('11');\"><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label> 	
		</td>
		<td></td>
		<td></td>
		<td></td>
	</tr>";
echo "<tr height='20px'><td colspan='5'></td></tr>";	
	
echo "</table></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>";

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

?>
