<?php

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

include("config.inc.php");
include("function.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");



if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

//Read From Setup Table							
$querysetup= " select base1,company_name, company_memo, RemarkInv,DecimalBase, COMPANY_CITY,Setup_VatPercentage, setup_invoiceremarks, Setup_VatNo,company_phone2,company_phone3,COMPANY_FAX ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

if($sellingprice_nbr == '') $sellingprice_nbr = 0;
$sellingprice_label = array('Price','Price Local', 'Price Export', 'Price 3', 'Price 4', 'Price 5');		
print <<<HERE

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<title>Selling Price Preview</title>
</head>
<body >
<style>
.style1 {
	font-size: 14px;
}
</style>
HERE;

echo "<table cellpadding=0 cellspacing=0 width=100%>
		<col width=25%>
		<col width=30%>
		<col width=15%>
		<col width=15%>
		<col width=15%>";
echo "<thead>";		
echo "<tr height='30px'><th colspan='5' align='left' valign='top' style='font-size:22px;font-weight:bold;'>".nl2br($company_name)."</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'>$COMPANY_CITY</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'>$company_memo</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'>$company_phone2</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'>$company_phone3</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'>$COMPANY_FAX</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'>$Setup_VatNo</th></tr>";
echo "<tr height='15px'><th colspan='5' align='left' style='font-size:12px;font-weight:bold;'></th></tr>";


echo "<tr height='30px' style='background-color:darkgray;'>
		<th align='left'><span class='style1'><b>Item Code</b></th>
		<th align='left'><span class='style1'><b>Item Description</b></th>
		<th align='left'><span class='style1'><b>Date</b></th>
		<th align='center'><span class='style1'><b>Currency</b></th>
		<th align='center'><span class='style1'><b>".$sellingprice_label[$sellingprice_nbr]."</b></th>
	</tr>";
echo "</thead>";
echo "<tbody>";		
$queryload = "select d.Item_Code, Item_Description, date_format(creationDate,'%d-%m-%Y'), d.currency_code, SellingPrice$sellingprice_nbr
			from sellingprice_adjustdt as d
			inner join sellingprice_adjust on sellingprice_adjust.sellingprice_id = d.sellingprice_id
			inner join items on items.item_code = d.item_code
			left join grouping on grouping.group_code = items.group_code
			left join subgroup on subgroup.subgroup_code = items.subgroup_code
			left join category on category.category_code = items.category_code
			where ifnull(sale_group,0) = 1 and if('$group_code'='',1=1, items.group_code = '$group_code')
			and if('$subgroup_code'='',1=1, items.subgroup_code = '$subgroup_code') and if('$category_code'='',1=1, items.category_code = '$category_code')
			and ifnull(SellingPrice$sellingprice_nbr,0) != 0
			order by d.item_code, creationDate "; 	
$ct = 0;
$tempcode = '**';		
$resload = mysql_query($queryload,$connection);
while($rowload = mysql_fetch_array($resload)){	
	if(($ct++)%2) $bgcolor = "background-color:#D8D8D8";
	else  $bgcolor = "";
	
	echo "<tr height='18px' style='$bgcolor;'>";
	if($tempcode != $rowload[0])
		echo "<td align='left'><span class='style1'><b>$rowload[0]</b></td>
			<td align='left'><span class='style1'><b>$rowload[1]</b></td>";
	else echo "<td align='left'></td>
			<td align='left'></td>";		
	
	echo "	<td align='center'><span class='style1'><b>$rowload[2]</b></td>
			<td align='center'><span class='style1'><b>$rowload[3]</b></td>
			<td align='center'><span class='style1'><b>$rowload[4]</b></td>
		</tr>";
	$tempcode = $rowload[0];
}	
echo "</tbody>";	
echo "</table>";	
print <<< HERE

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


