<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
			include ('../scripts/classes.php');
			if ($_SESSION['lang']=="EN"){include ('../lang/en.php');}elseif ($_SESSION['lang']=="GR"){include ('../lang/gr.php');}else{include ('../lang/en.php');}
			$mode = $lbl_transaction_entry;
			$page_title =$lbl_cls_transaction_entry ; //Assign Page Title
			$array = getGlobalSettings();
			foreach ($array as $settings){extract($settings);}
			
	if ($_SERVER['REQUEST_METHOD'] != 'GET') exit;
	$transaction_id = $_GET['transaction_id'];				
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../img/favicon.png" />
<link href="../cms1.css" rel="stylesheet" type="text/css" />

</head>
<body>
<script>top.document.title=self.document.title;</script>
		<div>
		<fieldset style="min-height:200px">
		<legend><?php echo  $mode ?></legend>
		<br />
		<div class="success">
			<ul>
				<li> 
					<?php echo $transaction_id; ?> 
					<?php echo $lbl_found_match; ?>
				</li>
			</ul>		
		</div>
		<div class="warning">
			<ul>
				<li> 

				<?php //Calculate header amounts
				$matchALL = "SELECT SUM(amount) AS sum_amount, SUM(credits) AS sum_credits FROM cls_transactions WHERE transaction_id='$transaction_id'";
				$resultALL = mysqli_query($mysqli, $matchALL) or die("Query failed : " . mysqli_error($mysqli));
				if (mysqli_num_rows($resultALL) == 0){
					echo "System Error! 005";
					exit();
				}else {
					while ($rowALL = mysqli_fetch_array($resultALL, MYSQLI_ASSOC)) {
					$creds=$rowALL['sum_credits'];
					$tot_amount=$rowALL['sum_amount'];
				echo "<div style='float:left;font-size:20px;padding-top:5px'>$lbl_last_trans_amount</div>
					<div style='float:left;font-size:20px;padding-top:5px;color:#FF0000'>$tot_amount&euro;</div>
					<div style='float:left;font-size:20px;padding-top:5px'>&nbsp;$lbl_credits</div>
					<div style='float:left;font-size:20px;padding-top:5px;color:#FF0000'>$creds</div>
					";
					}
				}	
				?>
				</li>
			</ul>		
			</div>		
		<div style="padding-top:20px;">
	<?php
	//Last Transaction Match Query
	$match = "SELECT * FROM cls_transactions WHERE transaction_id='$transaction_id'";
	$result = mysqli_query($mysqli, $match) or die("Query failed : " . mysqli_error($mysqli));
	if (mysqli_num_rows($result) == 0){
		echo "System Error! 006";
	$str = implode("\n", $errors);
	die("Search error:\n\n" . $str);
	exit();
		}
		else {
			echo "<table align='left' cellpadding='1' cellspacing='1' border='0' class='default_dg_table'>
					<tr><td class='manual_table_td'>$lbl_grid_barcode</td>
						<td class='manual_table_td'>$lbl_grid_transaction_type</td>
						<td class='manual_table_td'>$lbl_grid_cat_group</td>
						<td class='manual_table_td'>$lbl_grid_amount</td>
						<td class='manual_table_td'>$lbl_grid_credits</td>
						<td class='manual_table_td'>$lbl_transaction_entry</td>
						<td class='manual_table_td'>$lbl_grid_created_on</td>
						<td class='manual_table_td'>$lbl_grid_created_by</td>
					<tr>";
				while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
					echo "<tr><td class='manual_table_td_d'>".$row['barcode_id']."</td>
						<td class='manual_table_td_d'>".$row['transaction_type']."</td>
						<td class='manual_table_td_d'>".$row['category']."</td>
						<td class='manual_table_td_d'>".$row['amount']."&euro;</td>
						<td class='manual_table_td_d'>".$row['credits']."</td>
						<td class='manual_table_td_d'>".$row['trans_total_amount']."</td>
						<td class='manual_table_td_d'>".$row['created_on']."</td>
						<td class='manual_table_td_d'>".$row['created_by']."</td>
					<tr>";
			}
			echo "</table><br />";
		}
	?>
		</div>
			<div style="float:right; padding:5px" class="align-right">
				<input type="button" id="go_idle" value="<?php echo $lbl_idle ?>" class="big_idle" onclick="window.location.href='idle.php'" /><br />
				<input type="button" id="go_delete" value="<?php echo $lbl_delete; ?>" class="big_delete"
				onclick="if (confirm('<?php echo $lbl_records_will_be_deleted ?>')){window.location.href='delete_trans.php?trans_id=<?php echo $transaction_id ?>&tot_amount=<?php echo $tot_amount ?>&creds=<?php echo $creds ?>'}" />
			</div>
		</fieldset>			
        </div>
</body>
</html>
<?php 
} else {
    header('Location: login.php');
}
?>


