<?php


include 'function.inc.php';

session_start();

//$HTTP_SESSION_VARS['dbName'] = 'dajcom_acc2010';
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}
		
		
		
include("config.inc.php");



print <<< HERE
<HTML>
<HEAD>
<TITLE> Transfer Report </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<style type="text/css">

table.master th { font-size: 13px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 11px;
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 13px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
				 
table.detail td { font-size: 10px; 
                  font-family:Times-New-Roman;
                 }				 
				 
table.detail td.sr  { font-size: 10px; 
					  font-style: italic; 
                      font-family:Times-New-Roman;
                    }
				 
table.totals td.labels { font-size: 11px; 
                         font-weight: bold;
                         font-family:Times-New-Roman;
						 border-width: 1px;
						 border-style: none solid solid solid;
  						 border-color: #666666;
                       }					  
table.totals td.amounts { font-size: 13px; 
                          font-family:Times-New-Roman;
						  border-width: 1px;
						  border-style: none none solid none;
  						  border-color: #666666;
				        }
table.totals td.totalborder {
								font-size: 13px; 
								font-family:Times-New-Roman;
								border-width: 1px;
								border-style: none solid solid none;
								border-color: #666666;
							}						
				 

</style>


</HEAD>

<BODY>
HERE;


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

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


	$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);


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

$ModuleProject=$Module_Project;
$ModuleCostCenter=$Module_CostCenter;




if($transfer_id!='')
{
$query = "SELECT TRANSFER_REFERENCE , date_format(transfer.TRANSFER_DATE,'%d/%m/%Y') as TRANSFER_DATE, Transfer_Remark , transfer.Project_code1 , transfer.Project_code2 , 
			Costcenter_Code , if((Transfer_Warehousefrom is null or Transfer_Warehousefrom = '') ,TransferDt_WarehouseFrom,Transfer_WarehouseFrom) Transfer_WarehouseFrom, 
			if((Transfer_WarehouseTo is null or Transfer_WarehouseTo = ''),TransferDt_WarehouseTo, Transfer_WarehouseTo)    Transfer_WarehouseTo
			, Driver_Name , Vehicle_No ,ToCostcenter_Code ,Document_RefNo,transferdt_warehousefrom,transferdt_warehouseto
			from transfer 
			left join transferdt on transferdt.transfer_id = transfer.transfer_id
			where transfer.transfer_id = ".$transfer_id."
			group by transfer.TRANSFER_REFERENCE , transfer.TRANSFER_DATE , transfer.Transfer_Remark , transfer.Project_code1 ,
			transfer.Project_code2 , transfer.Costcenter_Code , Transfer_WarehouseFrom ,
			Transfer_WarehouseTo , Driver_Name , Vehicle_No
			";
			


$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
extract($rows);
}



echo "<table border=0 width=250 cellspacing=0 cellpadding=0 ><tr><td align='left'>";
echo "<table border=0 width='250' cellspacing=2 cellpadding=0 class='master'  >";
			  echo"<col width=80>	  
			  <col width=30>	  
			  <col width=30>	  
			  ";
			  
	echo "<tr>
	<td height='60' ><img src='LogoFile.php' width='70' height='50' /></td>
	<td colspan=1 align='right'><b>";
	if ($TransType=='Rm')
	echo "Transfer Rm";
	else
	echo "Transfer";
	
	echo"</td><td align='right' colspan=2 >&nbsp;&nbsp;";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br>".$dt[1]." ".$dt[2];
	echo "</font></td></tr>";
	
	echo "<tr height='10'><td colspan=7><hr></td></tr>";
				
				

echo"<tr><td bgcolor=#D8D8D8><b>Reference</td><td width='50'>$TRANSFER_REFERENCE</td><td colspan=6></tD></tr>";

echo"<tr><td bgcolor=#D8D8D8><b>Date</td><td>$TRANSFER_DATE</td><td>&nbsp;</td>";

echo"</tr>";

echo"<tr><td bgcolor=#D8D8D8><b>Driver Name</td><td colspan=3>$Driver_Name</td>";

echo"</tr>";

echo"<tr><td bgcolor=#D8D8D8><b>Vehicle No</td><td colspan=3>$Vehicle_No</td>";


echo"</tr>";



/*echo"<td></tD><td bgcolor=#D8D8D8><b>Warehouse</td>";

if ($ModuleCostCenter==1  and $Module_ShowLayoutCost==1)
echo"<td bgcolor=#D8D8D8><b>CostCenter</td>";


if ($ModuleProject==1 and $Module_ShowLayoutProj==1)
echo"<td bgcolor=#D8D8D8><b>Project</td>";


echo"</tr>";*/
echo"<tr>";

echo"<td bgcolor=#D8D8D8><b>From WH</td>";
if ($Module_TransferWithOneWh==1)
	echo"<td colspan=2>$Transfer_WarehouseFrom</td>";
else
	echo"<td>&nbsp;</td>";

	/*
// Module_ShowLayoutProj , Module_ShowLayoutCost
if ($ModuleCostCenter==1 and $Module_ShowLayoutCost==1)
echo"<td>$Costcenter_Code</td>";

if ($ModuleProject==1 and $Module_ShowLayoutProj==1)
echo"<td>$Project_code1</td>";
*/
echo"</tr>";

echo"
<td bgcolor=#D8D8D8><b>To WH</td>";
if ($Module_TransferWithOneWh==1)
	echo"<td  colspan=2>$Transfer_WarehouseTo</td>";
ELSE	
	echo"<td>&nbsp;</td>";
	/*
if ($ModuleCostCenter==1  and $Module_ShowLayoutCost==1)
echo"<td >$ToCostcenter_Code</td>";


if ($ModuleProject==1 and $Module_ShowLayoutProj==1)
echo"<td>$Project_code2</td>";

*/

echo"<tr><td bgcolor=#D8D8D8><b>Remark</td><td colspan=3>$Transfer_Remark</td></tr>";

if ($TransType=='Rm')
	echo"</tr><td bgcolor=#D8D8D8><b>Doc. Ref No</td><td colspan=2>$Document_RefNo</td></tr>";

echo"</table></td></tr>";

echo"<tr height='10'><td colspan=3><hr></td></tr>";



if ($detail==0) {
$query = "select transferdt.Item_CodeFinished as Item_code, transferdt.Item_Barcode Item_Barcode, ifnull(Transferdt.Item_qtyPacked,0) as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id,  count(*) as itemscount
			 ,TransferDt_WarehouseTo,items.Item_UnitSalesDesc from transferdt , items
			where items.item_code = transferdt.Item_CodeFinished
			And transferdt.Item_CodeFinished Is Not Null
			and transfer_id = ".$transfer_id."
			group by Transferdt.Item_CodeFinished, Transferdt.TransferDt_WarehouseTo 
			Union
			select transferdt.Item_CodeSemiFinished Item_code, transferdt.Item_Barcode Item_Barcode, ifnull(Transferdt.Item_qtyPacked,0) as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id , count(*) as itemscount
			 ,TransferDt_WarehouseTo,items.Item_UnitSalesDesc
			 from transferdt , items
			where items.item_code = transferdt.Item_CodeSemiFinished
			And transferdt.Item_CodeSemiFinished Is Not Null
			and transfer_id = ".$transfer_id."
			group by Transferdt.Item_CodeSemiFinished, Transferdt.TransferDt_WarehouseTo 
			union
			select transferdt.Item_code Item_code, transferdt.Item_Barcode Item_Barcode, TransferDt_Quantity as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id , 1 as itemscount
			,TransferDt_WarehouseTo,items.Item_UnitSalesDesc
			from transferdt , items
			where items.item_code = transferdt.item_code
			And transferdt.Item_CodeSemiFinished Is Null
			And transferdt.Item_CodeFinished Is Null
			and transfer_id = ".$transfer_id;}
else {
$query = "select transferdt.Item_code Item_code, transferdt.Item_Barcode Item_Barcode, TransferDt_Quantity as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id
			,TransferDt_WarehouseTo ,items.Item_UnitSalesDesc from transferdt , items
			where items.item_code = transferdt.item_code
			and transfer_id = ".$transfer_id;
			}

$pquery = "select serialno_code from purchasesserialno ";
$result=mysql_query($query,$connection) or die(mysql_error());
echo "<tr><td align='left'>";


echo "<table border=0 width='250px' cellspacing=2 class='detail' style='table-layout:fixed;' >";			
 echo"
			  <col width=150>	  
			  <col width=50>	  
			  <col width=50>";
echo"<tr bgcolor=#D8D8D8><td ><b>Description</b></td><td ><b>Unit</b></td>";

if ($Module_TransferWithOneWh==0)
	{
		echo"<td width='10%' align=left><b>From Wh.</b></td>";					
		echo"<td width='10%' align=left><b>To Wh.</b></td>";				
		echo"<td width='10%' align=right><b>Quantity</b></td></tr>";			
	}
else	
		echo"<td width='50' align=right><b>Quantity</b></td></tr>";			

while($rows=mysql_fetch_array($result)){
extract($rows);
	$pquery = "select serialno_code from purchasesserialno where transferdt_id = ".$transferdt_id." and item_code = '".$Item_code."'";
	//echo $pquery;
	$presult=mysql_query($pquery,$connection) or die(mysql_error());
	echo"<tr><td colspan=3>$Item_description</td></tr>";
	echo"<tr>";
	if ($Module_TransferWithOneWh==0)
	{
	echo"<td align=left>$transferdt_warehousefrom</td>";			
	echo"<td align=left>$TransferDt_WarehouseTo</td>";			
	echo"<td align=right>$TransferDt_Quantity</td></tr>";			
	}
	else
	echo"<td  colspan=2 align=right>$Item_UnitSalesDesc</td><td colspan=1 align=right>$TransferDt_Quantity</td></tr>";			
	//$TransferDt_QtyUnit

		$num=mysql_num_rows($presult);
		if ($num!=0)
		{
			echo"<tr><td align=center valign=top colspan=2 ><b><u>SerialNo</u></b></td></tr>";
			echo"<tr><td colspan=2>";
			while($prows=mysql_fetch_array($presult)){
				echo"$prows[0]"." - ";
				}
			echo"&nbsp;</td></tr>";
		}
			echo"<tr height='10'><td colspan=5><hr></td></tr>";
	//	echo"<tr height='10'><td colspan=7><hr></td></tr>";
}

echo"</table></tD></tr>";
echo"</table>";

echo"</table>";

echo"</br>";
//echo"<tr><span style="text-decoration:overline">Overline</span></tr>";
echo"<table border=0 width='250' style='font-size:10px'  style='table-layout:fixed;' >";

echo"<tr><td align=left>________</td><td align=right>________</td></tr>";
echo"<tr><td align=left>Store Keeper</td><td align=right>Received By</td></tr>";
echo"</table>";
}
else
echo"Please Choose a Transfer";

function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}


print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>

