<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");

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

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

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
		mysql_query("SET NAMES 'utf8'"); 
		mysql_query('SET CHARACTER SET utf8'); 
		mysql_set_charset('utf8', $connection);
}
	
//Read From Module Table
$querymodule="Select ifNull(Module_TransferWithOneWh,0) As Module_TransferWithOneWh 
			,Module_TransferSorder,ifnull(Module_ZeroQuantity,0) as Module_ZeroQuantity 
			,ifnull(Module_Unit1Method,0) as Module_Unit1Method
			,ifnull(Module_DoubleUnit,0) as Module_DoubleUnit
			From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Warehouse List
$querywarehouse=" select distinct warehouse.warehouse_code, warehouse_name ".
				" from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
				" order by warehouse.warehouse_code";
$resultwh = mysql_query($querywarehouse,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);
if ($whexist == 0)
	$querywarehouse="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
	
$resultwarehouse=mysql_query($querywarehouse,$connection) or die(mysql_error());

	
$resultwarehousefrom=mysql_query($querywarehouse,$connection) or die(mysql_error());



if ($transfer_id!='')
	{	
	
		$UpdCost = "update temp_transfer set costcenter_code = '".$costcent."',tocostcenter_code  =  '".$tocostcent."' where transfer_id = ".$transfer_id;
		$result=mysql_query($UpdCost,$connection) or die(mysql_error());					
	}
	
if ($transfer_id!='')
{		
	$query="select Transfer_WarehouseTo from transfer where transfer_id = ".$transfer_id;
	$result=mysql_query($query) or die(mysql_error());
	$resultcheckwarehouse=mysql_fetch_array($result);
	$previousWarehouse = $resultcheckwarehouse[0];
	//fecho $previousWarehouse;
}
	
if ($transfer_id!='' and $Module_TransferWithOneWh==1)
	{	
	
		$UpdCost = "update temp_transfer set Transfer_WarehouseTo = '".$towarehouse."' where transfer_id = ".$transfer_id;
		$result=mysql_query($UpdCost,$connection) or die(mysql_error());					
		
	}




$query="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
$warehouseresultfrom=mysql_query($query) or die(mysql_error());
$warehouseresultto=mysql_query($query) or die(mysql_error());


$query = "select Unmodify_SellingPrice from ".$_SESSION['dbLabel'].".login  where user_account ='".$_SESSION['useraccount']."'";
$result=mysql_query($query) or die(mysql_error());
$rows=mysql_fetch_array($result);

	if ($rows[0]==1)
		$pricestatus = '';
	else
		$pricestatus = 'readonly';

		
		$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";
		
if ($actionmoded=='e' and $transferdt_id!='')	
	{
	$query = "select temp_transferdt.item_code,TransferDt_Quantity,Transferdt_remark,item_description ,TransferDt_Price
				,Item_UnitPurchaseDesc ,  Item_UnitSalesDesc,Item_Unit2Qty	
				from temp_transferdt,items
				where temp_transferdt.transferdt_id = ".$transferdt_id."
				and items.item_code=temp_transferdt.item_code";
	$result=mysql_query($query) or die(mysql_error());
	$rows=mysql_fetch_array($result);
	$p_item_code=$rows[0];
	$p_item_quantity=$rows[1];
	$p_item_description=$rows[3];
	$p_item_sellingprice1=$rows[4];
	$p_transferdt_remark=$rows[2];
	$Item_UnitPurchaseDesc =$rows[5];
	$Item_UnitSalesDesc	=$rows[6];
	$Item_Unit2Qty	=$rows[7];
	}
else if ($p_item_code!=''){
	$query = "select Item_UnitSalesDesc , Item_UnitPurchaseDesc
				from items
				where items.item_code='".$p_item_code."'";
	$result=mysql_query($query) or die(mysql_error());
	$rows=mysql_fetch_array($result);
	$Item_UnitSalesDesc	=$rows[0];
	$Item_UnitPurchaseDesc =$rows[1];


}
$query="select 1 from warehouse where warehouse_production=1 and warehouse_code = '".$fromwarehouse."'";
								$result=mysql_query($query,$connection) or die(mysql_error());
								$isprod = mysql_num_rows($result);
						if ($isprod=='')  
									$isprod=0;
									
								
	
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" language="javascript">

function chk(){

var qty1 = document.transferitems.p_item_quantity1.value;
var qty = document.transferitems.p_item_quantity.value;
var pwh = document.transferitems.previousWarehouse.value;
var twh = document.transferitems.towarehouse.value;
var actmode = document.transferitems.actionmode.value
var x = parseFloat(qty1);
var y = parseFloat(qty);

if (document.transferitems.isprod.value==1)
	return 1;
//	alert(document.transferitems.isprod.value);
	
if ((qty == '' || qty*1 != qty/1 || qty <= 0) && ( (actmode=='edit' && pwh==twh) || (actmode!='edit') )){
		alert('Quantity should be a NUMERIC value and MORE THAN Zero');
		document.transferitems.p_item_quantity.focus();
		return 0;
}
else
if (y>x)
	{
		alert('Quantity Exceeds max:'+qty1);
		document.transferitems.p_item_quantity.focus();
		return 0;
	}	
return 1;


	}
	
	
function changeqty2(vnum,itemunit,moduleunit1){

if (vnum==1)
	{
if (document.transferitems.Item_Unit2Qty.value!='')
return;
		
			if (moduleunit1==1 && itemunit !='')
					{
					var itemqty = document.transferitems.p_item_quantity.value;
					var xx = Number(itemqty) * Number(itemunit);

					document.transferitems.Item_Unit2Qty.value = xx;
					}
			else {
				if (moduleunit1==0 && itemunit !='')
						{
							var itemqty = document.transferitems.p_item_quantity.value;
							var xx = Number(itemqty) / Number(itemunit);
							document.transferitems.Item_Unit2Qty.value = xx;
						}
				}
	}
else {
if (document.transferitems.p_item_quantity.value!='')
return;
			if (moduleunit1==1 && itemunit !='')
					{
					var itemqty = document.transferitems.Item_Unit2Qty.value;
					var xx = Number(itemqty) / Number(itemunit);

					document.transferitems.p_item_quantity.value = xx;
					}
			else {
				if (moduleunit1==0 && itemunit !='')
						{
							var itemqty = document.transferitems.Item_Unit2Qty.value;
							var xx = Number(itemqty) * Number(itemunit);
							document.transferitems.p_item_quantity.value = xx;
						}
				}
	}

}
	
function settransfer(TransType){

var transfer_id= document.transferitems.transfer_id.value;
var opener_transfer	=opener.document.transfer.transfer_id.value;
	if (opener_transfer=='')
	{
		opener.document.transfer.transfer_id.value=transfer_id;
		opener.document.transfer.actionmode.value='insert';
	}	
	
	opener.document.transfer.action='Form_Transfer.php?=TransType='+TransType;
	opener.document.transfer.submit();
}


function submitform(ModuleZeroQuantity,actionmoded,transferdt_id,td,transit,TransType){

var fromwarehouse= document.transferitems.fromwarehouse.value;
var towarehouse= document.transferitems.towarehouse.value;
var transferdt_remark= document.transferitems.p_transferdt_remark.value;
var actionmode= document.transferitems.actionmode.value;
var transfer_id= document.transferitems.transfer_id.value;
var transfer_remark= document.transferitems.transfer_remark.value;
var transfer_date= document.transferitems.transfer_date.value;
var driver_name = document.transferitems.driver_name.value;
var vehicle_no = document.transferitems.vehicle_no.value;
var fromproject= document.transferitems.fromproject.value;
var toproject= document.transferitems.toproject.value;
var itemcode= document.transferitems.p_item_code.value;
var costcent= document.transferitems.costcent.value;
var tocostcent= document.transferitems.tocostcent.value;
var item_withserial= document.transferitems.item_withserial.value;
var lstItemType= document.transferitems.lstItemType.value;
var documentrefno= document.transferitems.documentrefno.value;
var Item_Unit2Qty= document.transferitems.Item_Unit2Qty.value;

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

if (ModuleZeroQuantity!=1)
	var check= chk();
else
	var check= 1;		

	


if (document.transferitems.p_item_code.value=='')
	alert('Please choose at least one item.');
else
	{
	if (check==1)
	{
	document.transferitems.action= 'Form_Transfer_Actions.php?fromproject='+fromproject+'&toproject='+toproject+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&transferdt_remark='+transferdt_remark+'&actionmoded='+actionmoded+'&transfer_id='+transfer_id+'&transfer_remark='+transfer_remark+'&transfer_date='+transfer_date+'&drivername='+driver_name+'&vehicle_no='+vehicle_no+'&transferdt_id='+transferdt_id+'&actionmoded='+actionmoded+'&itemcode='+itemcode+'&costcent='+costcent+'&tocostcent='+tocostcent+'&td='+td+'&item_withserial='+item_withserial+'&transit='+transit+'&lstItemType='+lstItemType+'&TransType='+TransType+'&Item_Unit2Qty='+Item_Unit2Qty;
	document.transferitems.submit();
	}
	}
	//if (actionmoded=='e')
	//	self.close();
	
}

function deleteitem(id){

var fromwarehouse= document.transferitems.fromwarehouse.value;
var towarehouse= document.transferitems.towarehouse.value;
	var toproject = document.transferitems.toproject.value;
	var fromproject = document.transferitems.fromproject.value;
	var actionmode = document.transferitems.actionmode.value;
	var transfer_id = document.transferitems.transfer_id.value;
	var transfer_remark = document.transferitems.transfer_remark.value;
	var transfer_date = document.transferitems.transfer_date.value;
	var driver_name = document.transferitems.driver_name.value;
	var vehicle_no = document.transferitems.vehicle_no.value;

	fromwarehouse = fromwarehouse.replace('&','%26');
	towarehouse = towarehouse.replace('&','%26');
	
document.transferitems.action='d_tempitem.php?id='+id+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&actionmode='+actionmode+'&transfer_id='+transfer_id+'&transfer_remark='+transfer_remark+'&transfer_date='+transfer_date+'&driver_name='+driver_name+'&vehicle_no='+vehicle_no;
document.transferitems.submit();
}

function closewindow1(){

self.close();
}

function closewindow(){

self.close();
}

function openitempage(index,fromwarehouse,TransType){

var x = 'item_code['+index+']';
var name = document.getElementById(x); 
var fromwarehouse= document.transferitems.fromwarehouse.value;
var towarehouse= document.transferitems.towarehouse.value;
var fromproject= document.transferitems.fromproject.value;
var toproject= document.transferitems.toproject.value;
var transferdt_remark= document.transferitems.p_transferdt_remark.value;
var actionmode= document.transferitems.actionmode.value;
var transfer_id= document.transferitems.transfer_id.value;
var transfer_remark= document.transferitems.transfer_remark.value;
var transfer_date= document.transferitems.transfer_date.value;
var driver_name = document.transferitems.driver_name.value;
var vehicle_no = document.transferitems.vehicle_no.value;
var td = document.transferitems.td.value;
var vItemType = document.transferitems.lstItemType.value;

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

str1= 'Form_ListItems.php?item=1&index='+index+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&fromproject='+fromproject+'&toproject='+toproject+'&actionmode='+actionmode+'&transfer_id='+transfer_id+'&transfer_remark='+transfer_remark+'&transfer_date='+transfer_date+'&driver_name='+driver_name+'&vehicle_no='+vehicle_no+'&td='+td+'&ItemType='+vItemType+'&TransType='+TransType;

  width = screen.width - 100;
  height = screen.height - 100;
  window.open(str1,"",'width=900,height=620,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: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
	font-size: 12px;
}
.style3 {color: #999999}
.style4{
	
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style44{
	
	font-size: 11px;
	color: #999999;
	font-weight: regular;
}
.style15 {
	font-size: 11px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Verdana, Arial, Helvetica, sans-serif;
}
.style16 {
	font-size: 12px;
	color: #000000;
	font-weight: bold;
	font-family: "Verdana, Arial, Helvetica, sans-serif;
}

-->
</style></head>
<title>TRANSFER</title>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<body onload=settransfer('$TransType')>
<form name='transferitems' method='post' action=''>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='transfer_id' value='$transfer_id'>
<input type='hidden' name='transfer_remark' value='$transfer_remark'>
<input type='hidden' name='transfer_date' value='$transfer_date'>
<input type='hidden' name='driver_name' value='$driver_name'>
<input type='hidden' name='vehicle_no' value='$vehicle_no'>
<input type='hidden' name='fromproject' value='$fromproject'>
<input type='hidden' name='toproject' value='$toproject'>
<input type='hidden' name='costcent' value='$costcent'>
<input type='hidden' name='tocostcent' value='$tocostcent'>
<input type='hidden' name='td' value='$td'>
<input type='hidden' name='item_withserial' value='$item_withserial'>
<input type='hidden' name='previousWarehouse' value='$previousWarehouse'>
<input type='hidden' name='documentrefno' value='$documentrefno'>
<input type='hidden' name='isprod' value='$isprod'>
HERE;

if($p_item_code != ''){
	
	$data = substr($transfer_date, 6, 4) . substr($transfer_date, 3, 2) . substr($transfer_date, 0, 2);
    
	$transfer_date1 = substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2)." ".strftime("%H").":".strftime("%M").":".strftime("%S");

	$qry="select item_pack from items where item_code = '".$p_item_code."'";
	$resultlog=mysql_query($qry,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($resultlog)){
			extract($rows);
		}
	
	$min_sorder_qty = 0;
	$min_available_qty = 9999999999;
	$min_exists_qty = 9999999999;
	$available_qty = 0;
	$exist_qty = 0;
	
	if (empty($transfer_id)) $transfer_id = 0;
	
	if($item_pack == '1'){
		$query = "SELECT Item_CodePackDt, PackDt_Quantity FROM packdt WHERE Item_Code = '".$p_item_code."' And ifNull(PackDt_CostPercentage,0) != 0 ";
		$result = mysql_query($query, $connection);			
		//echo $query;
		while($cur = mysql_fetch_row($result)){
			$Qry_QtyBookTemp  = " SELECT ifnull(QtyBooking_Temp('".$cur[0]."', '".$fromwarehouse."', '".$transfer_date1."', $transfer_id),0)";
			$Qry_QtyAvailable = " SELECT ifnull(QtyExistsWSorder_Temp('".$cur[0]."', '".$fromwarehouse."', '".$transfer_date1."', $transfer_id, 'TR', '', '', 0),0) QtyExists ";
			$Qry_QtyInTemp    = " Select ifNull(Sum(ifNull(TransferDt_Quantity,0)),0) FROM Temp_Transferdt ".
							    " WHERE Item_code = '".$cur[0]."'  And  TransferDt_WarehouseFrom = '".$fromwarehouse."' And Transfer_ID = $transfer_id And SorderDt_ID != ifNull('".$transferdt_id."',0) ";
							
			/*$Qry_QtyExists    = " Select cast(ifNull(Sum(ifNull(QuantityProduceIn,0) - ifNull(QuantityProduceOut,0) + ifNull(QuantityEntered,0) - ifNull(QuantityDelivered,0)),0) as decimal(20,2)) as QuantityExists From StkTransaction ".
		    				    " Where StkTransaction.Item_Code = '".$cur[0]."' ".
			    			    " And (('".$fromwarehouse."' = '' and 1 = 1) or ('".$fromwarehouse."' != '' and ifNull(StkTransaction.Warehouse_Code, -1) = ifNull('".$fromwarehouse."', ifNull(StkTransaction.Warehouse_Code, -1))) ) ".
				    		    " And Transaction_Date <= '".$transfer_date1."' ";
			*/
			$Qry_QtyExists = " SELECT ifnull(QtyExists('".$cur[0]."', '".$fromwarehouse."', '".$transfer_date1."', 0, 'TR', '', ''),0) As QtyExists ";
			
			//echo "<br><br>".$Qry_QtyBookTemp;
			//echo "<br><br>".$Qry_QtyInTemp;
			//echo "<br><br>".$Qry_QtyAvailable;
			//echo "<br><br>".$Qry_QtyExists;
			$sub_result  = selectData($connection, $Qry_QtyBookTemp);
			$sub_result1 = selectData($connection, $Qry_QtyAvailable);
			$sub_result2 = selectData($connection, $Qry_QtyInTemp);
			$sub_result3 = selectData($connection, $Qry_QtyExists);
		
			if ($sub_result[0] < 0){$sub_result[0] = 0;}
			
			$booking_qty = (($sub_result[0] / $cur[1]) + ($sub_result2[0] / $cur[1]));
			if ($booking_qty > $min_sorder_qty){
				$min_sorder_qty = $booking_qty;
			}
			
			$available_qty = (($sub_result1[0] / $cur[1]) - ($sub_result2[0] / $cur[1]));
			$available_qty = abs($available_qty);
			if ($available_qty < $min_available_qty && $available_qty > 0){
				$min_available_qty = $available_qty;
			}
			
			$exist_qty = ($sub_result3[0] / $cur[1]); 
			if ($exist_qty < $min_exists_qty && $exist_qty != 0){
				$min_exists_qty = $exist_qty;
			}
			
		}
		
		
		
		$min_sorder_qty = floor($min_sorder_qty);
		//$min_available_qty = floor($min_available_qty);
		$min_available_qty = floor($min_exists_qty) - floor($min_sorder_qty);
		$min_exists_qty = floor($min_exists_qty);

	}else{ 
		$Qry_QtyBookTemp = "SELECT ifnull(QtyBooking_Temp('".$p_item_code."', '".$fromwarehouse."', '".$transfer_date1."', $transfer_id),0) ";
		//echo $Qry_QtyBookTemp;
		$result = selectData($connection, $Qry_QtyBookTemp);
		if ($result[0] < 0){$result[0] = 0;}
		$min_sorder_qty = $result[0];
		
		/*$Qry_QtyExists = " Select cast(ifNull(Sum(ifNull(QuantityProduceIn,0) - ifNull(QuantityProduceOut,0) + ifNull(QuantityEntered,0) - ifNull(QuantityDelivered,0)),0) as decimal(20,2)) as QuantityExists From StkTransaction ".
						 " Where StkTransaction.Item_Code = '".$p_item_code."' ".
						 " And (('".$fromwarehouse."' = '' and 1 = 1) or ('".$fromwarehouse."' != '' and ifNull(StkTransaction.Warehouse_Code, -1) = ifNull('".$fromwarehouse."', ifNull(StkTransaction.Warehouse_Code, -1))) ) ".
						 " And Transaction_Date <= '".$transfer_date1."' ";
		*/
		
		if ($transferdt_id ==''  )  $transferdtid = 0; else $transferdtid = $transferdt_id;
		if ($transfer_id ==''  )    $transferid = 0;   else $transferid = $transfer_id;
		
		$Qry_QtyExists = " SELECT ifnull(QtyExists('".$p_item_code."', '".$fromwarehouse."', '".$transfer_date1."', $transferdtid, 'TR', '', ''),0) As QtyExists ";
		//echo $Qry_QtyExists;	
		$result = selectData($connection, $Qry_QtyExists);
		$min_exists_qty = $result[0];
		//echo $Qry_QtyExists;
		
		$Qry_QtyAvailable = " Select QtyExistsWSorder('".$p_item_code."', '".$fromwarehouse."', '".$transfer_date1."', $transferid, 'TR', '', '') QtyExists From Dual ";
		$result = selectData($connection, $Qry_QtyAvailable);
		$min_available_qty = $result[0];

		$Qry_QtyInTemp = " Select ifNull(Sum(ifNull(TransferDt_Quantity,0)),0) FROM Temp_Transferdt ".
		                 " WHERE Item_code = '".$p_item_code."'  And  TransferDt_WarehouseFrom = '".$fromwarehouse."' And Transfer_ID = $transfer_id And TransferDt_ID != ifNull('".$transferdt_id."',0) ";
						 
		$Qry_QtyInTemp1 = " Select ifNull(Sum(ifNull(TransferDt_Quantity,0)),0) FROM Temp_Transferdt ".
		                  " WHERE Item_code = '".$p_item_code."'  And  TransferDt_WarehouseFrom = '".$fromwarehouse."' And Transfer_ID = $transfer_id And TransferDt_ID = ifNull('".$transferdt_id."',0) ";				 
		//echo $Qry_QtyInTemp;
		$result = selectData($connection, $Qry_QtyInTemp);
		$result1 = selectData($connection, $Qry_QtyInTemp1);
		$min_available_qty = $min_available_qty - $result[0];
		$min_exists_qty = $min_exists_qty - $result[0];
		$min_sorder_qty = $min_sorder_qty ;

	}
	//echo $query;
	$txtPOQty = $min_sorder_qty;
	$txtAvailableQty = $min_available_qty;
	$txtExistingQty = $min_exists_qty;
	
	}





echo'<table border=0 width=100% > ';



echo"		   		   <tr bgcolor='#F7F7F7' height='25'>
		     <th colspan='12'><span class='style16'>Items </span></th></tr>
";
if ($message!='')		   
echo"		   		   <tr bgcolor='#F7F7F7' height='25'>
		     <th align=left colspan=8><span class='style15'>$message </span></th></tr>
";
else	
	echo"		   		   <tr bgcolor='#F7F7F7' height='25'>
		     <th align=left colspan=8><span class='style15'>&nbsp; </span></th></tr>
";


 



echo"<tr><td colspan=12><table width='100%' border=0>";
if ($TransType=='Tr') {
echo"<select name='lstItemType' style='font-size:11px; visibility:hidden;width:200px; height:18px;'>";
echo "<option selected value='AllItems'></option>";
echo"</select>";
}
else
if ($TransType=='Rm') {
echo"
<tr bgcolor='#F7F7F7' height='25'>
            <td valign='center' align='left' ><span class='style4'>Item Type</span></td>
		    <td colspan='7'>	
			<select name='lstItemType' style='font-size:11px; width:200px; height:18px;'>";
			
			
			/*if ($lstItemType == "AllItems"){
				echo "<option selected value='AllItems'>All Items</option>";
			}else{
				echo "<option value='AllItems'>All Items</option>";
			}*/	
			if ($lstItemType == "FinishGoodPack"){
				echo "<option selected value='FinishGoodPack'>Finished Good Pack</option>";
			}else{
				echo "<option value='FinishGoodPack'>Finished Good Pack</option>";
			}
			if ($lstItemType == "SemiFinishSingle"){
				echo "<option selected value='SemiFinishSingle'>Semi-Finished Single</option>";
			}else{
				echo "<option value='SemiFinishSingle'>Semi-Finished Single</option>";
			}
			if ($lstItemType == "SemiFinishPack"){
				echo "<option selected value='SemiFinishPack'>Semi-Finished Pack</option>";
			}else{
				echo "<option value='SemiFinishPack'>Semi-Finished Pack</option>";
			}
			if ($lstItemType == "FinsihGoodSingle"){
				echo "<option selected value='FinsihGoodSingle'>Finsih-Good Single</option>";
			}else{
				echo "<option value='FinsihGoodSingle'>Finsih-Good Single</option>";
			}
			if ($lstItemType == "rawmaterials"){
				echo "<option selected value='rawmaterials'>Raw Materials</option>";
			}else{
				echo "<option value='rawmaterials'>Raw Materials</option>";
			}
			
			
			echo "</select></td></tr>";
			}
			
echo'<tr bgcolor="#F7F7F7">
		  <td width="10%"><span class="style4">Item&nbsp;*</td>';
echo"<td  ><input type='text' name='p_item_code' value='".$p_item_code."' ";
if ($item_withserial==1 or $transit==1)
	echo " readonly ";
echo" size=25>
<label><span class='style12'><img src='img/btnopen.jpg' title=' Select Item '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onclick=\"openitempage('".$index."','".htmlentities($fromwarehouse)."','$TransType')\" ";
if ($item_withserial==1 or $transit==1)
	echo " disabled ";
echo"/></span></label>
		  <input type='text' name='p_item_description' ";
if ($item_withserial==1 or $transit==1)
	echo " readonly ";
	
echo" value='".$p_item_description."'  size=50>
		  
		  </td><td><span class='style4'>Existing Qty</td><td align='right'><b>".number_format($txtExistingQty,0)."</b> </td></tr>";		  
		  
$q = "select ifnull(Item_Unit,0) from items where item_code = '$p_item_code' ";		  
$result=mysql_query($q) or die(mysql_error());
$rows=mysql_fetch_array($result);
$Item_Unit=$rows[0];
	
	
	//$Item_Unit2Qty = $Item_Unit * $p_item_quantity;
	
echo'<tr bgcolor="#F7F7F7"><td><span class="style4">Quantity</td>';
echo	  "<td><input type='text' name='p_item_quantity' onchange=changeqty2(1,'$Item_Unit',$Module_Unit1Method) value='".$p_item_quantity."' ";
if ($item_withserial==1 and ($Module_TransferSorder <> 1))
	echo " readonly ";
echo"size=4> ";

if ($Module_DoubleUnit==1)
echo "$Item_UnitSalesDesc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";


if ($Module_DoubleUnit==1)
echo"Qty2<input type='text' name='Item_Unit2Qty'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method)  value='".$Item_Unit2Qty."'  size=4>";
else
echo"<input type='hidden' name='Item_Unit2Qty'  onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method)  value='".$Item_Unit2Qty."'  size=4>";

echo"	  <input type='hidden' name='p_item_quantity1' value='".$p_item_quantity1."'  size=4>";
	if ($Module_DoubleUnit==1)
		  echo " $Item_UnitPurchaseDesc ";
		  echo"</td><td><span class='style4'>Booking Qty</td><td align='right'><b>".number_format($txtPOQty,0)."</b></td></tr>";
		  
echo'<tr bgcolor="#F7F7F7"><td><span class="style4">Price</td>';
echo	  "<td  width='10' >
<input type='text' name='p_item_sellingprice1' ".$pricestatus." value='".$p_item_sellingprice1."'  size=4>
</tD>
<td><span class='style4'>Real Qty</td><td align='right'><b>".number_format($txtAvailableQty,0)."</b> 
</td>
</td>";
  
echo'<tr bgcolor="#F7F7F7"><td><span class="style4">From Warehouse</td>';



if ($Module_TransferWithOneWh==1)
echo	  "<td  width='10' ><input type='text'  readonly name='fromwarehouse'  id='fromwarehouse' value='$fromwarehouse'></td>";
else {
	echo	  "<td  width='10' ><select name='fromwarehouse' id='fromwarehouse' style='font-size:11px; width:200px; height:18px;' >";
			echo"<option></option>";
			while($wrhf=mysql_fetch_row($resultwarehousefrom)){
			echo"<option ";
				if (($fromwarehouse==$wrhf[0]))
					echo " selected ";
			echo" value='$wrhf[0]'>$wrhf[0] / $wrhf[1]</option>";
			}
			echo"</select></td>";
    }
	


echo'<tr bgcolor="#F7F7F7"><td><span class="style4">To Warehouse</td>';


if ($Module_TransferWithOneWh==1)
echo	  "<td  width='10' ><input type='text' name='towarehouse' readonly value='$towarehouse' id='towarehouse'></td>";
else {
	echo	  "<td  width='10' ><select name='towarehouse' id='towarehouse' style='font-size:11px; width:200px; height:18px;' >";
			echo"<option></option>";
			while($wrhf=mysql_fetch_row($resultwarehouse)){
			echo"<option ";
				if (($towarehouse==$wrhf[0]))
					echo " selected ";
			echo" value='$wrhf[0]'>$wrhf[0] / $wrhf[1]</option>";
			}
			echo"</select></td>";
    }
	


echo'<tr bgcolor="#F7F7F7"><td><span class="style4">Remark</td>';
echo	  "<td  width='10' ><input type='text' name='p_transferdt_remark' value='".$p_transferdt_remark."'  size='80'></td>";

	echo"</table></td></tr>";
		   
		   if ($transit=='')
		   $transit=0;
		   if ($transferdt_id=='')
		   echo"<tr bgcolor='#D8D8D8'><td align='center' colspan=7>
		   <input type='button' onclick=submitform($Module_ZeroQuantity,'i','".$transferdt_id."','".$td."',".$transit.",'".$TransType."') ".$style." name='Submit' value='Submit record'>&nbsp;&nbsp;&nbsp;";
		   else
		   echo"<tr bgcolor='#D8D8D8'><td></td><td align='center' colspan=7>
		   <input type='button' onclick=submitform($Module_ZeroQuantity,'e','".$transferdt_id."','".$td."',".$transit.",'".$TransType."') ".$style." name='Submit' value='Submit record'>&nbsp;&nbsp;&nbsp;";
		   
			
			
			   echo'<input type="button" onclick=closewindow() name="close"  '.$style.' value="Close Window">';
		   
		   echo'</td></tr>';
		   
		   	/*
		   echo'<tr><td align="center" colspan=10>&nbsp;</td></tr>  
		   <tr bgcolor="#F7F7F7"><td>&nbsp;</td> 
      <td width="5%" bgcolor="#F7F7F7"><span class="style4">Code</span></td>
      <td width="35%" bgcolor="#F7F7F7"><span class="style4">Description</span></td>
      <td width="5%" bgcolor="#F7F7F7"><span class="style4">Qty</span></td>
      <td  width="5%" bgcolor="#F7F7F7"><span class="style4">Price</span></td>
      <td  width="10%" bgcolor="#F7F7F7"><span class="style4">From WH.</span></td>
      <td  width="10%" bgcolor="#F7F7F7"><span class="style4">To WH.</span></td>
      <td width="30%" bgcolor="#F7F7F7"><span class="style4">Remark</span></td>
    </tr>';





	
	$query = "select temp_transferdt.item_code , item_description,TransferDt_Quantity,TransferDt_Price,TransferDt_WarehouseFrom,TransferDt_WarehouseTo
			,Transferdt_remark ,transferdt_id from temp_transferdt , items where 
			items.item_code=temp_transferdt.item_code
			and items.item_withserialno = 0	";
	//echo $query;
	$transdtresult=mysql_query($query) or die(mysql_error());
	while($rows=mysql_fetch_array($transdtresult))
			{
			
			$Item_code=$rows[0];
			$Item_Description=$rows[1];
			$TransferDt_Quantity=$rows[2];
			$TransferDt_Price=$rows[3];
			$TransferDt_WarehouseFrom=$rows[4];
			$TransferDt_WarehouseTo=$rows[5];
			$Transferdt_remark=$rows[6];
			echo"<tr>
		    <td ><img src='img/c_delete.png' onclick=deleteitem('".$rows[7]."')></td>
			<td><span class='style44'>".$Item_code."</span></td>
			<td ><span class='style44'>".$Item_Description."</span></td>
			<td ><span class='style44'>".$TransferDt_Quantity."</span></td>
			<td ><span class='style44'>".$TransferDt_Price."</span></td>
			<td ><span class='style44'>".$TransferDt_WarehouseFrom."</span></td>
			<td ><span class='style44'>".$TransferDt_WarehouseTo."</span></td>
			<td ><span class='style44'>".$Transferdt_remark."</span></td>
			</tr>";
			}
*/
	
echo"<tr><td colspan='12'>&nbsp;</td></tr>";


echo"</table>";


	function selectData($conn, $query){
		$result = mysql_query($query, $conn);
		$cur = mysql_fetch_row($result);		
		return $cur;
	}
?>