<?php


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

print <<< HERE
<HTML>
<HEAD>
<TITLE> Stock 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;
   }
   
h3 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 2px;
	 width: 150px;
   }   
   
   
</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($HTTP_SESSION_VARS['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, ".
             " Company_Name As CompanyName from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}



//Read From Module Table
$querymodule=" Select ifNull(Module_ShowLayoutProj,0) As Module_ShowLayoutProj, ifNull(Module_ShowLayoutCost,0) As Module_ShowLayoutCost 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]);

$TotalQty = 0;

if($AdjustmentRequestId != '')
{
	$query = " Select AdjustmentRequest_ID, AdjustmentRequest_Reference, Date_Format(AdjustmentRequest_Date,'%d/%m/%Y') As AdjustmentRequestDate, ".
	         " AdjustmentRequest.Currency_Code As CurrencyCode, AdjustmentRequest_Remak, AdjustmentRequest_Type, AdjustmentRequest_EntryType As AdjustType, ".
			 " AdjustmentRequest.Project_Code As ProjectCode, Project_Name, ".
             " AdjustmentRequest.Costcent_code As Costcentcode, Costcent_name,  ".
			 " Round(AdjustmentRequest_Amount, ".$DecimalBase.") As AdjustmentRequestAmount, ".
			 " Round(AdjustmentRequest_AmountBase1, ".$DecimalBase1.") As AdjustmentRequestAmountBase1, ".
			 " Round(AdjustmentRequest_AmountBase2, ".$DecimalBase2.") As AdjustmentRequestAmountBase2 ".
			 " From AdjustmentRequest ".
			 " Left Join Project on AdjustmentRequest.Project_Code = Project.Project_Code ".
			 " Left Join CostCent on AdjustmentRequest.Costcent_code = CostCent.CostCent_Code ".
	         " Where AdjustmentRequest_ID = ".$AdjustmentRequestId;
			 
			 
	$result=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result)){
		extract($rows);
	}
	
	
	//Read From Project Table
	$queryProject="Select Project_Memo As ProjectMemo From Project Where Project_Code = '".$ProjectCode."'";
	$resultProject=mysql_query($queryProject,$connection) or die(mysql_error());
	while($rowProject=mysql_fetch_array($resultProject)){
		extract($rowProject);
	}
	
	$AdjustType ='O';	
	if ($AdjustType == 'O')      { $FormTitle = 'STOCK OUT REQUEST';  }
	else if ($AdjustType == 'I') { $FormTitle = 'STOCK IN REQUEST';   }
	else if ($AdjustType == 'A') { $FormTitle = 'ADJUSTMENT REQUEST'; } 
	
	
	
	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='635' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=165>
		  <col width=270>
		  <col width=95>
		  <col width=110>";
		  //<img src='img/imgheader1.jpg' width='115' height='50' />
	echo "<tr><td height='60'><img src='LogoFile.php' width='115' height='50' /></td>
	          <td align='center'><b><font size=5>$FormTitle</font></td><td align='right' colspan=2 ><font size='2'><b>Printed&nbsp;Date&nbsp;&amp;&nbsp;Time:</b>&nbsp;&nbsp;";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br>".$dt[1]." ".$dt[2];
	echo "</font></td></tr></table>";
	
	echo "<table border=0 width='635' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=110>
		  <col width=340>
		  <col width=90>
		  <col width=100>";

    //echo "<tr height='10'><td colspan=4><hr></td></tr>";
	echo "<tr height='5'><td colspan=4><h4></td></tr>";
	echo "<tr>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Reference</th>";
	echo "  <td align='left'>$AdjustmentRequest_Reference</td>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Date</th>";
	echo "  <td align='left'>$AdjustmentRequestDate</td>";
	echo "</tr>";
	
	
	echo "<tr>";
	echo "  <th align='left' bgcolor='#D8D8D8'>Remark</th>";
	echo "  <td align='left' >$AdjustmentRequest_Remak</td>";
	echo "  <th align='left' ></th>";
	//echo "  <td align='left'>$CurrencyCode</td>";
	echo "</tr>";
	
	
		
	if ($Module_ShowLayoutProj	== 1) {
		echo "<tr>";
		echo "  <th align='left' bgcolor='#D8D8D8'>Project</th>";
		echo "  <td align='left' >$ProjectCode&nbsp;-&nbsp;$Project_Name</td>";
		echo "  <td align='left' colspan='2'>&nbsp</td>";
		echo "</tr>";
	} 
	

	if ($Module_ShowLayoutCost == 1) {	
		echo "<tr>";
		echo "  <th align='left' bgcolor='#D8D8D8'>Cost Center</th>";
		echo "  <td align='left' >$Costcentcode&nbsp;&nbsp;$Costcent_name</td>";
		echo "  <td align='left' colspan='2'>&nbsp</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 AdjustmentRequestDt.AdjustmentRequestDt_ID As AdjustmentRequestDtID, AdjustmentRequestDt.Item_CodePacked, AdjustmentRequestDt.Item_code As ItemCode, ".
			   " Item_Description As ItemDescription, AdjustmentRequestDt.Warehouse_Code As WarehouseCode, AdjustmentRequestDt_Quantity, ".
			   " Round(AdjustmentRequestDt_Price, ".$DecimalBase.") As AdjustmentRequestDtPrice, AdjustmentRequestDt_PriceBase1, AdjustmentRequestDt_PriceBase2, ".
			   " Round((ifNull(AdjustmentRequestDt_Quantity,0)*ifNull(AdjustmentRequestDt_Price,0)), ".$DecimalBase.") As TotalAmount, AdjustmentRequestDt.Journal_Type As JournalType ".
			   " ,date_format(AdjustmentRequestDt_ExpireDate,'%d/%m/%Y') as AdjustmentRequestDt_ExpireDate From AdjustmentRequestDt ".
			   " Left Join Items on AdjustmentRequestDt.Item_code = Items.Item_code ".
			   " Where AdjustmentRequestDt.AdjustmentRequest_ID = ".$AdjustmentRequestId;
					   
	
	//echo $querydt;
	echo "<tr><td align='left'>";
	echo "<table border=0 width='635' cellspacing=2 class='detail' style='table-layout:fixed;' >
		  <col width=90>
		  <col width=250>
		  <col width=85>
		  <col width=55>
		  <col width=85>";
	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'>Expire Date</th>";
		
	echo "</tr>";			
		  
	//echo "<tr height='10'><td colspan=6><hr></td></tr>";
	echo "<tr height='5'><td colspan=6><h4></td></tr>";
	
	$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultdt)){
		extract($rows);
		
		$TotalQty = $TotalQty + $AdjustmentRequestDt_Quantity;
		
		echo "<tr>";
		echo "  <td align='left' valign='top'>$ItemCode</td>";
		echo "  <td align='left' valign='top'>$ItemDescription</td>";
		echo "  <td align='left' valign='top'>$WarehouseCode</td>";
		echo "	<td align='right' valign='top'>$AdjustmentRequestDt_Quantity</td>";
		echo "	<td align='right' valign='top'>".$AdjustmentRequestDt_ExpireDate."</td>";
		echo "</tr>";
		

		
		
		
		//echo "<tr height='10'><td colspan=6><hr></td></tr>";
	}
	
	//echo "<tr height='10'><td colspan=6><hr></td></tr>";
	echo "<tr height='5'><td colspan=6><h4></td></tr>";
	
	echo "<tr>";
	echo "   <td align='left' colspan='2'>&nbsp;</td>";
	echo "	 <th align='left' class='labels'>Total Qty.</th>";
	echo "	 <th align='right' class='amounts'>$TotalQty</th>";
	echo "   <td align='left' colspan='2'>&nbsp;</td>";
	echo "</tr>";
	
	echo "</table></td></tr>";
	
	
	//$queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$CurrencyCode."', ".abs($AdjustmentAmount).") As AlphaAmount FROM Dual ";
	//$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
	//$rowalpha=mysql_fetch_array($resultalpha);
		
	//echo "<tr height='30'><td colspan=6 valign='top' style='font-size:12px; font-family:Times-New-Roman;'>".$rowalpha[0]."</td></tr>";
		
	echo "<tr><td align='left'>";
	echo "<table border=0 width='635' cellspacing=0 cellpadding=1  class='totals' style='table-layout:fixed;' >
		  <col width=400>
		  <col width=130>
		  <col width=100>
		  <col width=20>";
		  
	echo "<tr height='20'><td colspan=4>&nbsp;</td></tr>";
	
		
		
	echo "</table></td></tr>";
		
	
	
	
	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;
?>

