<?php

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


include("config.inc.php");
include("function.inc.php");
include("Functions_Trans.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");

$fromdate   =$_POST["fromdate"];
$todate     =$_POST["todate"];

$querydate="select search_startingdate from setup";
$resultdate=mysql_query($querydate,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdate)){
	extract($rows);
}	
$MainCompanyName=explode('_',$_SESSION['dbName']); 
$QueryDir = " Select Date_Format(StartFinancialDate,'%d/%m/%Y') 
			From ".$_SESSION['dbLabel'].".Directories ". 	
			" Where  Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			" and Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
//echo $QueryDir;			
$ResultDir=mysql_query($QueryDir,$connection) or die(mysql_error());   
$RowsDir=mysql_fetch_row($ResultDir);
$StartFinancialDate = $RowsDir[0];


if ($fromdate == '') {
if ($search_startingdate == '-1') {
	$fromdate = $StartFinancialDate;
}

else if($search_startingdate == '0') {
	$fromdate = date('01/m/Y');
}

else if($querydate > '0') {
	$added_timestamp = strtotime('-'.$search_startingdate.' month', time());

	$fromdate = date('01/m/Y', $added_timestamp); 
}
}

if ($todate == '')
	$todate =  date('d/m/Y');

if ($TransType=='Tr') {
	$querylog="select ifNull(FI_ITransferDel,0) As FI_ITransferDel, ifNull(FI_TransferMod,0) As FI_TransferMod 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);
	}
	//Access Mode On Insert/Edit/Delete
	$TrDelMode = 1;
	$TrEditMode =1;
	if ($FI_ITransferDel == 0)
		$TrDelMode =0;
	if ($FI_TransferMod == 0)
		$TrEditMode =0;	
	//FI_ProductionDel  FI_TransferMod FI_TransferApp
}
else {
	$querylog="select ifNull(FI_IRmTransferDel,0) As FI_IRmTransferDel, ifNull(FI_RmTransferMod,0) As FI_RmTransferMod 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);
	}
	//Access Mode On Insert/Edit/Delete
	$TrDelMode = 1;
	$TrEditMode =1;
	if ($FI_IRmTransferDel == 0)
		$TrDelMode = 0;
	if ($FI_RmTransferMod == 0)
		$TrEditMode =0;	
	//FI_ProductionDel  FI_TransferMod FI_TransferApp
}



if (empty($orderby)) $orderby = 1;




	//echo $TrEditMode." ".$TrDelMode;
$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

$MainCompanyName=explode('_',$_SESSION['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays, ifNull(AllowLockedPeriod,0) As AllowLockedPeriod, ".
			  " LockedPeriod As LockedPeriodDate, LockedPeriodDays As LockedPeriodDays ".
              " From ".$_SESSION['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$_SESSION['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	
			  
			  
$querylog=" select ifNull(FI_TransferRequest,0) As FI_TransferRequest ,login_belongstogrp, ifNull(ShowTransaction,0) As ShowTransaction ".
          " 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);
}

$querywh=" 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']."') ".
		 " order by warehouse.warehouse_code";

		 $resultwh = mysql_query($querywh,$connection) or die(mysql_error());
$whexist  = mysql_num_rows($resultwh);



//echo $queryperiod;	

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

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

$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$_SESSION['dbLabel'].".ledgerstk  ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];

print <<<HERE
<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/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<title>Search Transfer Request</title>
<script type="text/javascript" language="javascript">
function set_limit(TransType){
	perpage=document.search.perpage.value;
	document.search.submit();
}

function clearform(TransType)
{
  document.search.keyword.value='';
  document.search.fromdate.value = '';
  document.search.todate.value = '';
  document.search.action='Form_TransferRequestSearch.php?TransType='+TransType;
  document.search.submit();

}

function LoadForm(TransType) 
{
	x=document.search;
	x.keyword.focus();
	
	ChangeLocation(TransType);
}

function SetNextPage(startrange,perpage,TransType){
	document.search.action='Form_TransferRequestSearch.php?keyword=&startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}

function SetPrvPage(startrange,perpage,TransType){
	document.search.action='Form_TransferRequestSearch.php?keyword=&startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}

function SelectStatus(TransType)
{
  document.search.keyword.value='';
    document.search.action='Form_TransferRequestSearch.php?TransType='+TransType;
  document.search.submit();

}

function DeleteRecord(TrId, SorRef,TransType){

	if (TrId != '') {
		if (confirm ( "Are you sure you want to Delete this record with reference = "+SorRef+" ?") )
		{
			document.search.action="Form_TransferRequest_Actions.php?actionmode=delete&transferrequest_id="+TrId+"&TransType="+TransType;
			document.search.submit();
		}
	}
	
}

function UpdateRecord(TrId,obj,TransType){
	
	 

	document.search.action="Form_TransferRequest_Actions.php?actionmode=search&transferrequest_id="+TrId+"&TransType="+TransType;;
	document.search.submit();
	
	document.search.PMode.value=1;
	
	opener.document.transferrequest.transferrequest_id.value=TrId;
	opener.document.transferrequest.actionmode.value='edit';
}

function PrintPreview(TrId,TransType)
{
	var Vdetail=0;
	var str = '';
	
	if (TransType!='Tr')
	if (confirm ( "Do you want to Print with detail?"))
	{
		Vdetail = 1;	
	}
	
	if (TransType=='Tr')
		Vdetail = 1;
	
	str = 'Form_TransferRequestPreview.php?transferrequest_id='+TrId+'&TransType='+TransType+'&detail='+Vdetail;
	window.open(str);

}

function ChangeLocation(TransType)
{
    if (document.search.PMode.value == 1) {
		opener.document.transferrequest.action='Form_TransferRequest.php?TransType='+TransType;
		opener.document.transferrequest.submit();
		self.close();
	}	
}

function SubmitForm(TransType)
{	
  document.search.action='Form_TransferRequestSearch.php?startrange=0&TransType='+TransType;
 document.search.submit();

}

function RefreshPage(perpage,TransType)
{
  
  //document.search.keyword.value='';
  document.search.action='Form_TransferRequestSearch.php?startrange=0&perpage='+perpage+'&TransType='+TransType;
  document.search.submit();

}

function SetFirstPage(startrange,perpage,TransType){
	document.search.action='Form_TransferRequestSearch.php?startrange=0&perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}

function SetLastPage(perpage,totalrows,TransType){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.search.action='Form_TransferRequestSearch.php?startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}
function ShowHideDetails(PurId, Option, startrange) {
	vSlideDivId = '#displaydetails'+PurId;
	$(vSlideDivId).slideToggle();
}
function showAllDetails(){ 
	if (document.search.showDetails.checked) {
		$('.slideAll').slideDown();
	}else{
		$('.slideAll').slideUp();
	}
}
</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 9px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</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 onLoad='LoadForm("$TransType");' class='bodybackground'>
<form name='search' method='post' action=''>
HERE;


$PRef = GetSQLValueString($keyword, 'text');

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;
			
					
$querysearch=" select transferrequest.transferrequest_reference,date_format(transferrequest.transferrequest_date,'%d-%m-%Y') as datte1,transferrequest.transferrequest_remark,".
			"transferrequest.project_code1,transferrequest.project_code2,Costcent.Costcent_name ,".
			 " Project1.Project_Name As ProjectName ,
			 Project2.Project_Name As ProjectName2 ,
			 warehouse1.warehouse_name  as warehousefrom, warehouse2.warehouse_name as warehouseto,
			 transferrequest.driver_name,transferrequest.vehicle_no , transferrequest.transferrequest_id as transferrequest_id ,ifnull(temp_transferrequest.transferrequest_id,-1) 
			 from transferrequest ".
			 " Left Join Project Project1 on transferrequest.Project_Code1 = Project1.Project_Code ".
			 " Left Join Project Project2 on transferrequest.Project_Code2 = Project2.Project_Code ".
			 " Left Join warehouse warehouse1 on transferrequest.Transferrequest_WarehouseFrom = warehouse1.warehouse_Code ".
			 " Left Join warehouse warehouse2 on transferrequest.Transferrequest_WarehouseTo = warehouse2.warehouse_Code ".
			 " Left Join Costcent on transferrequest.costcenter_code = Costcent.Costcent_code ".
			 " Left Join temp_transferrequest on transferrequest.transferrequest_id = temp_transferrequest.transferrequest_id " ;
//echo $querysearch;
			
			 
if ($projectexist >	0)
  $querysearch= $querysearch." left join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q1 on transferrequest.project_code1 like concat(Q1.project_code,'%') ";

if ($projectexist >	0)
  $querysearch= $querysearch." left join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q2 on transferrequest.project_code2 like concat(Q2.project_code,'%') ";

							 
if ($costcentexist > 0)
  $querysearch= $querysearch." left join ( select distinct costcent_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (costcent_code is not null and costcent_code != '') ".
							 "			 ) Q3 on transferrequest.costcenter_code like concat(Q3.costcent_code,'%') ";							 

$querysearch= $querysearch.											 
			 " Where transferrequest.Transferrequest_Reference = ifNull($PRef, transferrequest.Transferrequest_Reference) ".
			" and Upper(ifnull(transferrequest.Transferrequest_Type,'Tr'))= Upper('".$TransType."')".		
			"	and ifnull(transferrequest.Transferrequest_BelongsToGroup,0) >=	".$login_belongstogrp."		".
			 " And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(transferrequest.Transferrequest_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',transferrequest.Transferrequest_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
             "                                                      and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(transferrequest.Transferrequest_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ";

if ($ShowTransaction != 1)
	$querysearch= $querysearch." And Upper(transferrequest.User_Account) = Upper('".$_SESSION['useraccount']."') ";
	
if ($whexist > 0)
{
  $querysearch= $querysearch." and (";
  $querysearch= $querysearch."  (transferrequest.transferrequest_warehousefrom In (select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  )"; 
  $querysearch= $querysearch." or (transferrequest.transferrequest_warehouseto In (select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  )";  
  $querysearch= $querysearch." )";
  }			 

  if ($fromdate != '' && $todate !='' )
	$querysearch = $querysearch." And Date_Format(transferrequest.transferrequest_date,'%Y-%m-%d') between '".explodeword($fromdate)."' and '".explodeword($todate)."' ";
	

  if ($orderby == 1)
	$querysearch= $querysearch." Order By transferrequest.transferrequest_Date Desc, transferrequest.transferrequest_Reference Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By transferrequest.transferrequest_Reference Desc ";	


  
  //$querysearch= $querysearch." Order By transferrequest.Transferrequest_Date Desc ";
			 
//echo $querysearch;


$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
if ($startrange=='')
	$startrange = 0;
	
if ($perpage=='')
	$perpage = 20;


	if ($PRef=='' or $PRef=='Null')	
	$querysearch = $querysearch." limit ".$startrange.",".$perpage;

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' width='1060px'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px;' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of 	";
			if ($TransType=='Rm')
			echo "Rm";
		echo" Transfer Requests</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";

echo"<table border='0' style='table-layout:fixed'>
	  <col width=20>
	  <col width=20>
	  <col width=20>
	  <col width=65>
	   <col width=100>
	  <col width=100>
	  <col width=100>
	  <col width=150>
	  <col width=140>
	  <col width=280>
	
	  
	
	  <tr class='Search-header-bg'>
	    <td align='left' colspan='5'><span class='style4'>Search by Reference</span></td>
		<td align='left' colspan='3'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		   <button type='button' id='btnSubmit' name='btnSubmit' onclick=SubmitForm('$TransType'); return false; title='Find'><span><span>Find</span></span></button>
			<button type='button' id='btnCancel' name='btnCancel' onclick=clearform('$TransType'); return false; title='Cancel'><span><span>Cancel</span></span></button>
		</td>
	";

			 echo" <td align='left' colspan='3'><span class='style4'>Order By</span>
		  <span class='style4'><select name='orderby' id='orderby' value='$orderby' onchange='SelectStatus(\"$TransType\");'>";
		
		if ($orderby==1)
			$s11 = 'selected';
		else if ($orderby==2)
			$s12 = 'selected';
			
		echo"<option ".$s11." value='1'>Date</option>
			 <option ".$s12." value='2'>Reference</option>
			 </select></span>";
	echo "&nbsp;&nbsp;<span class='style4'>Show Details</span><input type='checkbox' name='showDetails' id='showDetails' onclick='showAllDetails()' value='' >";		 
	echo "</td>";
echo" </tr>
<tr class='Search-header-bg' height='23px'>
<td colspan='11'><span class='style4'>From&nbsp;</span><input type='text' name='fromdate' id='fromdate' value='$fromdate' maxlength='10' size='9'>
		<A HREF=\"#\" onClick=\"displayCalendar(document.search.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>
&nbsp; &nbsp;<span class='style4'>To&nbsp;</span><input type='text' name='todate' id='todate' value='$todate' maxlength='10' size='9'>
		<A HREF=\"#\" onClick=\"displayCalendar(document.search.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>
</tr>
</table></td>

		<td id='search-content3' style='width:31px;'>&nbsp;</td>"; 
echo" </tr>";
	 
echo"<tr>
		<td  id='search-content1' style='height:34px;width:31px;'>&nbsp;</td>
		<td  id='search-content2' style='height:34px;width:1025px;'>
		<table width='100%' border=0>
		<tr>
			<td align='right' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage('$perpage','$TransType');\">";
              
            $perpages = $config['trowlimit'];
			foreach ($perpages as $val){
			echo" <option value = '$val' "; if ($perpage ==$val) echo "selected"; 
			echo" >$val</option> ";
			}
	echo'	
				 </select></span></td>
			<td  style="width:74px;border-right:1px solid #000000;text-align:right;">';
			
			if($startrange > 0)
				echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."','".$TransType."')>";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."','".$TransType."')>";
			}
			else
				echo "&nbsp;";
		
echo"		</td><td  align='left' style='width:74px;'>";
		
		
			if ($startrange <= $totalrows){
				$startrange1 = $startrange + $perpage;
				if  ($startrange1 < $totalrows){
					echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."','".$TransType."')>";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."','".$TransType."')>";	
				}
			} else
				echo "&nbsp;";
				
			
echo"		</td><td style='width:380px;'>&nbsp;</td>
		</tr>";
echo"	</table></td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>";
echo"</tr>";			

	  
 echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		<td id='search-content2'>
			<div style='overflow:scroll;height:400px;width:1000px;'>
			<table border='0'  cellpadding='0' cellspacing='1' >
			  <col width=20>
			  <col width=20>
			  <col width=20> <col width=20>
			  <col width=65>
			  <col width=100>
			  <col width=100>
			  <col width=100>
			  <col width=150>
			  <col width=140>
			  <col width=150>
			  <col width=150>
			";

if($message!=''){
	echo"	  <tr class='Search-header-bg'>
	<td height='15' align='center' colspan='11' class='searchmessage'>".$message."</td>
	</tr>";
}
	
echo"<tr class='Search-Label-bg'>
	    <td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>Reference </span></td>
		<td  height='25' align='center'><span class='style4'>Date </span></td>	
		<td  height='25' align='center'><span class='style4'>Project From</span></td>
		<td  height='25' align='center'><span class='style4'>Project To</span></td>
		<td  height='25' align='center'><span class='style4'>Warehouse From</span></td>
		<td  height='25' align='center'><span class='style4'>Warehouse To</span></td>
		<td  height='25' align='center'><span class='style4'>CostCenter</span></td>
		<td  height='25' align='center'><span class='style4'>Remark</span></td>
		
		
	  </tr>";
		




while($rows=mysql_fetch_array($resultsearch)){
	$ExceedLockPeriod = 0;	
		if ($rows[13]!='-1')
			{
				$imgstat_edit = 0;
				$imgstat_del = 0;
				$imgstat_prv = 0;
				$titleprev = 'Exists in pending..';
				$titleedit = 'Exists in pending..';
				$titledelete = 'Exists in pending..';
			}
		else
			{
			if ($TrEditMode==1)
				$imgstat_edit = 1;		
			else
				$imgstat_edit = 0;
			
			if ($TrDelMode==1)
				$imgstat_del = 1;
			else
				$imgstat_del =0;
				
				$imgstat_prv = 1;
				
			$titleprev = 'Preview';
			$titleedit = 'Edit Record';
			$titledelete = 'Delete record';
			}
			//echo $imgstat_edit;
	extract($rows);
	$ct+=1;

	if ($rowsperiod > 0 && $AllowLockedPeriod == 1) {
		if (!(empty($LockedPeriodDate)) && $LockedPeriodDate != '' && date('Y-m-d',strtotime(insertMySQLDate($rows[1]))) <= date('Y-m-d',strtotime($LockedPeriodDate))) $ExceedLockPeriod = 1;
		if ($LockedPeriodDays != '' && dateDiff(insertMySQLDate(displayToday()),insertMySQLDate($rows[1])) >= $LockedPeriodDays) $ExceedLockPeriod = 1;
	}
	
	if ($ExceedLockPeriod == 1){
		$imgstat_edit = 0;
		$imgstat_del = 0;
	}
	
	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
			
			/*
			$imgstat = 'enabled';
			$titleprev = 'Preview';
			$titleedit = 'Edit Record';
			$titledelete = 'Delete record';
			*/
			
	$transferrequest_id = $rows[12];		
	echo'<tr '.$Color.'>';
		
		
		if($imgstat_prv==1)
	       echo' <td align="left"><span class="style5"><img src="img/mag.jpg" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$rows[12].',\''.$TransType.'\');" style="width:15px; height:15px; " title="'.$titleprev.'" ></span></td>';
		 else echo'<td align="center">&nbsp;</td>';  
		
		if($imgstat_edit==1)
			echo'<td align="left"><span class="style5">
			<img  src="img/edit.png" onMouseOver="style.cursor=\'hand\'" onclick="UpdateRecord('.$rows[12].',this,\''.$TransType.'\');" title="'.$titleedit.'" style="width:20px; height:20px; " ></span></td>';
		 else echo'<td align="center">&nbsp;</td>';  	
			
		if($imgstat_del==1)	
			echo'<td align="left"><span class="style5"><img src="img/delete.png" onMouseOver="style.cursor=\'hand\'" onclick="DeleteRecord('.$rows[12].', '.$rows[0].',\''.$TransType.'\');" title="'.$titledelete.'" style="width:20px; height:20px; "  ></span></td>';
		 else echo'<td align="center">&nbsp;</td>';  
		echo'	<td align="center"><span class="style5"><img src="img/details.gif" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$transferrequest_id.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:15px; height:15px; "></span></td>';
 
		echo'<td align="left"><span class="style5">'.$rows[0].'</span></td>
			<td align="left"><span class="style5">'.$rows[1].'</span></td>
			<td align="left"><span class="style5">'.$rows[6].'</span></td>
			<td align="left"><span class="style5">'.$rows[7].'</span></td>
			<td align="left"><span class="style5">'.$rows[8].'</span></td>
			<td align="left"><span class="style5">'.$rows[9].'</span></td>
			<td align="left"><span class="style5">'.$rows[5].'</span></td>
			<td align="left"><span class="style5">'.$rows[2].'</span></td>
		</tr>';
	
	$sub_query = " select TransferrequestDt_id, transferrequestdt.Item_CodePacked,transferrequestdt.Item_code,Item_Description,
				  TransferrequestDt_WarehouseFrom,TransferrequestDt_WarehouseTo,Item_UnitPurchaseDesc,TransferrequestDt_Quantity,
				  TransferrequestDt_Price, round(TransferrequestDt_Quantity*TransferrequestDt_Price,".$DecimalBase.") as total
				  from transferrequestdt
				  Left Join Items on transferrequestdt.Item_code = Items.Item_code 
				  where Transferrequest_Id = $transferrequest_id"; 
	$sub_result=mysql_query($sub_query,$connection) or die(mysql_error($connection));	
	$sub_totalrows = mysql_num_rows($sub_result);
		
	if ($sub_totalrows > 0) {
		$SlideDivId = 'displaydetails'.$transferrequest_id;
			
		echo "<tr ".$Color.">";
		echo "<td colspan='16' valign='top' align='left'><div id='$SlideDivId' class='div-search-details slideAll' style='display:none; margin-left:100px;'>";
		echo "<table border='0' style='table-layout:fixed; width:920px;' cellpadding='0' cellspacing='1'>";
		echo "<tr><td width='140px'><span class='style4'>Item Code</span></td>
				  <td width='240px'><span class='style4'>Description</span></td> 
				  <td width='100px'><span class='style4'>From Warehouse</span></td> 
				  <td width='100px'><span class='style4'>To Warehouse</span></td> 
				  <td width='60px' align='center'><span class='style4'>Unit1</span></td>
				  <td width='80px' align='center'><span class='style4'>Qty</span></td>
				  <td width='100px' align='center'><span class='style4'>Price</span></td>
				  <td width='120px' align='center'><span class='style4'>Total</span></td>
			 </tr>";
		while($sub_rows=mysql_fetch_array($sub_result)){
			echo "<tr><td align='left' valign='top' class='style9'>".$sub_rows[2]."</td>
					  <td align='left' valign='top' class='style9'>".$sub_rows[3]."</td>
					  <td align='left' valign='top' class='style9'>".$sub_rows[4]."</td>
					  <td align='center' valign='top' class='style9'>".$sub_rows[5]."</td>
					  <td align='right' valign='top' class='style9'>".$sub_rows[6]."</td>";
			echo" <td align='right' valign='top' class='style9'>".number_format($sub_rows[7],$DecimalBase)."</td>
				  <td align='right' valign='top' class='style9'>".number_format($sub_rows[8],$DecimalBase1)."</td>
				  <td align='right' valign='top' class='style9'>".number_format($sub_rows[9],$DecimalBase2)."</td>";
		
			
  			echo "</tr>";
				
		}
			
		echo "</table></div></td>";
		echo "</tr>";
	}	
}
							

			
echo"</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			
echo"   <tr ><td id='search-content1'>&nbsp;</td><td id='search-content2'>&nbsp;</td><td id='search-content3'>&nbsp;</td></tr>";
echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:908px;' valign='top'><table width='100%' border=0 height=28px>
		<tr><td style='width:380px;'>&nbsp;</td><td align='right' style='width:74px;border-right:1px solid #000000;'>";

		
		if($startrange>0)
			echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."','".$TransType."')>";

		//$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			//$prvstartrange = $startrange - $perpage;
			echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."','".$TransType."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='left' style='width:74px;'>";
		
		
		if ($startrange <= $totalrows){
			//$startrange = $startrange + $perpage;
			if  ($startrange1 < $totalrows){
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."','".$TransType."')>";
				echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."','".$TransType."')>";	
			}
		} else
			echo "&nbsp;";
	
			
		echo"</td><td style='width:380px;'>&nbsp;</td></tr>";
		echo"</table></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td>";

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


          

		  

print <<<HERE
</form>
</body>

HERE;

function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}

?>