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

//echo $transfer_id;
session_start();
//$HTTP_SESSION_VARS['dbName'] = 'dajcom_acc2010';
//$HTTP_SESSION_VARS['dbLabel'] = 'accesslabelsdajcom';
//$HTTP_SESSION_VARS['useraccount']='01';
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");

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

 
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

$querylog="select * from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' 
			and Login_schema = '".$HTTP_SESSION_VARS['dbName']."'";
//echo $querylog;

//$actionmode='cancel';



$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
extract($rows);
}
/*
//echo $actionmode;
if ($HTTP_SESSION_VARS['driver_name']!='')
$driver_name = $HTTP_SESSION_VARS['driver_name'];
if ($HTTP_SESSION_VARS['vehicle_no']!='')
$vehicle_no = $HTTP_SESSION_VARS['vehicle_no'];
if ($HTTP_SESSION_VARS['transfer_remark']!='')
$transfer_remark = $HTTP_SESSION_VARS['transfer_remark'];

*/
;

if (($sref!='' and $startrange==0) or ($transferid!=''))
{
if ($edit=='yes' or $actionmode=='insert')
	{
		$dis = "";
		//mysql_query("START TRANSACTION");
	}	
else
{
	$dis = " disabled ";
	$dis1 = " readonly ";
	}
}	
/*
$query = "select user_account ,warehouse_code as avlwarehouse,warehouse_code as default_warehouse_code
							,project_code as avlprojectcode from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk
							where user_account='".$HTTP_SESSION_VARS['useraccount']."'";
							
$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
extract($rows);
}	
*/						
//							echo $query;


							
$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}

if ($deleteditemid!='')
	{
		$string = "delete from ".$HTTP_SESSION_VARS['tabletd']." where id = ".$deleteditemid;
		//echo $string;
		$result=mysql_query($string,$connection)		or die(mysql_error());
		$deleteditemid='';
	}

//echo $actionmode;
$HTTP_SESSION_VARS['tabletd']="usertd"."".$HTTP_SESSION_VARS['useraccount'];

//echo $HTTP_SESSION_VARS['dbLabel'];
//echo $dbLabel;
//exit;
$query = "select FI_Transfer from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account = '".$HTTP_SESSION_VARS['useraccount']."' " ;
$result=mysql_query($query,$connection) or die(mysql_error());
$rows=mysql_fetch_array($result);

$FI_Transfer = $rows[0];

if ($transferid!='' or $sref!='')
	{ 	
		$actionmode='view';
		$query = "select transfer_id as transfer_id, transfer_reference as ref,
		date_format(transfer_date,'%d-%m-%Y') as transfer_date,transfer_remark as transfer_remark,
					project_code1 as fromproject,project_code2 as toproject,costcenter_code as costcent
					,transfer_id as transfer_id1 ,
					ifnull(transfer_warehousefrom,(select transferdt_warehousefrom from transferdt where transfer_id = transfer_id1 and transferdt_warehousefrom is not null limit 1)) as fromwarehouse ,
					ifnull(transfer_warehouseto ,(select transferdt_warehouseto from transferdt where transfer_id = transfer_id1 and transferdt_warehouseto is not null limit 1)) as towarehouse ,
					driver_name as driver_name, vehicle_no as vehicle_no 
					,ifnull(warehouse.Warehouse_name,(select warehouse_name from warehouse where warehouse_code = fromwarehouse)) as  Warehouse_name,
					ifnull(warehouse1.Warehouse_name ,(select warehouse_name from warehouse where warehouse_code = towarehouse)) as Warehouse_name1 

					,project.project_name as project_name, project1.project_name as project_name1
					from transfer left join warehouse on transfer.transfer_warehousefrom = warehouse.warehouse_code
					left join warehouse as warehouse1 on transfer.transfer_warehouseto = warehouse1.warehouse_code
					left join project on transfer.project_code1 = project.project_code
					left join project as project1 on transfer.project_code2 = project1.project_code
					where transfer_id='".$transferid."' or transfer_reference='".$sref."'
					
					";
					//echo $query;
				$result=mysql_query($query,$connection) or die(mysql_error());
				

			while($rows=mysql_fetch_array($result)){
						extract($rows);
						}
						
						
			$fromprojectedit = $fromproject;
			$toprojectedit = $toproject;			
			$fromprojectnameedit = $project_name;			
			$toprojectnameedit = $project_name1;			
						
						
						
			$fromwarehouseedit = $fromwarehouse;
			$towarehouseedit = $towarehouse;			
			$fromwarehousenameedit = $Warehouse_name;			
			$towarehousenameedit = $Warehouse_name1;
	//echo "ASd".$fromwarehouse;
	}
	else
	if (($fromwarehouse=='') and  ($fromproject=='') and ($costcent=='') and ($actionmode=='insert'))
				{
				$query222a="select user_account ,warehouse_code as avlwarehouse,warehouse_code as default_warehouse_code
							from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk
							where user_account='".$HTTP_SESSION_VARS['useraccount']."'";
							$result222a=mysql_query($query222a,$connection) or die(mysql_error());
							if(mysql_num_rows($result222a)=="0"){

							$query222="select project.Project_Code as pcode,project.Project_Name as pname 
							from salessetup,project where project.project_code=salessetup.project";
							}else{
							$query222="select project_code as pcode,costcent_code as costcode,Default_project,default_costcenter as default_costcenter , 
							warehouse_code,warehouse_code,Default_warehouse
							from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk
							where user_account='".$HTTP_SESSION_VARS['useraccount']."'";
							
							
							}
							
							$result222=mysql_query($query222,$connection) or die(mysql_error());
							while($rows=mysql_fetch_array($result222)){
							extract($rows);
							}
							//echo "0 ".$fromproject."<br>";
							//$fromproject = $pcode;
							//echo "1 ".$fromproject;
							$costcent = $costcode;
				}
	//echo $actionmode;
	
if ($actionmode=='insert')
	{
	$transfer_date=date('d/m/Y');

	//$query="select transfer_reference+1 as transref ,transfer_id+1 as fetrid ,journal_id+1 as joutrid from sequence";
	$query="select null  as transref ,transfer_id+1 as fetrid  from sequence";
	$result3=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result3)){
		extract($rows);
											}
		if ($fetrid!='')
		if ($ref=='')
		{
			$ref=$transref;
			$transfer_id =  $fetrid;
			//$journal_id =  $joutrid;
		//$query="update sequence set transfer_reference = transfer_reference + 1";
		//$result3=mysql_query($query,$connection) or die(mysql_error());
		
		}
	}	

if ($actionmode=='')
	{
	$sql="SELECT * FROM ".$HTTP_SESSION_VARS['tabletd'];
	//echo $sql;
		$result=@mysql_query($sql,$connection);
		if ($result)
			{
				$query="drop table if exists `".$HTTP_SESSION_VARS['tabletd']."`";
				//echo $query;
				$result=mysql_query($query,$connection) or die(mysql_error());
			}	
	
	
	}

if ($actionmode=='cancel' )
	{
	unset($serialarray); 
	unset($HTTP_SESSION_VARS["serialarray"]);
	unset($serialarrayload); 
	unset($HTTP_SESSION_VARS["serialarrayload"]);
	unset($HTTP_SESSION_VARS["itemarray"]);
	unset($itemarray); 
	unset($HTTP_SESSION_VARS['error']);
	if (isset($HTTP_SESSION_VARS['tabletd']))
	$query="drop table if exists `".$HTTP_SESSION_VARS['tabletd']."`";

	$result=mysql_query($query,$connection) or die(mysql_error());
	if (isset($HTTP_SESSION_VARS['tablet']))
	$query="drop table if exists `".$HTTP_SESSION_VARS['table']."`";

	$result=mysql_query($query,$connection) or die(mysql_error());
		$process='';
	}

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">



function deleteitem(id){
if (confirm ( "Are you sure you want to Remove the item?"))
{
	document.transfer.deleteditemid.value = id;
	document.transfer.action='transfertrans.php';
	document.transfer.submit();
}
}

function deletetransferdt(transferdtid)
	{
	
	
	var sref = document.transfer.sref.value;
	var perpage = document.transfer.perpage.value;

	if (confirm ( "Are you sure you want to Delete the item?"))
	{
	document.transfer.action='d_transferdt.php?sref='+sref+'&perpage='+perpage+'&transferdt='+transferdtid;
	document.transfer.submit();	
	}
	}
function setnextpage(sref,startrange,perpage){

document.transfer.action='transfertrans.php?sref='+sref+'&startrange='+startrange+'&perpage='+perpage;
document.transfer.submit();

}

function setprvpage(sref,startrange,perpage){

document.transfer.action='transfertrans.php?sref='+sref+'&startrange='+startrange+'&perpage='+perpage;
document.transfer.submit();

}

function searchforref(){
var ref = document.transfer.sref.value;
var perpage = document.transfer.perpage.value;

//document.transfer.insert.disabled = true;
document.transfer.action='transfertrans.php?sref='+ref+'&startrange=0&perpage='+perpage;
document.transfer.submit();
}

function printpage(transferid)
{
	if (transferid=='')
		{
			alert('Please Choose a Transfer');
			return false;
		}
	else
		{
		  str1= 'printable_transfer.php?transfer_id='+transferid;
		  width = screen.width - 100;
		  height = screen.height - 250;
		  window.open(str1,"", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
		}
}

function printpage1(transferid)
{
	  str1= 'printable_transfer.php?transfer_id='+transferid;
	  width = screen.width - 100;
	  height = screen.height - 250;
	  window.open(str1,"", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");

}

function checkfields(fromwarehouse,towarehouse,fromproject,toproject,costcent){
if (fromwarehouse=='')
	{
		alert("WareHouse Column is mandatory!");
		document.transfer.fromwarehouse.focus();
		return 0;
	}
if (towarehouse=='')
	{
		alert("WareHouse Column is mandatory!");
		document.transfer.towarehouse.focus();
		return 0;
	}
if (fromproject=='')
	{
		alert("Project Column is mandatory!");
		document.transfer.fromproject.focus();
		return 0;
	}
if (toproject=='')
	{
		alert("Project Column is mandatory!");
		document.transfer.toproject.focus();
		return 0;
	}
/*if (costcent=='')
	{
		alert("CostCenter Column is mandatory!");
		document.transfer.costcent.focus();
		return 0;
	}*/
else
return 1 ;	
}

function addnewitem(obj,transferid){
var ref= document.transfer.ref.value;
var date= document.transfer.transfer_date.value;
var costcent= document.transfer.costcent.value;
var fromwarehouse= document.transfer.fromwarehouse.value;
var towarehouse= document.transfer.towarehouse.value;
var toproject = document.transfer.toproject.value;
var fromproject = document.transfer.fromproject.value;
//var journal = document.transfer.journal_id.value;
var transferid = document.transfer.transfer_id.value;
var driver_name = document.transfer.driver_name.value;
var vehicle_no = document.transfer.vehicle_no.value;

var x = checkfields(fromwarehouse,towarehouse,fromproject,toproject,costcent);
fromwarehouse = fromwarehouse.replace('&','%26');
towarehouse = towarehouse.replace('&','%26');

if (x==1)
if (obj.value=='Add Item')
	{
	obj.value='Post';
	document.transfer.actionmode.value='addnewitem';
	document.transfer.action="transfertrans.php?ref="+ref+"&date="+date+"&costcent="+costcent+"&fromwarehouse="+fromwarehouse+"&towarehouse="+towarehouse+"&actionmode=insert&fromproject="+fromproject+"&toproject="+toproject+"&transfer_id="+transferid+"&driver_name="+driver_name+"&vehicle_no="+vehicle_no;
	document.transfer.submit();
	}
else
	{
	obj.value='Add Item';
	document.transfer.actionmode.value='addnewitem';
//	document.transfer.action="i_newitem.php?&transferid="+transferid;
	document.transfer.action="i_newitem.php?ref="+ref+"&date="+date+"&costcent="+costcent+"&fromwarehouse="+fromwarehouse+"&towarehouse="+towarehouse+"&actionmode=insert&fromproject="+fromproject+"&toproject="+toproject+"&transfer_id="+transferid+"&driver_name="+driver_name+"&vehicle_no="+vehicle_no;
	document.transfer.submit();
	}
	
}

function openitempage(transferid,edit){
//alert(document.transfer.item_code[index].value);
//var transferid = document.transfer.transfer_id.value;
//var x = 'item_code['+index+']';
//var name = document.getElementById(x); 
//alert(name.value);
var costcent= document.transfer.costcent.value;
var fromwarehouse= document.transfer.fromwarehouse.value;
var towarehouse= document.transfer.towarehouse.value;
var toproject = document.transfer.toproject.value;
var fromproject = document.transfer.fromproject.value;
var x = checkfields(fromwarehouse,towarehouse,fromproject,toproject,costcent);
fromwarehouse = fromwarehouse.replace('&','%26');
towarehouse = towarehouse.replace('&','%26');

	//str1= 'transfer_items.php?item=1&index='+index+'&transferid='+transferid;
	if (x==1)
	{
	  str1= 'transfer_items.php?item=1&transferid='+transferid+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&edit='+edit;
	  width = screen.width - 100;
	  height = screen.height - 250;
	  window.open(str1,"", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
	}
}



function loadtransfers(transferid){
var ref= document.transfer.ref.value;
var date= document.transfer.transfer_date.value;
var costcent= document.transfer.costcent.value;
var fromwarehouse= document.transfer.fromwarehouse.value;
var towarehouse= document.transfer.towarehouse.value;
var toproject = document.transfer.toproject.value;
var fromproject = document.transfer.fromproject.value;
//var journal = document.transfer.journal_id.value;
var driver_name = document.transfer.driver_name.value;
var vehicle_no = document.transfer.vehicle_no.value;

var x = checkfields(fromwarehouse,towarehouse,fromproject,toproject,costcent);
fromwarehouse = fromwarehouse.replace('&','%26');
towarehouse = towarehouse.replace('&','%26');
if (x==1)
{
document.transfer.action="loaditems.php?ref="+ref+"&date="+date+"&costcent="+costcent+"&fromwarehouse="+fromwarehouse+"&towarehouse="+towarehouse+"&actionmode=insert&fromproject="+fromproject+"&toproject="+toproject+"&transfer_id="+transferid+"&driver_name="+driver_name+"&vehicle_no="+vehicle_no;
document.transfer.submit();
}
}

function posttransfers(act,edit){




var fromwarehouse= document.transfer.fromwarehouse.value;
var towarehouse= document.transfer.towarehouse.value;
var toproject = document.transfer.toproject.value;
var fromproject = document.transfer.fromproject.value;




var x = checkfields(fromwarehouse,towarehouse,fromproject,toproject,'');

if (x==1)
{


		if (act=='a')
			{
			if (edit=='yes')
				{
				document.transfer.action="edittransfers.php";
				document.transfer.submit();
				}
			else
				{
				document.transfer.action="posttransfers.php";
				document.transfer.submit();
				}
			}
		else
		if (act=='e')
			{
			document.transfer.action="transfertrans.php?edit=yes";
			document.transfer.submit();
			}	
}			
}

function insert(){
clearform();
document.transfer.actionmode.value='insert';
document.transfer.action='transfertrans.php';
document.transfer.submit();
}

function addsntotransfer(){
document.transfer.action='transfertrans.php';
document.transfer.submit();
}

function opensnpage(edit)
{
var ref= document.transfer.ref.value;
var date= document.transfer.transfer_date.value;
var costcent= document.transfer.costcent.value;
var fromwarehouse= document.transfer.fromwarehouse.value;
var towarehouse= document.transfer.towarehouse.value;
var toproject = document.transfer.toproject.value;
var fromproject = document.transfer.fromproject.value;
//var journal = document.transfer.journal_id.value;
var x = checkfields(fromwarehouse,towarehouse,fromproject,toproject,costcent);

fromwarehouse = fromwarehouse.replace('&','%26');
towarehouse = towarehouse.replace('&','%26');

if (x==1)
	{
	  str1= 'itemSerialNumberPopup.php?fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&edit='+edit;
	  width = screen.width - 550;
	  height = screen.height - 250;
	  window.open(str1,"", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
	}
}
function showsnperitem(itemcode,edit)
{
var fromwarehouse= document.transfer.fromwarehouse.value;
var towarehouse= document.transfer.towarehouse.value;

fromwarehouse = fromwarehouse.replace('&','%26');
towarehouse = towarehouse.replace('&','%26');

 str1= 'itemSerialNumberPopup.php?fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'type=peritem&itemcode='+itemcode+'&edit='+edit;
  width = screen.width - 550;
  height = screen.height - 250;
  window.open(str1,"", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");

}
function showsnperitemLoad(itemcode,transferdt,edit)
{
var fromwarehouse= document.transfer.fromwarehouse.value;

fromwarehouse = fromwarehouse.replace('&','%26');


  str1= 'itemSerialNumberPopup.php?type=peritem&itemcode='+itemcode+'&transferdtid='+transferdt+'&edit='+edit+'&fromwarehouse='+fromwarehouse;
  width = screen.width - 550;
  height = screen.height - 250;
  window.open(str1,"", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");

}
function clearform(){
document.transfer.actionmode.value='cancel';
document.transfer.ref.value='';
document.transfer.transfer_date.value='';
document.transfer.transfer_id.value='';
document.transfer.costcent.value='';
document.transfer.toproject.value='';
document.transfer.fromproject.value='';
document.transfer.fromwarehouse.value='';
document.transfer.towarehouse.value='';
document.transfer.transfer_remark.value='';
document.transfer.vehicle_no.value='';
document.transfer.driver_name.value='';
document.transfer.sref.value='';
document.transfer.ref.value='';
document.transfer.action='transfertrans.php';
document.transfer.submit();

}





function remove(){
document.form1.addmode.value="delete";
submitok="true"
x=document.form1;
code=x.code.value;

if(code==""){
alert("You have not specified an item code for the records to be deleted. Click on the Item Code link to select an item code number.");
submitok="false"
}else if(confirm('Are you sure you want to Delete this item records?')){
document.form1.action='item_execute.php';
document.form1.del.submit();
}
if(submitok=="false"){
		return false;
	}
}


function clearer(){
x=document.form1;
document.form1.action='item_form.php';
document.form1.inserted.submit();
}


function posting(){
x = document.form1;
submitok="true"
addmode=x.addmode.value;
code=x.code.value;
minqty=x.minqty.value;
maxqty=x.maxqty.value;
price=x.price.value;
group=x.group.value;
subgroup=x.subgroup.value;
description=x.description.value;
lastpurchdate=x.lastpurchdate.value;
if(addmode==""){
alert("You have not specified an operation mode");
submitok="false";
}else if(code==""){
alert("Item Code is required!");
submitok="false";
x.code.focus();
}else if(minqty==""){
alert("Item Minimum Quantity is required!");
submitok="false";
x.minqty.focus();
}else if(maxqty==""){
alert("Item Maximum Quantity is required!");
submitok="false";
x.maxqty.focus();
}else if(price==""){
alert("Item Price is required!");
submitok="false";
x.price.focus();
}else if(group==""){
alert("Item Group is required!");
submitok="false";
x.group.focus();
}else if(subgroup==""){
alert("Item Subgroup is required!");
submitok="false";
x.subgroup.focus();
}else if(description==""){
alert("Item Description is required!");
submitok="false";
x.description.focus();
}else if(lastpurchdate==""){
alert("Item Last Purchase Date is required!");
submitok="false";
x.lastpurchdate.focus();
}

if(submitok=="false"){
return false; 
}else{
document.form1.action="item_execute.php";
document.form1.posted.submit();
}
}







</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Transfer</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<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;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.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>
</head>
<body>
<form name='transfer' method='post'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='transfer_id' value='$transfer_id'>
<input type='hidden' name='deleteditemid' value='$deleteditemid'>
HERE;

//setup tables
$query="SELECT costcent_code,costcent_name FROM costcent order by costcent_code";
$costcenterresult=mysql_query($query,$connection) or die(mysql_error());

//$query="select currency_code,currency_name from currency order by currency_code";
//$currencyresult=mysql_query($query,$connection) or die(mysql_error());


// default project
$query="select project_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk 
where default_project = 1 
and user_account='".$HTTP_SESSION_VARS['useraccount']."'";
//echo $query;
$defaultproject=mysql_query($query,$connection) or die(mysql_error());
$rows = mysql_fetch_row($defaultproject);
				
							$defaultprojectcode = $rows[0];
							
							if ($fromproject=='')
							$fromproject = $defaultprojectcode;

$sqlproject = "select project_code,project_name
									from project
									where project_code in 
			(select project_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')
									";
							$resultdefaultproject=mysql_query($sqlproject,$connection) or die(mysql_error());
						//	echo $sqlproject;
$sqlproject1 = "select project_code,project_name
									from project
									where project_code in 
			(select project_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')
									";
			
		if(mysql_num_rows($resultdefaultproject)=="0")
			{
				$sqlproject = "select project_code,project_name
									from project
									";							
				$sqlproject1 = "select project_code,project_name
									from project
									";	
			}									
			else
			if (($edit=='yes' or sref!='') and $fromprojectedit!='')
			{
				$sqlproject = "select '".$fromprojectedit."' , '".$fromprojectnameedit."' from dual union " . $sqlproject;
				$sqlproject1 = "select '".$toprojectedit."' , '".$toprojectnameedit."' from dual union " . $sqlproject1;
			
			}
			//echo $sqlproject;
			$sqlproject = $sqlproject . " order by project_code ";
			$sqlproject1 = $sqlproject1 . " order by project_code ";
$projectresultfrom=mysql_query($sqlproject,$connection) or die(mysql_error());
$projectresultto=mysql_query($sqlproject1,$connection) or die(mysql_error());

$query="select warehouse_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where default_warehouse = 1 
and user_account='".$HTTP_SESSION_VARS['useraccount']."'";
//echo $query;
							$defaultwarehouse=mysql_query($query,$connection) or die(mysql_error());
							$rows = mysql_fetch_row($defaultwarehouse);
							$defaultwarehousecode = $rows[0];
							
							//echo $actionmode;
							if ($fromwarehouse=='' and $actionmode!='view')
							$fromwarehouse = $defaultwarehousecode;
			

			$sql = "select warehouse_code,warehouse_name
									from warehouse
									where warehouse_code in (select warehouse_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')
									";
							$resultdefaultwarehouse=mysql_query($sql,$connection) or die(mysql_error());
							//echo $sql;
							
			$sql1 = "select warehouse_code,warehouse_name
									from warehouse
									where warehouse_code in (select warehouse_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')
									";
							$resultdefaultwarehouse=mysql_query($sql,$connection) or die(mysql_error());
							
			if(mysql_num_rows($resultdefaultwarehouse)=="0")
			{
				$sql = "select warehouse_code,warehouse_name
									from warehouse";
				$sql1 = "select warehouse_code,warehouse_name
									from warehouse";
															
			}	
			else
			if (($edit=='yes' or sref!='') and $fromwarehouseedit!='')
			{
				$sql = "select '".$fromwarehouseedit."' , '".$fromwarehousenameedit."' from dual union " . $sql;
				$sql1 = "select '".$towarehouseedit."' , '".$towarehousenameedit."' from dual union " . $sql1;
			
			}
			//$resultdefaultwarehouse=mysql_query($sql,$connection) or die(mysql_error());
				//$fromwarehouseedit		
			//echo $sql."<br>";
			//echo $sql1;
			//exit;
			$sql = $sql . " order by warehouse_code ";
			$sql1 = $sql1 . " order by warehouse_code ";
$warehouseresultfrom=mysql_query($sql,$connection) or die(mysql_error());
$warehouseresultto=mysql_query($sql1,$connection) or die(mysql_error());

echo"<table border=0 width='100%'>";
echo '<tr><td colspan="9" align="left" valign="top">';

include_once("MenuBar.php");

print <<< HERE
       </td>
      </tr>
HERE;
print <<<HERE
		<tr><td height="30" colspan="16" valign="bottom"><span class="style16"> &nbsp;TRANSFER</span></tr>
		<tr><td>
		<table width="100%" border="0" bordercolor="#F7F7F7">
		 <tr bgcolor="#F7F7F7" height='30'>
          <td width="9%" valign="center" align='left' bgcolor="#F7F7F7"><span class="style11">Reference&nbsp;<span class="style26">*</span></span></td>
		  <td><input type="text" name="ref" value="$ref" readonly><input type="hidden" name="journal_id" value="$journal_id" ></td>
		  <td></td><td><span class='style11'>Project&nbsp;</span><span class="style26">*</span></td><td> <span class='style11'>Warehouse&nbsp;</span><span class="style26">*</span></td>
		  </tr>
		  <tr  height='30' bgcolor="#F7F7F7"><td width="8%" align="left"><span class="style11">Date&nbsp;<span class="style26">*</span></span></td>
		  <td><input type='text' size='10' name='transfer_date' readonly value='$transfer_date' maxlength=10></td>
HERE;
		 echo" <td><span class='style11'>From</span></td><td><span class='style11'><select name='fromproject' id='fromproject' $dis>";
		echo"<option></option>";
		while($prj=mysql_fetch_row($projectresultfrom)){
		echo"<option ";
			if ($fromproject==$prj[0])
				echo " selected ";
		echo" value='$prj[0]'>$prj[0] / $prj[1]</option>";
		}
		echo"</select>";
		echo"</span></td><td>
		<span class='style11'><select name='fromwarehouse' id='fromwarehouse' $dis>";
		echo"<option></option>";
		/*
		if ($fromwarehouseedit!='')
		echo"<option value='".$fromwarehouseedit."' selected>";
						
		echo $fromwarehouseedit." / ".$fromwarehousenameedit."</option>";
		*/
		while($wrhf=mysql_fetch_row($warehouseresultfrom)){
		
		
		echo"<option ";
			if ($fromwarehouse!='')
				{if ($fromwarehouse==$wrhf[0])
					echo " selected ";}
			else
				if ($Default_warehouse_code==$wrhf[0])
					echo " selected ";	
		echo" value='$wrhf[0]'>$wrhf[0] / $wrhf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";
		  
		  
		  echo'</tr>
		  <tr  height="30" bgcolor="#F7F7F7"><td width="8%" align="left" ><span class="style11">CostCenter&nbsp;</span></td>  
';
		  echo'<td height="20" align="left" valign="center" bgcolor="#F7F7F7"><select name="costcent" id="costcent" '.$dis.' >
              <option value=""></option>';
         while($costct=mysql_fetch_row($costcenterresult)){
				echo"<option ";
				if ($costcent==$costct[0])
					echo " selected ";
				echo" value='$costct[0]'>$costct[0] / $costct[1]</option>";						
				}
		     echo'</select></td>
					';
		 
		 
		echo"<td><span class='style11'>To</span></td><td>
		<span class='style11'><select name='toproject' id='toproject' ".$dis.">";
		echo"<option></option>";
		while($prj=mysql_fetch_row($projectresultto)){
		echo"<option ";
			if ($toproject==$prj[0])
				echo" selected ";
		echo" value='$prj[0]'>$prj[0] / $prj[1]</option>";
		}
		echo"</select>";
				
		echo"</span></td><td> <span class='style11'><select name='towarehouse' id='towarehouse' ".$dis.">";
		echo"<option></option>";
		while($wrht=mysql_fetch_row($warehouseresultto)){
		echo"<option ";
			if ($towarehouse==$wrht[0])
				echo" selected ";
		echo" value='$wrht[0]'>$wrht[0] / $wrht[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";
		echo'</tr>';
		
		$totalscanned = count($serialarray); 
		//$lastitemscanning	= getlastscanning();
		$lastitemscanning = $serialarray[$totalscanned-1][1];
		
		echo"<tr bgcolor='#F7F7F7'><td><span class='style11'>Driver Name</td><td>
		<input type='text' name='driver_name'  value='$driver_name' $dis></td>
		<td><span class='style11'>Sum of Total Scan:</td><td><input type='text' name='totalscanned' readonly value='$totalscanned' size='7'></td><td></td></tr>";
		echo"<tr bgcolor='#F7F7F7'><td><span class='style11'>Vehicle No</td><td><input type='text' name='vehicle_no' value='$vehicle_no' $dis></td>
		<td class='style11'>Last Item Scanning</td>
		<td><input type='text' name='lastitemscanning' value='$lastitemscanning' $dis></td>
		<td></td></tr>";
			
		echo"<tr bgcolor='#F7F7F7'  height='30'>
		<td  align='left' ><span class='style11'>Remark</span></td><td colspan='4' > <span class='style11'>
		<input type='text' name='transfer_remark'   size='130' value='".htmlspecialchars($transfer_remark, ENT_QUOTES)."' $dis></td></tr>";
		//echo"<tr bgcolor='#F7F7F7'><td colspan=4>&nbsp;</td></tr>";
		//echo"<tr bgcolor='#F7F7F7'><td></td><td> <span class='style11'></td></tr>";
		echo'</table></td></tr><tr><td><font color=red>';
		//echo $HTTP_SESSION_VARS['error'];
		echo'</font></td></tr>';//end of first table transfer
		echo"<tr><td><table border=0 width='100%' >";// table transferdt
		

		
		echo'
		    <tr bgcolor="#F7F7F7">
	  <td>&nbsp;</td>
	  <td width="3%">&nbsp;</td>
      <td width="8%" bgcolor="#F7F7F7"><span class="style27">Code</span></td>
      <td width="28%" bgcolor="#F7F7F7"><span class="style27">Description</span></td>
      <td width="5%" bgcolor="#F7F7F7"><span class="style27">Qty</span></td>
   
      <td  width="5%" bgcolor="#F7F7F7"><span class="style27">Price</span></td>
	     <td  width="8%" bgcolor="#F7F7F7"><span class="style27">From Warehouse</span></td>
      <td  width="8%" bgcolor="#F7F7F7"><span class="style27">To Warehouse</span></td>
      <td width="50%" bgcolor="#F7F7F7"><span class="style27">Remark</span></td>
    </tr>';

    $itemarray = $HTTP_SESSION_VARS["itemarray"];
	$count1 = count($itemarray); 
	
$countload=0;
//unset($HTTP_SESSION_VARS["itemarray"]);
//unset($HTTP_SESSION_VARS["serialarray"]);
//echo $actionmode;

//if ($actionmode=='addnewitem')
	
		$sql="SELECT * FROM ".$HTTP_SESSION_VARS['tabletd'];
		$result=@mysql_query($sql,$connection);
		if ($result)
		/////////////////////////  adding new item with no serial no
		{
		//echo"ads";
		$query = "select item_code,item_description,transferdt_quantity,TransferDt_Price,TransferDt_WarehouseFrom,TransferDt_WarehouseTo
			,transferdt_id , count(serialno_code),relateddt_id,transferdt_remark , id
			from ".$HTTP_SESSION_VARS['tabletd']." where serialno_code <> ''
			group by transferdt_id,item_code";
			
		//echo $query;
		$transdtresult=mysql_query($query,$connection) or die(mysql_error());
		
		$t=0;
		//////////////      temporary with serial no
		///maroun 
		/*
		while($rows=mysql_fetch_array($transdtresult))
			{
			
			$t=$t+1;
			$item_code = $rows[0];
			$item_description = $rows[1];
			$item_quantity = $rows[7];
			$item_sellingprice1 = $rows[3];
			$warehousefrom=$rows[4];
			$warehouseto=$rows[5];
			$transferdt_remark = $rows[9];
			$transferdtid=$rows[6];
			$relateddt_id=$rows[8];
			echo"<tr>
		    <td ><img src='images/c_delete.png'   onclick=deleteitem('".$rows[10]."') ".$dis." ></td>
			  <td align='center'><input type='button' name='button' value='SN'   ".$dis." onclick=showsnperitem('".$item_code."','".$edit."')></td>
						<td ><input type='hidden' name='transferdtid[]' value='".$transferdtid."'   hidden size=15>
			<input type='text' name='item_code[]' value='".$item_code."' size=15 ".$dis."></td>
			<td ><input type='text' name='item_description[]'  value='".$item_description."'  ".$dis." size=55></td>
			<td ><input type='text' name='item_quantity[]' value='".$item_quantity."'   readonly size=4></td>
		    <td ><input type='text' readonly name='item_sellingprice1[]' value='".$item_sellingprice1."'    size=10></td>
			<td ><input type='text' readonly name='warehousefrom1[]' value='".$warehousefrom."'   ".$dis." size=15></td>
		    <td ><input type='text' readonly name='warehouseto1[]' value='".$warehouseto."'   ".$dis." size=15></td>
			<td ><input type='text' name='transferdt_remark[]' value='".$transferdt_remark."'   ".$dis." size='60'>
			<input type='hidden' name='relateddt_id[]' value='".$relateddt_id."'>
			</td></tr>";	
			$countload = $countload + 1;
			}
			*/
			$query = "select item_code,item_description,transferdt_quantity,TransferDt_Price,TransferDt_WarehouseFrom,TransferDt_WarehouseTo
			,transferdt_id , transferdt_quantity,relateddt_id,transferdt_remark,id
			from ".$HTTP_SESSION_VARS['tabletd']." where serialno_code = ''
			";
			
		//echo $query;
		$transdtresult=mysql_query($query,$connection) or die(mysql_error());
		
		$t=0;
		//////////////      temporary without serial no
		while($rows=mysql_fetch_array($transdtresult))
			{
			$t=$t+1;
			$item_code = $rows[0];
			$item_description = $rows[1];
			$item_quantity = $rows[7];
			$item_sellingprice1 = $rows[3];
			$warehousefrom=$rows[4];
			$warehouseto=$rows[5];
			$transferdt_remark = $rows[9];
			$transferdtid=$rows[6];
			$relateddt_id=$rows[8];
			echo"<tr>
		    <td ><img src='images/c_delete.png'   ".$dis."  onclick=deleteitem('".$rows[10]."')></td>
			<td  align='center'></td>
			<td ><input type='hidden' name='transferdtid[]' value='".$transferdtid."'    size=15>
			<input type='text' name='item_code[]' value='".$item_code."'   ".$dis." size=15></td>
			<td ><input type='text' name='item_description[]' size='55'   ".$dis." value='".$item_description."' ></td>
			<td ><input type='text' name='item_quantity[]' value='".$item_quantity."'  readonly ".$dis." size=4></td>
		    <td ><input type='text' readonly name='item_sellingprice1[]'    value='".$item_sellingprice1."' size=10></td>
		    <td ><input type='text' readonly name='warehousefrom1[]'   ".$dis." value='".$warehousefrom."' size=15></td>
		    <td ><input type='text' readonly name='warehouseto1[]'   ".$dis." value='".$warehouseto."' size=15></td>
			<td ><input type='text' name='transferdt_remark[]'   ".$dis." value='$transferdt_remark' size='60'>
			<input type='text' name='relateddt_id[]'   ".$dis." value='".$relateddt_id."'>
			</td></tr>";	
			$countload = $countload + 1;
			}
		

		
		}


if ($actionmode=='insert')
if($count1!=0){ 
	$process='array';

	for ($i=0;$i<$count1;$i++)	{ 
			
		$item_code = $itemarray[$i][0];
		$item_quantity=$itemarray[$i][1];	
		
		$query="select item_description ,item_sellingprice1 from items where item_code = '".$item_code."'";
		//echo $query;
		$result=mysql_query($query,$connection) or die(mysql_error());;
		$rows=mysql_fetch_array($result);
		$item_description = $rows[0];
		$item_sellingprice1 = $rows[1];
		$relateddt_id='';
		$transferdt_remark='';
		if ($item_quantity!='0')
		{
		echo"<tr>
		  <td></td>
		  <td align='center'><input type='button' name='button' value='SN'   ".$dis." onclick=showsnperitem('".$item_code."','".$edit."')></td>
		  <td>
		  <input type='hidden' name='transferdtid[]' value='".$transferdtid."'   size=15>
		  <input type='text' name='item_code[]' size='15' value='".$item_code."'></td>
		  <td><input type='text' name='item_description[]' size='55'   ".$dis." value='".$item_description."'></td>
		  <td><input type='text' name='item_quantity[]'   ".$dis." ";
		  							
								echo " readonly ";
		  echo " value='".$item_quantity."' size=4></td>
		<td><input type='text' name='item_sellingprice1[]'  readonly value='".$item_sellingprice1."' size=10></td>
		<td><input type='text' name='fromwarehouse1[]'    ".$dis." value='".$fromwarehouse."' size='15'>
		<td><input type='text' name='towarehouse1[]'    ".$dis." value='".$towarehouse."' size='15'>
		<td><input type='text' name='transferdt_remark'    ".$dis." value='$transferdt_remark' size='60'>
		<input type='text' name='relateddt_id[]'   ".$dis." value='".$relateddt_id."'>
		</td></tr>";	
		}
		$totalscanned = $totalscanned + $item_quantity;
	}
	$countload=$count1 + $countload;
	}
	
	
	
	echo"<input type='hidden' name='count1' value='$count1'>";
	/*
	else
	{   
		$process='load';
		$query="create table if not exists ".$HTTP_SESSION_VARS['tabletd']."(
				id int(10) NOT NULL auto_increment ,transfer_id int(20),
				transferdt_id int(20),
				item_code varchar(20),
				item_description varchar(60),
				transferdt_quantity double,
				TransferDt_Price double,
				relateddt_id bigint,
				TransferDt_WarehouseFrom varchar(15),
				TransferDt_WarehouseTo varchar(15) ,
				serialno_code varchar(40),
				PRIMARY KEY(id))";
				$result=mysql_query($query,$connection)
				or die(mysql_error());
			$query = "select item_code,item_description,transferdt_quantity,TransferDt_Price,TransferDt_WarehouseFrom,TransferDt_WarehouseTo
			,transferdt_id , count(serialno_code),relateddt_id
			from ".$HTTP_SESSION_VARS['tabletd']."
			group by transferdt_id,item_code";
			
		//echo $query;
		$transdtresult=mysql_query($query,$connection) or die(mysql_error());;
		$t=0;
		
		while($rows=mysql_fetch_array($transdtresult))
			{
			$t=$t+1;
			$item_code = $rows[0];
			$item_description = $rows[1];
			$item_quantity = $rows[7];
			$item_sellingprice1 = $rows[3];
			$warehousefrom=$rows[4];
			$warehouseto=$rows[5];
			$transferdt_remark = '';
			$transferdtid=$rows[6];
			$relateddt_id=$rows[8];
			echo"<tr>
		    <td ><img src='images/c_delete.png'></td>
			<td  align='center'><input type='button' name='button' value='SN' onclick=showsnperitemLoad('".$item_code."','".$transferdtid."')></td>
			<td ><input type='text' name='item_code[]' value='".$item_code."' size=15></td>
			<td ><input type='text' name='item_description[]' value='".$item_description."' size=55></td>
			<td ><input type='text' name='item_quantity[]' value='".$item_quantity."' size=4></td>
		    <td ><input type='text' readonly name='item_sellingprice1[]' value='".$item_sellingprice1."' size=4></td>
			<td ><input type='text' name='transferdt_remark[]' value='$transferdt_remark' size='90'>
			<input type='hidden' name='relateddt_id[]' value='".$relateddt_id."'>
			</td></tr>";	
			}
			$countload = $t;
			
	}
	*/
	
	
	$tt=$countload-1;
if ($actionmode=='addnewitem')
{	/*	
		$item_code = '';
			$item_description = '';
			$item_quantity = '';
			$item_sellingprice1 = '';
			$warehousefrom='';
			$warehouseto='';
			$transferdt_remark = '';
			$transferdtid='';
		$count1=$tt+1;
		  echo"<tr>
		  <td><img src='images/c_delete.png'></td><td align='center'><input type='button' name='button' value='ITM' onclick='openitempage($count1)'></td>
		  <td><input type='text' id = 'item_code[]' name='item_code[]' value='".$item_code."' onclick='test(this.name)';></td>
		  <td><input type='text' id ='item_description[]' name='item_description' size=55 value='".$item_description."'></td>
		  <td><input type='text'  name='item_quantity[]' value='".$item_quantity."' size=4></td>
		<td><input type='text' id='item_sellingprice1[]' name='item_sellingprice1' size=4 value='".$item_sellingprice1."'></td>
		<td><input type='text' name='transferdt_remark' value='$transferdt_remark' size='40'></td></tr>";	
		$newitemcount = $newitemcount + 1;
		*/
		}	
	
if ($actionmode=='view' or $ref!='')	
	{
		if (isset($transferid) or $sref!='')
			{
			$query = "select transferdt.transferdt_id as transferdt_id, transferdt.item_code as item_code,items.item_description as item_description,
					transferdt_quantity as item_quantity,
					transferdt_price as item_sellingprice1,
					transferdt_remark as transferdt_remark ,purchasesserialno.serialno_code as serialnocode from 
					items ,transferdt left join purchasesserialno
					on purchasesserialno.transferdt_id=transferdt.transferdt_id
					where items.item_code=transferdt.item_code and (transfer_id='".$transferid."' or transfer_id ='".$transfer_id."')
					group by transferdt_id
					";
			//echo $query;
					
				$result=mysql_query($query,$connection) or die(mysql_error());
				$countload = mysql_num_rows($result);
				
				while($rows=mysql_fetch_array($result)){
				
						$transferdtid=$rows[0];
						extract($rows);
						
						if ($item_quantity > 0)
						{
						echo"<tr>
						<td align='center'>";
						if ($serialnocode=='')
						echo"<img src='images/c_delete.png' onclick=deletetransferdt('".$transferdtid."') ".$dis." >";
						else
						echo"&nbsp";
						echo"
						
						</td><td>";
						if ($serialnocode!='')
						//echo"<input type='button' name='button' value='SN' onclick=showsnperitemLoad('".$item_code."','".$transferdtid."')>";
						echo"<input type='button' name='button' value='SN' ".$dis." onclick=showsnperitemLoad('".$item_code."','".$transferdt_id."','".$edit."')>";
										
						echo"</td>
						<td>
						<input type='hidden' name='transferdtid[]' value='".$transferdtid."'    size=15>
						<input type='text' name='item_code[]'   ".$dis." value='".$item_code."' size=15></td>
						<td><input type='text' name='item_description[]'   ".$dis." value='".$item_description."' size=55></td>
						<td><input type='text' name='item_quantity[]'   ".$dis1." value='".$item_quantity."' ";
							if ($serialnocode!='')
								echo " readonly ";
							echo " size=5></td>
						<td><input type='text' readonly name='item_sellingprice1[]'    value='".$item_sellingprice1."' size=10></td>
						<td><input type='text' readonly name='fromwarehouse1[]'   ".$dis." value='".$fromwarehouse."' size=12></td>
						<td><input type='text' readonly name='towarehouse1[]'   ".$dis." value='".$towarehouse."' size=12></td>
						
						<td><input type='text' name='transferdt_remark[]'   ".$dis." value='$transferdt_remark' size='60'></td></tr>";	
							} // end of >0
						}
			}
	}
	echo"<input type='hidden' name='countload' value='$countload'>";
			echo"<input type='hidden' name='process' value='$process'>";
	echo"</td></tr></table>";
	echo"<tr><td>&nbsp;</td></tr>";
	$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";
	echo"<tr><td  align='left'><table  border=0 bgcolor=#D8D8D8 width='800'><tr >";
	echo $FI_Transfer;
	
	if ($FI_Transfer==1)
	{
	
				echo"<td  width='100' align='center'><input type='button' id='addnewitembut' name='button'  ";
						if ($actionmode=="addnewitem") ///add new item
							echo "value='Post New Item'";
						else
							echo "value='Add Item'";
							
						if ($actionmode=='cancel' or $actionmode=='' or $sref!='' or $transferid!='')
						echo " disabled ";
						
					//onclick='openitempage($transfer_id)'
							echo" onclick=openitempage('".$transfer_id."','".$edit."') $style>
				</td>";
				
				
				
				echo"<td  width='40' align='center'><input type='button' id='add' name='button' ";//add sn 
					if ($actionmode=='cancel' or $actionmode=='' or $actionmode=='addnewitem'  or $sref!=''  or $transferid!='')
						echo " disabled ";
				echo " value='Add Serial No' onclick=opensnpage('".$edit."') $style></td>";
				
	
				echo"<td  width='40' align='center'><input name='load' ";	//load
					if ($actionmode=='cancel' or $actionmode==''  or $actionmode=='addnewitem'  or $sref!=''  or $transferid!='')
						echo " disabled ";
				echo" type='button' onclick='loadtransfers($transfer_id)' id='load' value='Load' $style	title='Load Transfers' /></td>";
				
	}
				//echo "fi ".$FI_ITransferApp;
				
				echo"<td  width='40' align='center'><input type='button' id='insertbut' name='but1' ";//insert
				if (($actionmode=='insert'  or $actionmode=='addnewitem' or $actionmode=='view' or $FI_ITransferApp==0) and  ($transferid==''))
						echo " disabled ";

				echo " value='Insert'   onclick='insert()' $style></tD>";
				
				echo"<td  width='40' align='center'><input type='button' id='editbut' name='but2' ";//edit
				if ($actionmode=='insert'  or $actionmode=='addnewitem' or ($ref=='') or ($edit=='yes') or ($FI_ITransferMod==0) or $transferid!='')
						echo " disabled ";
				echo " value='Edit' onclick=posttransfers('e','".$edit."') $style></tD>";
				
				echo"<td  width='40' align='center'><input type='button' name='but3' id='cancel' value='Cancel' ";//cancel
					if ($actionmode=='cancel' or $actionmode=='' )
						echo " disabled ";
				echo" onclick='clearform()' $style></tD>";
				//echo $actionmode." ".$edit;
				echo"<td  width='40' align='center'><input name='load' type='button' ";//post
					
					if (($actionmode=='cancel') or
					(($actionmode=='cancel' or $actionmode=='' or ($ref!='')) and ($edit!='yes' and $actionmode=='view')) )
						echo " disabled ";
				echo" onclick=posttransfers('a','".$edit."') id='post' value='Post' $style	title='Post Transfers' /></td>";
				echo'<td><input name="print" type="button" id="print" value="print" style="font-weight:bold; color:#FFFFFF; font-size:13px; font-family:Arial, Helvetica, sans-serif; border:#FFFFFF; background-color: #4069A7;" title="print this page" ';
				if ($FI_Transfer==1)
				echo ' onclick=printpage("'.$transfer_id.'")  ';
				else
				echo ' onclick=printpage1("'.$transfer_id.'")  ';
				
				if ($actionmode=='insert' or $actionmode=='cancel' or $actionmode=='')
					echo" disabled ";
				echo '/></td>';
				
			echo'<td width="151" align="right"><span class="style12">Ref</span>
            <input name="sref" type="text" id="sref" size="5" value="'.$sref.'">';
				print <<<HERE
			<input name="displayed" type="button" id="displayed" value="search" onclick="searchforref()" style=" background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;" title="Search by reference number" /></td>
			</td>
          <td width="203" align="left"><span class="style25">Result per page
            <select name="perpage" id="perpage" value='$perpage'>
              
HERE;

              if ($perpage==20)
				$s20 = 'selected';
				else
              if ($perpage==30)
				$s30 = 'selected';
				else
              if ($perpage==40)
				$s40 = 'selected';
				else
              if ($perpage==50)
				$s50 = 'selected';

			
				
             echo'<option '.$s20.' value="20">20</option>
              <option '.$s30.' value="30">30</option>
              <option '.$s40.' value="40">40</option>
              <option '.$s50.' value="50">50</option>
            </select>
          </span></td>';
	echo"</tr>";
	echo"</table>";
	
	echo'</table></td></tr>  ';//end of last table menu
	
	echo"</td></tr><tr><td>";
	
	if ($sref!='' or $startrange!='')
	{
		echo"<table width='990'>";
		echo'<tr bgcolor="#CCD8E6">';
		echo'
		<td  height="25"><span class="style25">Reference </span></td>
		<td  height="25"><span class="style25">Date </span></td>
		<td  height="25"><span class="style25">Remark</span></td>
		<td height="25"><span class="style25">From Project</span></td>
		<td  height="25"><span class="style25">To Project</span></td>
		<td height="25" colspan="4"><span class="style25">CostCenter </span><span class="style25">&nbsp;</span></td>
		</tr>';
		
$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}

	

	
	$query="select transfer_reference,date_format(transfer_date,'%d-%m-%Y') as datte1,transfer_remark,
	project_code1,project_code2,costcenter_code
	from transfer 
	where transfer_reference=ifnull('".$sref."',transfer_reference)";
	$result1=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result1)){
	extract($rows);
	}

	//echo "asd".$startrange;
/*	if ($startrange!='' )
		{
			echo'
								<tr '.$Color.'>
								
								  <td height="22"><a href="transfertrans.php?sref='.$transfer_reference.'&stratrange=1" class="style15"><span class="style15 style17" style="text-decoration:underline;">'.$transfer_reference.'</span></a></td>
								  <td height="22"><span class="style15">'.$datte1.'</span></td>
								  <td height="22"><span class="style15">'.$transfer_remark.'</span></td>
								  <td height="22"><span class="style15">'.$project_code1.'</span></td>
								  <td height="22"><span class="style15">'.$project_code2.'</span></td>
								  <td height="22" colspan="4"><span class="style15">'.$costcenter_code.'</span><span class="style15">&nbsp;</span></td>
								</tr>
									';

	
		}*/
	//else
	if ($sref=='')
		$sref = 'null';
		//if ($sref!='')
		{ 
			
			$query="select transfer_reference,date_format(transfer_date,'%d-%m-%Y') as datte1,transfer_remark,
					project_code1,project_code2,costcenter_code
					from transfer where transfer_reference=ifnull($sref,transfer_reference) order by transfer_reference";
			$result=mysql_query($query,$connection) or die(mysql_error());
			$totalrows = mysql_num_rows($result);
			//echo $query."<br>";
			if ($startrange=='')
				$startrange = 1;
			if ($perpage=='')
				$perpage = 20;
			$query="select transfer_reference,date_format(transfer_date,'%d-%m-%Y') as datte1,transfer_remark,
					project_code1,project_code2,costcenter_code
					from transfer  where transfer_reference=ifnull($sref,transfer_reference)  order by transfer_reference limit ".$startrange.",".$perpage;
						//echo $query;

					$result=mysql_query($query,$connection) or die(mysql_error());		

					while($rows=mysql_fetch_array($result)){
							extract($rows);
				
							$ct+=1;

							if($ct%2==0)
							{
								$Color="style='background-color:".$grid_color1."'";
								
								}else{
									
								$Color="style='background-color:".$grid_color2."'";	
							}

								echo'
								<tr '.$Color.'>
							
								  <td height="22"><a href="transfertrans.php?sref='.$transfer_reference.'&startrange=1&perpage='.$perpage.'" class="style15"><span class="style15 style17" style="text-decoration:underline;">'.$transfer_reference.'</span></a></td>
								  <td height="22"><span class="style15">'.$datte1.'</span></td>
								  <td height="22"><span class="style15">'.$transfer_remark.'</span></td>
								  <td height="22"><span class="style15">'.$project_code1.'</span></td>
								  <td height="22"><span class="style15">'.$project_code2.'</span></td>
								  <td height="22" colspan="4"><span class="style15">'.$costcenter_code.'</span><span class="style15">&nbsp;</span></td>
								</tr>
									';
							}
							
		
			
			
		
		echo"
		<tr><td>&nbsp;</td></tr>
		<tr><td colspan=10><table width='100%' border=0><tr><td width='300'></td><td width='300'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='images/arrowleft.jpg' onMouseOver=\"style.cursor='hand'\"  onclick=setprvpage('".$sref."','".$prvstartrange."','".$perpage."')>";
			}
		else
			echo "&nbsp";
		
		echo"</td><td>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
			echo"<img src='images/arrowright.jpg'  onMouseOver=\"style.cursor='hand'\" onclick=setnextpage('".$sref."','".$startrange."','".$perpage."')>";
					}
		echo"</td></tr>";
		
		}

		echo"<table>";
		echo"</td></tr>
		</table>";
	}	
	echo"</td></tr>";
//unset($HTTP_SESSION_VARS['error']);
	print <<<HERE
</form>
</body>



HERE;

?>