<?php


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

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


if($exp==1)
{
		$filename = "Group_Report.xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
}





	                $today = date('d/m/Y');
	                $Group_CreationDate = $today;
					
             


?> 


<html>
        <head><title>Grouping Transaction</title></head>
		<body>
		<td>
		 <img src="img/imgheader1.jpg"   width="450" height="80">
		 <br>
		 <?php
		 echo $Group_CreationDate;
		 ?>
		</td>
         <div class="container">
		    <div class="wrapper">
			    <h1  align="center">Group Transaction </h1>
			     
				 			 
			    
			
				 <?php
				 $query = "select Auto, Journal_type, Trans_RMAcc, Trans_RMVatAcc, Trans_NonRMAcc, Trans_NonRMVatAcc, Trans_RMTTCIncAcc, Trans_NonRMTTCIncAcc, Trans_Currency,
						 Trans_DefaultCur, Trans_DirectStkDbt, Trans_DirectStkCrd, Trans_DirectStkCur, transactionsetup.Group_code as group_code, transactionsetup.Synchronized, CEP_CreditAcc, Trans_wasteDebitAcc,
						  Trans_wasteCreditAcc, Trans_wasteDifferenceAcc, Trans_DiscountAcc, Trans_PromotionAcc, IsoDescription, Trans_VATAccount, trans_Purchasepromotionacc,
						  trans_Purchasediscountacc, Trans_TipsAcc, group_name
						  from transactionsetup
						inner join grouping on grouping.group_code = transactionsetup.group_code where  1=1";
				 if($group_code != ""){
					 $query = $query." and transactionsetup.group_code = '$group_code'";
					 }
				  
				 if($grouping != ""){
					 $query = $query." and Journal_type = '".$grouping."'";
				 }
				 $query = $query." order by group_name, group_code";
				/*
				 if($valueToSearch != '') $query = $query." and (group_name like '%".$valueToSearch."%' or transactionsetup.group_code like '%".$valueToSearch."%' or 
  				 Journal_type like '%".$valueToSearch."%' or Trans_RMAcc like '%".$valueToSearch."%' or Trans_RMVatAcc like '%".$valueToSearch."%' or 
                 Trans_NonRMVatAcc like '%".$valueToSearch."%'	or Trans_RMTTCIncAcc like '%".$valueToSearch."%'  or Trans_NonRMTTCIncAcc like '%".$valueToSearch."%' or 
                 Trans_Currency like '%".$valueToSearch."%' or Trans_DefaultCur like '%".$valueToSearch."%'   or Trans_DirectStkDbt like '%".$valueToSearch."%' or 
                 Trans_DirectStkCrd like '%".$valueToSearch."%' or Trans_DirectStkCur like '%".$valueToSearch."%' or CEP_CreditAcc like '%".$valueToSearch."%' or 
                 Trans_wasteDebitAcc like '%".$valueToSearch."%'  or Trans_wasteCreditAcc like '%".$valueToSearch."%' or Trans_wasteDifferenceAcc like '%".$valueToSearch."%' or 
                 Trans_DiscountAcc like '%".$valueToSearch."%' or Trans_PromotionAcc like '%".$valueToSearch."%' or IsoDescription like '%".$valueToSearch."%' or 
                 Trans_VATAccount like '%".$valueToSearch."%' or trans_Purchasepromotionacc like '%".$valueToSearch."%' or trans_Purchasediscountacc like '%".$valueToSearch."%' or
                 Trans_TipsAcc like '%".$valueToSearch."%')";
				 */
				 $result = mysql_query ($query,$connection);
				// echo $query;
				  
				  while($row = mysql_fetch_array($result))
				  {
					  extract($row);
					  echo "<table border='1'>
					  <tr>
					  <td width='25%'>Type</td>
					  <td width='25%'>".$Journal_type."</td>
					  <td width='25%'>Group</td><br/>
					  <td width='25%'>".$group_code."</td>
					   </tr>
					   <tr>
					  <td width='25%'>Vat Account</td>
					  <td width='25%'>".$Trans_VATAccount."</td>
					     <tr>
					       <td width='25%'>Currency</td>
					       <td width='25%'>".$Trans_Currency."</td>
					     </tr>
					   </tr>
					   <tr>
					   <td width='25%'>Raw Material</td>
					  <td width='25%'>".$Trans_RMAcc."</td>
					  <td width='25%'>Non Raw Material</td>
					  <td width='25%'>".$Trans_NonRMVatAcc."</td>
					   <tr>
					    <td width='25%'>Raw Mat. TTC Inc.</td>
					    <td width='25%'>".$Trans_RMTTCIncAcc."</td>
						 <td width='25%'>Non R.M. TTC Inc.</td>
					     <td width='25%'>".$Trans_NonRMTTCIncAcc."</td>
					   </tr>
					  
					   <tr>
					  <td width='25%'>Raw Material</td>
					  <td width='25%'>".$Trans_RMVatAcc."</td>
					  <td width='25%'>Non Raw Material</td>
					  <td width='25%'>".$Trans_NonRMVatAcc."</td>
					   </tr>
					   <tr>
					    <tr>
						    <td width='25%'>Currency</td>
					        <td width='25%'>".$Trans_Currency."</td>
					     </tr>
					  <td width='25%'>Debit Account</td>
					  <td width='25%'>".$Trans_DirectStkDbt."</td>
					  <td width='25%'>Credit Account</td>
					  <td width='25%'>".$Trans_DirectStkCrd."</td>
					   </tr>
					  </table>";
					  
					  
					  echo "<br><br>";
				  }
				
				
				
				
			    echo "
			</div>
	      </div>
	 </body>
</html>";
?>