<img src="img/imgheader1.jpg" width="300" height="110" />
<?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");


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

$INS="insert into test(id) values(2)";
	$result2=mysql_query($INS,$connection) or die(mysql_error());
	
	$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);

if($transfer_id!='')
{
$query = "SELECT TRANSFER_REFERENCE , transfer.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
			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 width=100%><tr><td align='left'>";
echo"<table border=0 width='100%' cellspacing=10>";
echo"<tr><td colspan=0 align='left'><b><font size=5><u>Transfer # $TRANSFER_REFERENCE</u></font></td><td colspan=6 align='right' height='38' ><font size='2'><b>Printed&nbsp;Date&nbsp;&amp;&nbsp;Time:</b>&nbsp;&nbsp;";
				echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
				//echo DATE("d"."/"."m"."/"."Y");
				echo "<br>".$dt[1]." ".$dt[2];
				echo"</font></td></tr>";
echo"<tr height='10'><td colspan=7><hr></td></tr>";
//echo"<tr height=25><td colspan=6 align=center>&nbsp;</td></tr>";
echo"<tr><td bgcolor=#f8f8f8><b>Date</td><td>$TRANSFER_DATE</td><td></td><td bgcolor=#f8f8f8><b>Project</td><td bgcolor=#f8f8f8><b>Warehouse</td>";

echo"<tr><td bgcolor=#f8f8f8><b>Driver Name</td><td>$Driver_Name</td><td bgcolor=#f8f8f8><b>From</td><td>$Project_code1</td><td>$Transfer_WarehouseFrom</td></tr>";
echo"<tr><td bgcolor=#f8f8f8><b>Vehicle No</td><td>$Vehicle_No</td><td bgcolor=#f8f8f8><b>To</td><td>$Project_code2</td><td>$Transfer_WarehouseTo</td></tr>";
//echo"<tr><td bgcolor=#f8f8f8><b>Driver Name</td><td>$Driver_Name</td><td bgcolor=#f8f8f8><b>Vehicle No</td><td>$Vehicle_No</td>";
//echo"<tr><td bgcolor=#f8f8f8><b>Vehicle No</td><td>$Vehicle_No</td>";
echo"<tr><td bgcolor=#f8f8f8><b>Remark</td><td colspan=4>$Transfer_Remark</td>";
echo"</table></td></tr>";

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

$query = "select transferdt.Item_code Item_code, transferdt.Item_Barcode Item_Barcode, TransferDt_Quantity , TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id
			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"<table border=0 width='100%' cellspacing=5>";				
echo"<tr bgcolor=#F8F8F8><td width='10%'><b>Code</b></td><td width='35%'><b>Description</b></td><td width='10%' align=right><b>Quantity</b></td></tr>";			
echo"<tr height='10'><td colspan=7><hr></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>$Item_code</td><td>$Item_description</td><td align=right>$TransferDt_Quantity</td></tr>";			
	echo"<tr height='10'><td colspan=7><hr></td></tr>";
		$num=mysql_num_rows($presult);
		if ($num!=0)
		{
			echo"<tr><td align=center valign=top><b><font size='2'><u>SerialNo</u></b></td><td colspan=10 ><font size='1'>";
			while($prows=mysql_fetch_array($presult)){
				echo"$prows[0]"." - ";
				}
			echo"</td></tr>";
		}
		echo"<tr height='10'><td colspan=7><hr></td></tr>";
}

echo"</table>";

echo"</table>";
echo"</br>";
echo"</br>";
echo"</br>";
echo"</br>";
echo"<tr height='10'><td colspan=7><hr></td></tr>";
echo"</br>";
echo"</br>";
//echo"<tr><span style="text-decoration:overline">Overline</span></tr>";
echo"<table border=0 width='100%'>";
echo"<tr><td align=left>____________</td><td align=center>________________</td><td align=right>___________</td></tr>";
echo"<tr><td align=left>Store Keeper</td><td align=center>Driver Signature</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;
?>

