<?php

header("Content-type: text/html; charset=windows-1256");
session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

print <<< HERE

<HTML>
<HEAD>
<TITLE> Category List </TITLE>

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top: 2 solid #000000;
				  border-bottom: 1 solid #000000;
				 }
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
				 
table.master td.reportfooter { font-size: 14px; 
							   font-weight: bold;
							   font-family:Times-New-Roman;
							   border-top: 1 solid #000000;
							  }
</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");

				
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, report_color1, report_color2, grid_color1, grid_color2, ".
             " 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);
}
	//User Access
$querylog=" select ifNull(login_belongstogrp,0) As FI_BelongsToGrp from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

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




	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='650' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=130>
		  <col width=190>
		  <col width=55>
		  <col width=55>
		  <col width=55>
		  <col width=55>
		  <col width=55>
		  <col width=55>";    
	

	echo "<tr><td height='60'><img src='img/imgheader1.jpg' width='115' height='50' /></td><td align='center'><b><font size=5>Category List</font></td><td colspan = '6'align='right' ><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>";
	

	echo "<tr >";
	echo "  <th align='left' >Code</th>";
	echo "  <th align='left' >Name</th>";
	echo "  <th align='left' >I</th>";
	echo "  <th align='left' >II</th>";
	echo "  <th align='left' >III</th>";
	echo "  <th align='left' >IV</th>";
	echo "  <th align='left' >V</th>";
	echo "  <th align='left' >VI</th>";
	echo "</tr>";
	


	$query = "select Category_Code, Category_name, Category_Price1, Category_Price2, Category_Price3 , Category_Price4,".
             "Category_Price5, Category_Price6 from  Category
			 where ifNull(Category_BelongsToGroup,0) >= ifNull($FI_BelongsToGrp,0) order by Category_code";


	$result= mysql_query($query, $connection);
	$totalrows= mysql_num_rows($result);
	
	$col=0;
    while($row=mysql_fetch_array($result)){
		
		if($col%2==0){
			$color = "style='background-color:".$report_color1."'";
		}else{
			$color = "style='background-color:".$report_color2."'";
		}
		
		$Category_Code=$row[0];
		$Category_name=$row[1];
		$Category_Price1=$row[2];
		$Category_Price2=$row[3];
		$Category_Price3=$row[4];
		$Category_Price4=$row[5];
		$Category_Price5=$row[6];
		$Category_Price6=$row[7];
		
		
		echo "<tr $color>";
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>$Category_Code &nbsp;</td>";
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>$Category_name &nbsp;</td>";
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>&nbsp;";
		if ($Category_Price1 != '')
			echo"$Category_Price1% &nbsp;";
		
		echo"</td>";

		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>&nbsp;";
		if ($Category_Price2 != '')
		    echo "$Category_Price2% &nbsp;";
		echo "</td>";
		
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>&nbsp;";
		if ($Category_Price3 != '')
		     echo"$Category_Price3% ";
		echo "</td>";
		
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>&nbsp;";
		if ($Category_Price4 != '')
		    echo"$Category_Price4% &nbsp;";
		echo"</td>";
		
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>&nbsp;";
		if ($Category_Price5 != '')
		    echo "$Category_Price5% &nbsp;";
		echo"</td>";
		
		echo "  <td align='left' style='border-right:1px solid black; padding-left:2px;'>&nbsp;";
		if ($Category_Price6 != '')
		    echo "$Category_Price6% &nbsp;";
		echo"</td>";
		
		echo "</tr>";
		$col+=1;
	}
	

echo "<tr height='35'><td colspan='8' class='reportfooter'>Total Records: $totalrows </td></tr>";	
echo "</table></table>";
	
	

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


				 
				  
				  