<?php



session_start();
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");

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

$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 ".$HTTP_SESSION_VARS['dbLabel'].".login  where user_account ='".$HTTP_SESSION_VARS['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
				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];
	}


	
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 x = parseFloat(qty1);
var y = parseFloat(qty);


 if (qty == '' || qty*1 != qty/1 || qty <= 0){
		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 settransfer(){
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';
	opener.document.transfer.submit();
}


function submitform(actionmoded,transferdt_id){
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;

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


if (document.transferitems.p_item_code.value=='')
	alert('Please choose at least one item.');
else
	{
	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;
	document.transferitems.submit();
	}
}


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

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 fromwarehouse1 = fromwarehouse.replace('&','%26');
//var towarehouse1 = towarehouse.replace('&','%26');

str1= 'list_items.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;

  width = screen.width - 190;
  height = screen.height - 250;
  window.open(str1,"",'width=850,height=400,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;
}

.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()'>
<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'>

HERE;


echo'<table border=0 width=100% > ';
echo"		   		   <tr bgcolor='#F7F7F7' height='25'>
		     <th colspan='10'><span class='style16'>Add Items </span></th></tr>
";
		   
		   echo"<tr><td colspan=12><table width='100%'>";


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."'  size=10>
		  <input type='text' name='p_item_description' value='".$p_item_description."'  size=20>
		  <label><span class='style12'><input type='image' src='img/btnopen.jpg' title=' Select Item '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onclick=openitempage('".$index."','".$fromwarehouse."') /></span></label>
		  </td></tr>";		  
echo'<tr bgcolor="#F7F7F7"><td><span class="style4">Quantity</td>';
echo	  "<td><input type='text' name='p_item_quantity' value='".$p_item_quantity."' onblur=chk() size=4>
		  <input type='hidden' name='p_item_quantity1' value='".$p_item_quantity1."'  size=4>
		  </td>";
		  
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>";
  
echo'<tr bgcolor="#F7F7F7"><td><span class="style4">From Warehouse</td>';
echo	  "<td  width='10' ><input type='text'  readonly name='fromwarehouse'  id='fromwarehouse' value='$fromwarehouse'></td>";

echo'<tr bgcolor="#F7F7F7"><td><span class="style4">To Warehouse</td>';
echo	  "<td  width='10' ><input type='text' name='towarehouse' readonly value='$towarehouse' id='towarehouse'></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='40'></td>";

	echo"</table></td></tr>";
		   
		   
		   if ($transferdt_id=='')
		   echo"<tr bgcolor='#F8F8F8'><td></td><td align='center' colspan=6>
		   <input type='button' onclick=submitform('i','".$transferdt_id."') ".$style." name='Submit' value='Submit record'>&nbsp;&nbsp;&nbsp;";
		   else
		   echo"<tr bgcolor='#F8F8F8'><td></td><td align='center' colspan=6>
		   <input type='button' onclick=submitform('e','".$transferdt_id."') ".$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>";
?>