<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
$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');

//Read From Module Table
$querymodule=" Select ifNull(Module_TransferConfirmation,0) As Module_TransferConfirmation, ifNull(Module_Project,0) As Module_Project ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$transwh = array();
$query="select TransferWH as TransferWH from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' ";
//echo $query;
$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
	extract($rows);
	array_push($transwh,strtoupper($TransferWH));
}



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;

if (empty($searchby)) $searchby = 2;

if (empty($viewproject)) $viewproject = 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,FI_login_ViewDocument as FI_login_ViewDocument ".
              " 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_Transfer,0) As FI_Transfer ,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];

//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);
}
$fromproject = "".$fromproject;
if ($fromproject == '' && $Module_Project == 1)
	$fromproject = $defaultproject;

if ($trStatus == '') $trStatus='*';
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</title>
<script type="text/javascript" language="javascript">


function kd(e)
{
	x=document.search;
    var intKey = (window.Event) ? e.which : e.keyCode;
	
    if (intKey == 13) { //enter key
        x.btnSubmit.click();
		return false;
    }
    return true;
}

function ConfirmTransfer(TrId,TrRef,TransType){


		var vMsg = '';
	
		vMainMode = 'ConfirmTransfer'; 
		vMsg = 'Are you sure you want to Confirm order with reference = '+TrRef+' ?';
	
	if (TrId != '') {
		if (confirm (vMsg) )
		{
			document.search.action="Form_Transfer_Actions.php?mainmode="+vMainMode+"&TrId="+TrId+"&TransType="+TransType;
			document.search.submit();
		}
	}

}

function set_limit(TransType){
	perpage=document.search.perpage.value;
//	document.search.action='Form_TransferSearch.php?perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}

function clearform(TransType)
{
  document.search.keyword.value='';
  document.search.searchby.value='';
  document.search.fromdate.value = '';
  document.search.todate.value = '';
  
  document.search.fromwh.value = '';
  document.search.towh.value = '';
  
  if (document.search.fromproject)
	document.search.fromproject.value = '';
  if (document.search.toproject)
	document.search.toproject.value = '';
  
  document.search.action='Form_TransferSearch.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_TransferSearch.php?keyword=&startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}

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

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

}

function UploadDocuments(vform,txtPorId){
	win = window.open('UploadDocuments.php?vform='+vform+'&prqstid='+txtPorId +'&readonly=readonly', 'Upload', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');		
	  win.creator = self;
	  win.focus();	 
  
  }

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_Transfer_Actions.php?actionmode=delete&transfer_id="+TrId+"&TransType="+TransType;
			document.search.submit();
		}
	}
	
}

function UpdateRecord(TrId,obj,TransType){
	
	 

//	obj.disabled=true; 
//	obj.disable=false;
		
	document.search.action="Form_Transfer_Actions.php?actionmode=search&transfer_id="+TrId+"&TransType="+TransType;;
	document.search.submit();
	
	document.search.PMode.value=1;
	
	opener.document.transfer.transfer_id.value=TrId;
	opener.document.transfer.actionmode.value='edit';
}

function ShowHideDetails(TrId, Option, startrange) {
	/*if (Option == 'S') {
		document.search.SelectedID.value = TrId;
		document.search.action='Form_TransferSearch.php?startrange='+startrange+'&SelectedID='+TrId;
	}
	else if (Option == 'H') {
		document.search.SelectedID.value = '';
		document.search.action='Form_TransferSearch.php?startrange='+startrange;
	}	
	
	document.search.submit();*/
	
	vSlideDivId = '#displaydetails'+TrId;
	$(vSlideDivId).slideToggle();
}


function PrintPreview(TrId,TransType,exp)
{
	var hide='';
	if(document.getElementById('hide').checked)
	hide=1;
	else hide=0;
	var Vdetail=0;
	var str = '';
	
	if (TransType!='Tr')
	if (confirm ( "Do you want to Print with detail?"))
	{
		Vdetail = 1;	
	}
	
	if (TransType=='Tr')
		Vdetail = 1;
	var transPrev = document.getElementById("txttransferPrev").value;
	var waybillPrev = document.getElementById("txtwaybillPrev").value;
	
	if(transPrev == 1)
	str = 'Form_TransferPreview.php?transfer_id='+TrId+'&TransType='+TransType+'&detail='+Vdetail+'&hide='+hide+'&exp='+exp;
	else if(waybillPrev == 1)
	str = 'Form_TransferWaybillPreview.php?transfer_id='+TrId+'&TransType='+TransType+'&detail='+Vdetail+'&PLang=EN'+'&hide='+hide+'&exp='+exp;
	window.open(str);

}

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

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

}

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

}

function SetFirstPage(startrange,perpage,TransType){
	document.search.action='Form_TransferSearch.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_TransferSearch.php?startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;
	document.search.submit();
}
function showAllDetails(){ 
	if (document.search.showDetails.checked) {
		$('.slideAll').slideDown();
	}else{
		$('.slideAll').slideUp();
	}
}
function checkPrev(ptype){
	if(ptype==1){
		if(document.getElementById("txttransferPrev").checked)
			{
				document.getElementById("txtwaybillPrev").checked=false;
				document.getElementById("txtwaybillPrev").value=0;
				
				document.getElementById("txttransferPrev").value=1;
			}
		else if(!document.getElementById("txttransferPrev").checked)
			{
				document.getElementById("txtwaybillPrev").checked=true;
				document.getElementById("txtwaybillPrev").value=1;
				document.getElementById("txttransferPrev").value=0;
				document.getElementById("txttransferPrev").checked=false;
				
			}		
	}
	if(ptype==2){
		if(document.getElementById("txtwaybillPrev").checked)
			{
				document.getElementById("txttransferPrev").checked=false;
				document.getElementById("txttransferPrev").value=0;
				document.getElementById("txtwaybillPrev").value=1;
			}
		else if(!document.getElementById("txtwaybillPrev").checked)
			{
				document.getElementById("txttransferPrev").checked=true;
				document.getElementById(txttransferPrev).value=1;
				document.getElementById("txtwaybillPrev").value=0;
				document.getElementById("txtwaybillPrev").checked=false;
			
			}		
	}

}

function duplicateTransfer(transfer_id, trans_ref, TransType){
	var vMsg = 'Are you sure you want to Duplicate Transfer with reference = '+trans_ref+' ?';
	if (transfer_id != '') {
		if (confirm (vMsg) )
		{
			document.search.action="Form_Transfer_Actions.php?actionmode=duplicateTransfer&transfer_id="+transfer_id+"&TransType="+TransType;
			document.search.submit();
		}
	}
}


function SelectSearchBy()
{	

  document.search.submit();

}


function SelectRecord(Obj, SelectedRec, SelectedRecColor, transferid){

	if (document.getElementById(SelectedRec).value=='')
	{
		document.getElementById(SelectedRec).value = Obj.id;
		document.getElementById(SelectedRecColor).value = Obj.style.backgroundColor;
	}	
	else {

		var prevobj = document.getElementById(SelectedRec).value;
		document.getElementById(prevobj).style.backgroundColor = document.getElementById(SelectedRecColor).value;

		document.getElementById(SelectedRec).value = Obj.id;
		document.getElementById(SelectedRecColor).value = Obj.style.backgroundColor;
	}	

	document.getElementById('transferid').value = transferid;
	document.getElementById(Obj.id).style.backgroundColor ='#B8EDFF';

}

function generateBarcode2(){
	var TrId = document.getElementById('transferid').value;
	if(TrId == ''){
		alert("Please Select a Transfer!");
		return 0;
	} else {
		var str = "Rep_AllItemBarcode.php?transid="+TrId+"&trans_type=TR";
		window.open(str, 'itembarcode','width=260,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	}
}


function generateBarcode3(){
	var TrId = document.getElementById('transferid').value;
	if(TrId == ''){
		alert("Please Select a Transfer!");
		return 0;
	} else {
		var str = "Rep_AllItemBarcode3.php?transid="+TrId+"&trans_type=TR";
		window.open(str, 'itembarcode','width=260,height=500,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=38&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistWarehouse(str,wrh){

var TransType = 'Tr';
var text1value = document.getElementById(wrh).value;
window.open('List_TrsWarehouseGrid.php?item='+str+'&Warehouse='+wrh+'&TransType='+TransType+'&PLedger_number='+text1value,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');

}
</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=''>
<input type='hidden' name='transferid' id='transferid' value=''>
<input type='hidden' name='ReportSelected' id='ReportSelected' value=''>
<input type='hidden' name='SelectedRec' id='SelectedRec' value=''>
<input type='hidden' name='SelectedRecColor' id='SelectedRecColor' value=''>
HERE;

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

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;
			
					
$querysearch=" select distinct transfer.transfer_reference,date_format(transfer.transfer_date,'%d-%m-%Y') as datte1,transfer.transfer_remark,".
			 " transfer.project_code1,transfer.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, ".
			 " transfer.driver_name,transfer.vehicle_no , transfer.transfer_id ,ifnull(temp_transfer.transfer_id,-1),ifnull(transfer.transfer_confirmed,0) transfer_confirmed,transfer.transfer_warehouseto as WhTo,transfer.transfer_warehousefrom as WhFrom , transfer.user_account as TUserAccount".
			 " from transfer ".
			 " Left Join Project Project1 on Transfer.Project_Code1 = Project1.Project_Code ".
			 " Left Join Project Project2 on Transfer.Project_Code2 = Project2.Project_Code ".
			 " Left Join warehouse warehouse1 on Transfer.Transfer_WarehouseFrom = warehouse1.warehouse_Code ".
			 " Left Join warehouse warehouse2 on Transfer.Transfer_WarehouseTo = warehouse2.warehouse_Code ".
			 " Left Join Costcent on Transfer.costcenter_code = Costcent.Costcent_code ".
			 " Left Join temp_transfer on Transfer.transfer_id = temp_transfer.transfer_id ".
			 " Left Join transferdt on transferdt.transfer_id = transfer.transfer_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 Transfer.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 Transfer.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 Transfer.costcenter_code like concat(Q3.costcent_code,'%') ";							 

$querysearch= $querysearch.											 
		" Where ( ($searchby = 2 and Transfer.Transfer_Reference = ifNull($PRef, transfer.Transfer_Reference) ) or 
			($searchby = 1 and Date_Format(transfer.Transfer_Date,'%Y-%m-%d') = ifNull(Date_Format($PRef,'%Y-%m-%d'), Date_Format(transfer.Transfer_Date,'%Y-%m-%d')) ) or
			($searchby = 3 and Transfer.Transfer_Remark Like Concat('%', ifNull($PRef, transfer.Transfer_Remark),'%') )	) ".
		" and Upper(ifnull(Transfer.Transfer_Type,'Tr'))= Upper('".$TransType."')".		
		" and ifnull(transfer.Transfer_BelongsToGroup,0) >=	".$login_belongstogrp."		".
		" And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(transfer.Transfer_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',transfer.Transfer_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
        " and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(transfer.Transfer_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ";

if ($ShowTransaction != 1)
	$querysearch= $querysearch." And Upper(Transfer.User_Account) = Upper('".$_SESSION['useraccount']."') ";

if ($whexist > 0)
{
  $querysearch= $querysearch." and (";
  //$querysearch= $querysearch."  (transfer.transfer_warehousefrom In (select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  ) or"; 
  $querysearch= $querysearch."  (transfer.transfer_warehouseto In (select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  )";  
  $querysearch= $querysearch." )";
  }		


if ($fromproject != '')
	$querysearch= $querysearch." And Transfer.Project_code1 like concat('".$fromproject."','%') ";
if ($toproject != '')
	$querysearch= $querysearch." And Transfer.Project_code2 like concat('".$toproject."','%') ";

if ($fromwh != '')
	$querysearch= $querysearch." And Transferdt.TransferDt_WarehouseFrom like concat('".$fromwh."','%') ";
if ($towh != '')
	$querysearch= $querysearch." And Transferdt.TransferDt_WarehouseTo like concat('".$towh."','%') ";

if ($trStatus == '1')
	$querysearch= $querysearch." and ifnull(Transfer.transfer_confirmed,0) = 1 ";
else if ($trStatus == '0')
	$querysearch= $querysearch." and ifnull(Transfer.transfer_confirmed,0) = 0 ";

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

  if ($orderby == 1)
	$querysearch= $querysearch." Order By transfer.transfer_Date Desc, transfer.transfer_Reference Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By transfer.transfer_Reference Desc ";	
	

  
  //$querysearch= $querysearch." Order By Transfer.Transfer_Date Desc ";
			 
// echo $querysearch;exit;


$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='1090px'>";
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" Transfers</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"";


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=160>
	  <col width=200>";

echo "	<tr height='30px' class='Search-header-bg'>";	  
if ($Module_Project == 1) {
	echo" <td align='left' colspan='4'><span class='style4'>&nbsp; From Project</span></td>
	      <td align='left' colspan='2'><span class='style4'>
		    <input type='text' name='fromproject' id='fromproject' value='$fromproject' size='15' maxlength='20' onkeydown=\"return kd(event)\" /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject('1');\"  /></span></label></td>";
	echo" <td align='left' colspan='1'><span class='style4'>&nbsp; To Project</span></td>
	      <td align='left' colspan='2'><span class='style4'>
		    <input type='text' name='toproject' id='toproject' value='$toproject' size='15' maxlength='20' onkeydown=\"return kd(event)\" /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject('2');\"  /></span></label></td>";
	echo "<td colspan='2'><span class='style4'>&nbsp; View Project by </span><select name='viewproject' style='width:100px;' onchange=\"SubmitForm('$TransType');\">";
	echo "<option value='1' ".($viewproject=='1'?'selected':'').">Code</option>";
	echo "<option value='2' ".($viewproject=='2'?'selected':'').">Name</option>";
	echo "</select></td>";
} else {
	echo" <td align='left' colspan='6'><input type='hidden' name='fromproject' id='fromproject' value='$fromproject' /></td>";
	echo" <td align='left' colspan='3'><input type='hidden' name='toproject' id='toproject' value='$toproject' /></td>";
	echo "<td colspan='2'><input type='hidden' name='viewproject' id='viewproject' value='$viewproject' /></td>";
}	


echo "</tr>";	

echo "	<tr height='30px' class='Search-header-bg'>";	  

	echo" <td align='left' colspan='4'><span class='style4'>&nbsp; From WH</span></td>
	      <td align='left' colspan='2'><span class='style4'>
		    <input type='text' name='fromwh' id='fromwh' value='$fromwh' size='15' maxlength='20' onkeydown=\"return kd(event)\" /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistWarehouse('fromwh','fromwh');\"  /></span></label></td>";
	echo" <td align='left' colspan='1'><span class='style4'>&nbsp; To WH</span></td>
	      <td align='left' colspan='2'><span class='style4'>
		    <input type='text' name='towh' id='towh' value='$towh' size='15' maxlength='20' onkeydown=\"return kd(event)\" /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistWarehouse('towh','towh');\"  /></span></label></td>";
	echo "<td colspan='2'></td>";


echo "</tr>";
  
echo "	<tr height='30px' class='Search-header-bg'>
	    <td align='left' colspan='4'><span class='style4'>&nbsp; Search by</span></td>
		<td align='left' colspan='4'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' size='15' maxlength='30' onkeydown=\"return kd(event)\"/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30' /></span>
			<select name='searchby' id='searchby' value='$searchby' onchange='SelectSearchBy();'>";
			if ($searchby==1)		$s21 = 'selected';
			else if ($searchby==2)	$s22 = 'selected';
			else if ($searchby==3)	$s23 = 'selected';
			
			echo"<option ".$s21." value='1'>Date (yyyy-mm-dd)</option>
				 <option ".$s22." value='2'>Reference</option>
				 <option ".$s23." value='3'>Remark</option>";	
	echo "	</select>
			<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='2'><span class='style4'>Show Details</span><input type='checkbox' name='showDetails' id='showDetails' onclick='showAllDetails()' value='' >&nbsp;&nbsp;
			<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></td>";
			 echo "<td align='left' colspan='1'><span class='style4'><input type='checkbox' value='0'  name='hide' id='hide'></span><span class='style4'>hide header/footer</span></td>";

echo" </tr>";
if($txttransferPrev=='') $txttransferPrev=1;
if($txtwaybillPrev=='') $txtwaybillPrev=0;
echo "<tr height='30px' class='Search-header-bg'><td colspan='8'><span class='style4'>";
echo "	<button type='button' id='btnBar2' name='btnBar2'  onclick=\"generateBarcode2();\" title='Print Barcode 2'><span><span>Barcode 2</span></span></button>
		<button type='button' id='btnBar3' name='btnBar3'  onclick=\"generateBarcode3();\" title='Print Barcode 3'><span><span>Barcode 3</span></span></button>
	&nbsp;&nbsp;";
echo "<input type='checkbox' name='txttransferPrev' id='txttransferPrev' onclick=\"checkPrev(1);\" value='$txttransferPrev' checked> Transfer</span>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='style4'>";

echo "<input type='checkbox' name='txtwaybillPrev' id='txtwaybillPrev' onclick=\"checkPrev(2);\" value='$txtwaybillPrev'> Waybill</span>";
echo "<span class='style4'>";
if ($Module_TransferConfirmation == 1){
	echo "&nbsp;&nbsp; Show <select name='trStatus' id='trStatus' onchange=\"SelectStatus('$TransType');\" style='width:100px;'>
			<option value='*' ".($trStatus=='*'?'selected':'').">All</option>
			<option value='1' ".($trStatus=='1'?'selected':'').">Confirmed</option>
			<option value='0' ".($trStatus=='0'?'selected':'').">Unconfirmed</option>
			</select>";
	
} else echo "<input type='hidden' name='trStatus' id='trStatus'>";

echo "</td>";
echo"<td colspan = 3><span class='style4'>From&nbsp;</span><input type='text' name='fromdate' id='fromdate' value='$fromdate' maxlength='10' size='9' onkeydown=\"return kd(event)\">
		<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' onkeydown=\"return kd(event)\">
		<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>";

echo"</tr>";
echo "</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:1020px;'>
			<table border='0'  cellpadding='0' cellspacing='1' style='width:1180px;'>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=70>
			  <col width=100>
			  <col width=120>
			  <col width=120>
			  <col width=150>
			  <col width=150>
			  <col width=150>
			  <col width=200>
			  <col width=100>";
			  
	if($message!=''){
		echo"<tr class='Search-header-bg'>
				<td height='15' align='center' colspan='12' 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'>&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>
			<td  height='25' align='center'><span class='style4'>User</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';
			*/
			
			
	echo'<tr '.$Color.' ';
	echo " onMouseOver=\"style.cursor='pointer'\"  id='row$ct' onclick=\"SelectRecord(this,'SelectedRec','SelectedRecColor','".$rows[12]."');\" ";	
	echo ">";
		
	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.'\',0);" style="width: 15px; height: 15px; " title="'.$titleprev.'" ></span></td>';
		echo'<td align="center"><span class="style5"><img src="img/excelbtn.png" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$rows[12].',\''.$TransType.'\',1);"  title="Exp Excel" style="width:20px; height:20px; " '.$PrevMode.'></span></td>';
	} else {
		echo'<td align="center" ><span class="style5"></span></td>';
		echo'<td align="center" ><span class="style5"></span></td>';
	}	
		
	if($imgstat_edit==1 and  (  ($Module_TransferConfirmation==1 && $rows[14]==0 && (in_array(strtoupper($WhFrom), $transwh) or $TransferWH=='')) or  ($Module_TransferConfirmation==0 )))
		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 and  (  ($Module_TransferConfirmation==1 and $rows[14]==0) or  ($Module_TransferConfirmation==0 )))	
		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>';  
	
	if ($imgstat_edit == 1 and  (  ($Module_TransferConfirmation==1 and $rows[14]==0) or  ($Module_TransferConfirmation==0 )))		
	echo'<td align="center"><span class="style5"><img src="img/duplicate-icon.png" onMouseOver="style.cursor=\'hand\'" onclick="duplicateTransfer('.$rows[12].', \''.$rows[0].'\', \''.$TransType.'\')"; title="Duplicate Transfer" style="width: 15px; height: 15px; "  ></span></td>';
	else 	
	echo'<td align="center"><span class="style5">&nbsp;</span></td>';	
	echo'	<td align="center"><span class="style5"><img src="img/details.gif" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$rows[12].', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:15px; height:15px; "></span></td>';
	if($FI_login_ViewDocument==1){
	echo'<td align="center"><span class="style5"><img src="img/viewdoc.png" onMouseOver="style.cursor=\'hand\'"  onclick="UploadDocuments(\''.'Transfer'.'\','.$rows[12].');"  title="Show Document" style="width: 18px; height: 15px; " ></span></td>';
	}else{
	echo'<td align="center">&nbsp;</td>';  
	}
	
	if ((in_array(strtoupper($WhTo), $transwh) or $TransferWH=='') and ($Module_TransferConfirmation==1) and $rows[14]==0 )
			 echo'<td width=10px align="center"><span class="style5"><img src="img/confirmorder.png" onMouseOver="style.cursor=\'hand\'" onclick="ConfirmTransfer('.$rows[12].','.$rows[0].',\''.$TransType.'\');" title="'.$ConfHint.'" style="width: 15px; height: 15px; "  ></span></td>';
	else 	 echo'<td align="center"></td>';
	
	 if ($viewproject == 1) {
		$fromprojname1 = $rows[3];
		$fromprojname2 = $rows[4];
	}
	else if ($viewproject == 2){
		$fromprojname1 = $rows[6];
		$fromprojname2 = $rows[7];
	}
	 
	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">'.$fromprojname1.'</span></td>
			<td align="left"><span class="style5">'.$fromprojname2.'</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>
			<td align="center"><span class="style5">'.$rows[17].'</span></td>
		</tr>';
		
		
	$sub_query = " Select TransferDt.TransferDt_ID, TransferDt.Item_CodePacked, TransferDt.Item_code, Item_Description, ".
				 " TransferDt.TransferDt_WarehouseFrom, TransferDt.TransferDt_WarehouseTo, Item_UnitSalesDesc, TransferDt_Quantity ".
				 " From TransferDt Left Join Items on TransferDt.Item_code = Items.Item_code ".
				 " Where TransferDt.Transfer_ID = ".$rows[12];
	//echo $sub_query;
	$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'.$rows[12];
			
		echo "<tr ".$Color.">";
		echo "<td colspan='16' valign='top' align='left'><div id='$SlideDivId' class='div-search-details slideAll' style='display:none; margin-left:80px;'>";
		echo "<table border='0' style='table-layout:fixed; width:780px;' cellpadding='0' cellspacing='1'>";
		echo "<tr><td width='140px'><span class='style4'>Item Code</span></td>
				  <td width='300px'><span class='style4'>Description</span></td> 
				  <td width='100px'><span class='style4'>From WH</span></td> 
				  <td width='100px'><span class='style4'>To WH</span></td> 
				  <td width='60px' align='center'><span class='style4'>Unit</span></td>
				  <td width='80px' align='center'><span class='style4'>Qty</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='left' valign='top' class='style9'>".$sub_rows[5]."</td>
					  <td align='center' valign='top' class='style9'>".$sub_rows[6]."</td>
					  <td align='right' valign='top' class='style9'>".$sub_rows[7]."</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:1025px;' 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;
}
?>