<?php

require __dir__ . '/init.php';


template::get_header();



?>
   
	<?php template::title("My Payment History"); ?>
	
	<div class='card'>
		<div class='card-body'>
			<div class="table-responsive">
				<table id="payment-history" class="table table-condensed table-responsive table-striped statement sortable" data-table="advance" data-pagelength="25">
				
					<thead>
						<tr>
							<th width="80" class="{sorter: &#39;date&#39;} header">Date</th>
							<th width="30%" class="header">Transacion ID</th>
							<th width="40%" class="header">Details</th>
							<th class="{sorter: &#39;amount&#39;} right amount header">Amount</th>
							<th class="{sorter: &#39;amount&#39;} right amount header">Charges</th>
							<th class="right header">Status</th>
							<th class="{sorter: false} mark-as-favorite">Receipt</th>
						</tr>
					</thead>
					
					<tbody>
					<?php
						$sql = "
							SELECT * FROM tbl_transaction 
							WHERE '{$__user['acctno']}' IN(account, to_accno)
							ORDER BY id DESC LIMIT 1000
						";
									$result = mysqli_query($link,$sql);
						if(mysqli_num_rows($result) > 0) { //if
							while($row = mysqli_fetch_assoc($result)) {
					?>
			
						<tr class="transaction-row nondefined" id="payment-10215" data-payment-id="10215">
							<td><?php echo $row['date']; ?></td>
							<td><?php echo $row['tx_no']; ?></td>
							<td>
								<div id="comment-10215" class="muted comment-in-history"></div>
								<?php echo $row['description']; ?>
							</td>
							<td class="right amount">
								<?php 
									if($row['tx_type'] == 'credit') { 
										$unit = '+';
										$color = 'text-success';
									} else {
										$unit = '-';
										$color = 'text-danger';
									};
									$amount = empty($row['amount']) ? 0 : $row['amount'];
									$value = '$' . number_format($amount, 2);
									if( !empty($amount) ) $value = $unit . $value;
								?>
								<span class="<?php echo $color; ?>"><?php echo $value; ?></span>
							</td>
							<td class="right amount">
								<span class="amount-value text-info">
									-<?php echo  "$" . number_format($row['charges'], 2); ?>
								</span>
							</td>
							<td class="right payment-status deferred">Completed</td>
							<td class="favorite-action">
								<a href='receipt.php?id=<?php echo $row['id']; ?>' class='btn btn-outline-primary'>
									<i class='fas fa-eye'></i>
								</a>
							</td>
						</tr>
					<?php
							} // end while
						}//if
						else {
					?>
						<tr> 
							<td colspan="6" align="center">
								You have no transaction history. <br>
								Seems that you haven't done any transaction yet.
							</td>
						</tr>
					<?php }//else{ ?>
					
				   </tbody>
				   
				 </table>	
			</div>
		</div>
	</div>
	
<?php template::get_footer(); ?>  