<?= printMessages('profile') ?>

<div class="table-responsive">
<table class=" table-striped table">
	<thead>
		<tr>
			<td width="110"></td>
			<td width="200"></td>
			<td></td>
			<td width="120"></td>
		</tr>
	</thead>
	<tbody>
<?PHP

if (is_array($transactions) && count($transactions)) {

$nextTransaction = [];
$i = 0;

foreach($transactions as $transact) {
	if ($transact['status'] == 0) {
		$nextTransaction = $transact;
		
		continue;
	}
	/* TODO: fix timezone */
	echo '
	<tr>
		<td>inv#'.$transact['id_customer_transaction'].'</td>
		<td>'.date("Y/m/d H:i", strtotime($transact['execution'])) . ' UTC+2</td>
		<td>'.($i++ == 0 ? 'Trial Fee' : 'Benefit Package').'</td>
		<td>'. $transact['amount'] .' '. $transact['currency'] .'</td>
	</tr>
	';
}

?>

	</tbody>
</table>
</div>

<i>Next billing will occur on <?= date("Y/m/d H:i", strtotime($nextTransaction['execution'])) . " UTC+2" ?> </i>

<?PHP

$time = $transactions[0]['execution'];

date_default_timezone_set($tz);

$hours = 14;

if ((true || (time() - strtotime($time))/3600 > $hours) && !$cancelled) {


echo '<br><br><br><div class="text-center"><a href="?cancel=1" class="btn btn-success" id="cancel-btn-fixer">Cancel subscription</a></div>';

} else if ($cancelled) {
	echo '<a href="#" class="btn btn-danger disabled" id="cancel-btn-fixer">Already unsubscribed</a>';

} else {

?>

<a href="#" class="btn btn-danger disabled" id="cancel-btn-fixer">Cannot cancel yet</a>
<br>
You can cancel your subscription on <?= date("Y/m/d H:i", strtotime($time)+$hours*3600) . " UTC+2" ?> 

<?PHP
}

}	?>