<?php


session_start();
if($_SESSION['dbName']==""){
header("location:../index.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: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
				 
table.detail td { font-size: 12px; 
                  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: 14px; 
                         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: 14px; 
                          font-family:Times-New-Roman;
						  border-width: 1px;
						  border-style: none none solid none;
  						  border-color: #666666;
				        }
table.totals td.totalborder {
								font-size: 14px; 
								font-family:Times-New-Roman;
								border-width: 1px;
								border-style: none solid solid none;
								border-color: #666666;
							}						
				 
h4 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 1px;
   }
   
   
</style>


</HEAD>

<BODY>
HERE;

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


//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Company_memo As CompanyMemo, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

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

$TotalQty = 0;

if($transfer_id != '')
{
	$query = " select Transfer_Id,Transfer_Reference,date_format(Transfer_Date,'%d/%m/%Y') as Transfer_Date,transfer_warehouseto,Warehouse_name,Driver_Name,Vehicle_No,
			concat(Project_Code1,' - ',p1.Project_Name) as fromproject,concat(Project_Code2,' - ',p2.Project_Name) as toproject,
			concat(Costcenter_Code,' - ',c1.Costcent_name) as fromcostcent,concat(ToCostcenter_Code,' - ',c2.Costcent_name) as tocostcent,Transfer_Remark	
			from transfer
			left join warehouse on Warehouse_code = transfer_warehouseto
			left join project p1 on p1.Project_Code = Project_Code1
			left join project p2 on p2.Project_Code = Project_Code2
			left join costcent c1 on c1.Costcent_code = Costcenter_Code
			left join costcent c2 on c2.Costcent_code = ToCostcenter_Code
			where Transfer_Id = $transfer_id";
//echo $query;			 
			 
	$result=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result)){
		extract($rows);
	}
	
	

	
	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='840' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=150>
		  <col width=270>
		  <col width=270>
		  <col width=150>";
	echo "<tr><td height='60'><img src='LogoFile.php' width='115' height='50' /></td>
	<td align='center' colspan=2><b><font size=5>Transfer</font></td><td align='right'  ><font size='2'><b>Printed Date: </b>";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br><b>Time: </b>".$dt[1]." ".$dt[2];
	echo "</font></td></tr></table>";
	
	echo "<table border=0 width='840' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=120>
		  <col width=300>
		  <col width=120>
		  <col width=300>";

    //echo "<tr height='10'><td colspan=4><hr></td></tr>";
	echo "<tr height='5'><td colspan=4><h4></td></tr>";
	echo "<tr height='25'>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Reference</th>";
	echo "  <td align='left'>$Transfer_Reference</td>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Date</th>";
	echo "  <td align='left'>$Transfer_Date</td>";
	echo "</tr>";
	
	echo "<tr height='25'>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Warehouse</th>";
	echo "  <td align='left' >$transfer_warehouseto $Warehouse_name</td>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Transfer Date</th>";
	echo "  <td align='left' >$Transfer_Date</td>";
	echo "</tr>";
	
	
	
	echo "<tr height='25'>";
	echo "  <th align='left' bgcolor='#D8D8D8'>From Project</th>";
	echo "  <td align='left' >$fromproject</td>";
	echo "  <th align='left' bgcolor='#D8D8D8'>To Project</th>";
	echo "  <td align='left' >$toproject</td>";
	echo "</tr>";


	echo "<tr height='25'>";
	echo "  <th align='left' bgcolor='#D8D8D8'>From Cost Center</th>";
	echo "  <td align='left' >$fromcostcent</td>";
	
	echo "  <th align='left' bgcolor='#D8D8D8'>To Cost Center</th>";
	echo "  <td align='left' '>$tocostcent</td>";
	echo "</tr>";
	
	echo "<tr height='25'>";
	echo "  <th align='left' valign='top' bgcolor='#D8D8D8'>Driver Name</th>";
	echo "  <td align='left' >$Driver_Name</td>";
	
	echo "  <th align='left' valign='top' bgcolor='#D8D8D8'>Vehicle No</th>";
	echo "  <td align='left' valign='top' >$Vehicle_No</td>";
	echo "</tr>";
	
	echo "<tr height='25'>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Remark</th>";
	echo "  <td align='left' colspan='3'>$Transfer_Remark</td>";
	echo "</tr>";
	
	
	
	
	//echo "<tr height='10'><td colspan=4><hr></td></tr>";
	echo "<tr height='5'><td colspan=4><h4></td></tr>";
	echo "</table></td></tr>";

	
	
		$querydt = " select transferdt.Item_code as ItemCode, Item_Description, TransferDt_Quantity,TransferDt_WarehouseTo,Item_UnitSalesDesc,TRANSFERDT_REMARK
					from transferdt
					left join items on items.item_code = transferdt.Item_code
					where transfer_id=$transfer_id";
	
			   

	//echo $querydt;
	echo "<tr><td align='left'>";
	echo "<table border=0 width='840' cellspacing=2 class='detail' style='table-layout:fixed;' >
		  <col width=200>
		  <col width=250>
		  <col width=150>
		  <col width=120>
		  <col width=120>";
	echo "<tr bgcolor=#D8D8D8>";
	
	
		echo "   <th align='left'>Code</th>";
		echo "   <th align='left'>Description</th>";
		echo "	 <th align='center' >Warehouse</th>";
		echo "	 <th align='center'>Qty.</th>";
		echo "	 <th align='center'>Unit</th>";
	
	
	echo "</tr>";			
		  
	//echo "<tr height='10'><td colspan=7><hr></td></tr>";
	echo "<tr height='5'><td colspan=7><h4></td></tr>";
	$totQty = 0;
	$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultdt)){
		extract($rows);
		
			$totQty = $TransferDt_Quantity + $totQty;
			echo "<tr>";
			echo "  <td align='left' valign='top'>$ItemCode</td>";
			echo "  <td align='left' valign='top'>$Item_Description</td>";
			echo "  <td align='left' valign='top' >$transfer_warehouseto</td>";
			echo "	<td align='right' valign='top'>$TransferDt_Quantity</td>";
					
			echo "</tr>";
		

		if ($TRANSFERDT_REMARK != '') {
			echo "<tr>";
			echo "  <td align='left' valign='top'>&nbsp;</td>";
			echo "  <td align='left' valign='top' colspan='4'>$TRANSFERDT_REMARK</td>";
			echo "</tr>";

		}	
		
		
	}
	
	echo "<tr height='5'><td colspan=7><h4></td></tr>";
	
	
		echo "<tr>";
		echo "   <td align='left' colspan='2'>&nbsp;</td>";
		echo "	 <th align='right'  class='labels'>Total Qty.</th>";
		echo "	 <th align='right' class='amounts'>$totQty</th>";
		echo "</tr>";	
	
	
	echo "</table></td></tr>";
	
	
		
	echo "<tr><td align='left'>";
	echo "<table border=0 width='840' cellspacing=0 cellpadding=1  class='master' style='table-layout:fixed;' >
		  <col width=840>
		 ";
	
	echo "<tr height='100'>";
	echo "  <td align='left' >&nbsp;</td>";
	echo "</tr>";	
	
	echo "<tr height='5'><td ><h4></td></tr>";
	
	echo "<tr>";
	echo "  <td align='center'  valign='top'></td>";
	echo "</tr>";	
	echo "</table></td></tr>";
	
	echo "</table>";
	echo "<br>";
	

}


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

function format_currency($amount, $DecimalBase) { 

    if($amount < 0) 
        return "(".number_format(abs($amount),$DecimalBase).")"; 
 
    else return number_format($amount, $DecimalBase); 
} 

print <<< HERE

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

