<?php





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

print <<< HERE
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE> Offer Report </TITLE>

<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: 13px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top:1px solid black;
				  border-bottom:1px solid black;
				  border-left:1px solid black;
                }				 
				 
table.detail td { font-size: 12px; 
                  font-family:Times-New-Roman;
				  border-left:1px solid black;
                 }			
h1.breakhere { page-break-after: auto;}				 
</style>
</HEAD>
<BODY>
HERE;

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$connection1 = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($config['dbName_log'],$connection1) 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);
}

//mysql_set_charset('utf8',$connection);

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






	


$querysetup ="select base1, base2 from ".$config['dbName_log'].".setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultsetup)){
	extract($rowmodule);
}


function formatdate($dateval){
	if($dateval != ''){
	$ndate = explode("-", $dateval);
	$dateval = $ndate[2]."-".$ndate[1]."-".$ndate[0];
}
	return $dateval;
}
$offer_id 			= $_POST["offer_id"]; 		    if ($offer_id == ""){			$offer_id 		     = $_GET["offer_id"];}  
$archive_offer	 	= $_POST["archive_offer"]; 	 	if ($archive_offer == ""){		$archive_offer 		 = $_GET["archive_offer"];} 
$archive_issue_date	= $_POST["archive_issue_date"]; if ($archive_issue_date == ""){	$archive_issue_date  = $_GET["archive_issue_date"];} 
$archive_expire_date= $_POST["archive_expire_date"];if ($archive_expire_date == ""){$archive_expire_date = $_GET["archive_expire_date"];} 
$archive_account	= $_POST["archive_account"]; 	if ($archive_account == ""){	$archive_account 	 = $_GET["archive_account"];} 
$archive_size1	 	= $_POST["archive_size1"]; 	 	if ($archive_size1 == ""){		$archive_size1 		 = $_GET["archive_size1"];} 
$archive_size2	 	= $_POST["archive_size2"]; 		if ($archive_size2 == ""){		$archive_size2 	 	 = $_GET["archive_size2"];} 
$archive_POL	 	= $_POST["archive_POL"]; 	 	if ($archive_POL == ""){		$archive_POL 	 	 = $_GET["archive_POL"];} 
$archive_POD	 	= $_POST["archive_POD"]; 	 	if ($archive_POD == ""){		$archive_POD 		 = $_GET["archive_POD"];} 
$archive_FOD	 	= $_POST["archive_FOD"]; 	 	if ($archive_FOD == ""){		$archive_FOD 		 = $_GET["archive_FOD"];} 
$archive_type	 	= $_POST["archive_type"]; 	 	if ($archive_type == ""){		$archive_type 		 = $_GET["archive_type"];} 
$confirmed	 	= $_POST["confirmed"]; 	 	if ($confirmed == ""){		$confirmed 		 = $_GET["confirmed"];} 
$fromdateo	 	= $_POST["fromdateo"]; 	 	if ($fromdateo == ""){		$fromdateo 		 = $_GET["fromdateo"];} 
$todateo	 	= $_POST["todateo"]; 	 	if ($todateo == ""){		$todateo 		 = $_GET["todateo"];} 
$checkdateissue	 	= $_POST["checkdateissue"]; 	 	if ($checkdateissue == ""){		$checkdateissue 		 = $_GET["checkdateissue"];} 
$checkdateexpire	 	= $_POST["checkdateexpire"]; 	 	if ($checkdateexpire == ""){		$checkdateexpire 		 = $_GET["checkdateexpire"];} 


	/*	
$archive_type 	  = "'".ereg_replace("'", "\'", trim($archive_type))."'";
$archive_FOD 	  = "'".ereg_replace("'", "\'", trim($archive_FOD))."'";
$archive_POD 	  = "'".ereg_replace("'", "\'", trim($archive_POD))."'";
$archive_POL 	  = "'".ereg_replace("'", "\'", trim($archive_POL))."'";
$archive_size2 	  = "'".ereg_replace("'", "\'", trim($archive_size2))."'";
$archive_size1 	  = "'".ereg_replace("'", "\'", trim($archive_size1))."'";
$archive_offer	  = "'".ereg_replace("'", "\'", trim($archive_offer))."'";
$archive_account  = "'".ereg_replace("'", "\'", trim($archive_account))."'";*/


$groupbylist	 	= $_POST["groupbylist"]; 	 	if ($groupbylist == ""){		$groupbylist 		 = $_GET["groupbylist"];} 
$querysearch = "select auto, Offer_code, Date_Format(issuedate,'%d/%m/%Y'), account, POL, POD, Date_Format(Expiredate,'%d/%m/%Y'), FOD, size1, size2, type,confirmed as offer_confirm from archivingoffer where 1=1 ";

	
	
	
	if($archive_offer != '') $querysearch = $querysearch." and ifnull(offer_code,'') like ('%".$archive_offer."%') ";
	if($archive_account != '') $querysearch = $querysearch." and ifnull(account,'') like ('%".$archive_account."%') ";
	if($archive_POL != '') $querysearch = $querysearch." and ifnull(POL,'') like ('%".$archive_POL."%') ";
	if($archive_POD != '') $querysearch = $querysearch." and ifnull(POD,'') like ('%".$archive_POD."%') ";
	if($archive_FOD != '') $querysearch = $querysearch." and ifnull(FOD,'') like ('%".$archive_FOD."%') ";
	if($archive_type != '') $querysearch = $querysearch." and ifnull(type,'') like ('%".$archive_type."%') ";
	if($archive_size1 != '') $querysearch = $querysearch." and ifnull(size1,'') like ('%".$archive_size1."%') ";
	if($archive_size2 != '') $querysearch = $querysearch." and ifnull(size2,'') like ('%".$archive_size2."%') ";
	
	if($checkdateissue == 1) 
		$querysearch = $querysearch." and ( issuedate between '$fromdateo' and '$todateo' ) ";
	 if($checkdateexpire == 1) 
		$querysearch = $querysearch." and ( expiredate between '$fromdateo' and '$todateo' ) ";
	 if($confirmed == 1) 
		$querysearch = $querysearch." and ( confirmed =1 ) ";
	 
	 if($groupbylist !='') 
	$querysearch = $querysearch." order by  $groupbylist,auto desc  ";
	else 
	$querysearch = $querysearch." order by  auto desc  ";
	

///////////////////////////////
 /*if($groupbylist !='') 
	$querysearch = $querysearch." order by  $groupbylist ";
*/
//////////////////////////////////

$style="style='border:1px solid black; text-align:right;'";
echo"<table border='0' width='1100px' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		<col width=200>
		<col width=300>
		<col width=300>";
		//T-header
/*echo"	<tr>
			<td align=' left' valign='top' style='font-size:14px; font-style:italic; font-weight:bold;' colspan=3>
			<table>
			<tr>
			<td rowspan=2><img src='LogoFile.php' ></td>
			<td style='vertical-align: top;'><br><span style='font-size: 20px; font-weight: bold'>$Company_Name</span><br>
			<span style='font-size: 11px;'><pre>".str_replace( '\n', '<br>', $Company_Memo)."</pre></span></td>
			</tr>
			
			</table>
			<td>
			
		<tr>";
		*/
		
		//2nd row
		
echo "	<tr>
			<td align='right' colspan='2' valign='top' style='font-size:20px; font-weight:bold;'>List of Offers<td>
			<td align='left' valign='top' style='font-size:14px; font-style:italic; font-weight:bold;'>
				<td colspan='2'><b>Printed Date:</b>";
			echo date("d/m/Y")."<br>";
				echo "<span><b>Time:</b></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".date("h:i:sa");
				echo "</td>
			<td>";
			
			
		//table header
		
echo "	</tr>

		<tr>
			<td>
			
					
			
				<table style=' border: 1px solid black;' width='1096'>
					<col width=80><col width=80><col width=350><col width=180>
					<col width=350><col width=180><col width=180><col width=200><col width=200><col width=200>
					<tr style='background-color:#d3d3d3'>
						<td>confirmed</td>
						<td  >Auto</td>
						
						<td align='center' >Offer Code</td>
						<td align='center' >Issue Date</td>
						<td align='center' >Account </td>
						<td  align='center'>POL</td>
						<td align='center' >POD</td>
						<td align='center' >Expire Date</td>
						<td  align='center'>FOD</td>
						
						
						<td  >Type</td>
						
						
					</tr>";
					


	//echo $staff_listquery;
			//	echo $carlist_query;
					$result=mysql_query($querysearch,$connection);
					$i=0;
					while($offer_result=mysql_fetch_array($result)){
		
	if($i%2) $bgcolor = "bgcolor = '#E6E6E6'";
		else $bgcolor = "bgcolor = '#F7F7F7'";
						
						echo "<tr style='background-color:white; border: 1px solid black;'>	
							
							
						</tr>
						
						<tr $bgcolor>
							
							<td  align='center'>";if ($offer_result[11]==1)
		echo "<img src='./img/confirmorder.png' height='20' width='20' ></span></td>";
	else echo "<img src='./img/unconfirmorder.png' height='20' width='20' ></span></td>";
							echo "<td  align='center'>$offer_result[0]</td>
							<td align='center'>$offer_result[1]</td>
							<td align='center'>$offer_result[2]</td>"
							;
							echo "	
							<td align='center'>$offer_result[3]</td>
							<td align='center'>$offer_result[4]</td>
							<td align='center' >$offer_result[5]</td>
							<td align='center'>$offer_result[6]</td>
							<td align='center'>$offer_result[7]</td>
							
							<td align='center'>$offer_result[10]</td>
					";
							
						echo  "</tr>
						
						<tr style='background-color:white; border: 1px solid black;'>
							
						</tr><h1 CLASS='breakhere'>";
						$i++;
					}
					
echo "			</table>
			</td>
		</tr>
	</table>";
print <<< HERE

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