<?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);
}

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

}

$queryWHExist = " select towarehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and ifnull(towarehouse_code,'') <> '' ";
$resWHExist = mysql_query($queryWHExist, $connection);
$WHExist = mysql_num_rows($resWHExist);


?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Warehouses</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  document.form1.PLedger_number.value='';


}
</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;
}
.style3 {color: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="3" bgcolor="#DDDDDD"><span class="style1"> Warehouse </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Warehouse <br> Code / Name</span></td>
      <td bgcolor="#DDDDDD" colspan=2><input type="text" name="PLedger_number" value="<?php echo $PLedger_number; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $lcode; ?>">
	
   <input name="ledger1" type="hidden" id="ledger1"  value="<?php echo $ledger1; ?>">
   <input name="ledger2" type="hidden" id="ledger2"  value="<?php echo $ledger2; ?>">
   <input name="currency" type="hidden" id="currency"  value="<?php echo $currency; ?>">currency
  

        <?php echo"<input type='hidden' name='Warehouse' value='$Warehouse'>";?><input name="desc1" type="hidden" id="desc1" value="<?php echo $desc1; ?>" />
	    <input type="submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		<input type="button" name="cancelbtn" value="Cancel" onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>

	                    
    </tr>
<?php if($post=="1"){ ?>
<script type="text/javascript" language="javascript">


Warehouse = document.form1.Warehouse.value;
var parentText1 = window.opener.document.getElementById(Warehouse);
parentText1.value = document.form1.desc1.value.trim();
parentText1.value = document.form1.code1.value.trim();



<?php
	$a = $_GET['from_to_warehouse'];
 
 
	if (strpos($a, 'towarehouse') !== false) {
	 
	 
print <<<HERE

	try{
		
	ledger1 = document.form1.ledger1.value;
	window.opener.document.getElementById('txtClientCode').value = ledger1.trim();
	
	ledger2 = document.form1.ledger2.value;
	window.opener.document.getElementById('txtClientName').value = ledger2.trim();

	currency = document.form1.currency.value;
	window.opener.document.getElementById('txtCurr').value = currency.trim();
	window.opener.ChangeCurrency();
	
		// // //   opener.document.transferrequest.submit();
	
	}catch{
	 
	}

HERE;
	 
}
?>
 
self.close();


</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Warehouse Code </span></td>
      <td width="411" colspan="2"><span class="style2">Warehouse  Name </span></td>
      
    </tr>
<?php	
	// default warehouse
	$query="select Warehouse_code from ".$_SESSION['dbLabel'].".loginstk where default_warehouse = 1 and user_account='".$_SESSION['useraccount']."'";
	$defaultwarehouse=mysql_query($query,$connection) or die(mysql_error());
	$rows = mysql_fetch_row($defaultwarehouse);
	$defaultwarehousecode = $rows[0];
							
	if ($fromwarehouse=='')
	$fromwarehouse = $defaultwarehousecode;

	$sqlwarehouse = "select warehouse.warehouse_code,warehouse.warehouse_name , clients.ledger_number , clients.ledger_name, clients.currency_code 
					from warehouse
					left join clients on clients.warehouse_code = warehouse.warehouse_code 
					where  1=1 ";
	// stopped by nadine
	//warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')
			//echo $sqlwarehouse;
	$resultdefaultwarehouse=mysql_query($sqlwarehouse,$connection) or die(mysql_error());
							
	$sqlwarehouse1 = "select warehouse_code,warehouse_name from warehouse	where if('$WHExist'=1, warehouse_code in 
					(select towarehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."'), 1=1) ";
			
	if(mysql_num_rows($resultdefaultwarehouse)=="0"){
		$sqlwarehouse = "select warehouse_code,warehouse_name	from warehouse";							
		$sqlwarehouse1 = "select warehouse_code,warehouse_name from warehouse";	
	}									
	else if (($edit=='yes' or sref!='') and $fromwarehouseedit!=''){
		$sqlwarehouse = "select '".$fromwarehouseedit."' , '".$fromwarehousenameedit."' from dual union " . $sqlwarehouse;
		$sqlwarehouse1 = "select '".$towarehouseedit."' , '".$towarehousenameedit."' from dual union " . $sqlwarehouse1;			
	}
	if(mysql_num_rows($resultdefaultwarehouse)=="0")
		$sqlwarehouse = $sqlwarehouse . " where warehouse.warehouse_code like '".$PLedger_number."%' ";
	else
		$sqlwarehouse = $sqlwarehouse . " and warehouse.warehouse_code like '".$PLedger_number."%' ";
			
	$sqlwarehouse = $sqlwarehouse . " order by warehouse.warehouse_code ";
	$sqlwarehouse1 = $sqlwarehouse1 . " order by warehouse.warehouse_code ";

	if ($item == 'towarehouse' && $Warehouse == 'towarehouse' && $TransType =='Tr'){
		$warehouseresultfrom=mysql_query($sqlwarehouse1,$connection) or die(mysql_error());
	}else{
	 // echo $sqlwarehouse;
		$warehouseresultfrom=mysql_query($sqlwarehouse,$connection) or die(mysql_error());
}


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

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

?>
    <tr <?php echo $Color; ?>>
      	<td align="left">
	  	<a href="List_TrsWarehouseGrid.php?post=1&lcode=<?php echo ereg_replace("&","%26",$rows[0]); ?>
			&desc1=<?php echo ereg_replace("&","%26",$rows[1]); ?>	
		
			&ledger1=<?php echo ereg_replace("&","%26",$rows[2]) ?>
			
			&ledger2=<?php echo ereg_replace("&","%26",$rows[3]) ?>

			&currency=<?php echo ereg_replace("&","%26",$rows[4]) ?>
			
			&from_to_warehouse=<?php echo $_GET['item']; ?>
		
	  		&Warehouse=<?php echo $Warehouse; ?>"><?php echo $rows[0]; ?>
		</a>
		</td>
      
		<td colspan="2">
		<a href="List_TrsWarehouseGrid.php?post=1&lcode=<?php echo ereg_replace("&","%26",$rows[0]); ?>
			&desc1=<?php echo ereg_replace("&","%26",$rows[1]) ?>
		
			&ledger1=<?php echo ereg_replace("&","%26",$rows[2]) ?>

			&ledger2=<?php echo ereg_replace("&","%26",$rows[3]) ?>

			&currency=<?php echo ereg_replace("&","%26",$rows[4]) ?>		
			
			&from_to_warehouse=<?php echo $_GET['item']; ?>
					
			&Warehouse=<?php echo $Warehouse; ?>"><?php echo $rows[1]; ?>
		</a>
		</td>

 
    </tr>
	<!-- ledger1 -->
<?php
}

function explodeword($date){
	$trim = explode('/',$date);
	$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
	return $trim;
}
?>
  </table>
</form>
</body>
</html>

