<?php

require __dir__ . '/init.php';

template::get_header();

?>
 
    <?php template::title("My Account Statement"); ?>

	<?php
		$sql = "
			SELECT * FROM tbl_transaction WHERE account = {$__user['acctno']} 
			ORDER BY id DESC LIMIT 2000
		";
		$result = mysqli_query($link,$sql);
	?> 

		<div class="form-group-inner">
			<div class="row">
				<div class="col-lg-3">
					<label class="login2 pull-right pull-right-pro"><button class="btn btn-primary">Statement Of Account</button></label>
				</div>
				<div class="col-lg-6">
					<input type="text"  value="<?php echo $__user['fname'].'  '.$__user['lname'].' | '.$__user['acctno'];?>" readonly="true" class="form-control" />
				</div>
			</div>
		</div>

		<hr>

		<div class="sparkline13-graph row">
            <div class="col-md-12 col-sm-12 col-sx-12">
				<div class='card'>
					<div class='card-body'>
					   <div class="table-responsive">
							 <table class="display table table-striped"  data-table="advance">
								<thead>
									<tr>
										<th class="account header">Account</th>
										<th class="header">Name</th>
										<th class="{sorter: &#39;numeric&#39;} header">Reference No#</th>
										<th class="right header">Date</th>
										<th class="right header">Description</th>
										<th class="right {sorter: &#39;date&#39;} header">Debit</th>
										<th class="right {sorter: &#39;date&#39;} header">Credit</th>
										<th class="right {sorter: &#39;date&#39;} header">Charges</th>
									</tr>
								</thead>
								<tbody>
								<?php
									$sql = "SELECT * FROM tbl_transaction WHERE account = {$__user['acctno']} ORDER BY id DESC";
									$result = mysqli_query($link, $sql);
									if(mysqli_num_rows($result)){
										while($row = mysqli_fetch_assoc($result)){
								?>
									<tr>
										<td class="account" id="account-10034">
											<?php echo $__user['acctno'] ?>
										</td>
										<td><?php echo $__user['fname'];  ?></td>
										<td>
											<?php echo $row['tx_no']; ?>
										</td>
										<td class="right"><?php echo $row['date']; ?></td>
										<td class="right"><?php echo $row['comments']; ?></td>
										<td class="right" style="text-transform: lowercase">
											<span style="color:red">
												<?php echo $row['tx_type'] == "debit" ? $currency . "&nbsp;" . number_format($row['amount'], 2) : "-"; ?>
											</span>
										</td>
										<td class="right" style="text-transform: lowercase">
											<span style="color:green">
												<?php echo $row['tx_type'] == "credit" ? $currency . "&nbsp;" . number_format($row['amount'], 2) : "-"; ?>
											</span>
										</td>
										<td class="right" style="text-transform: lowercase">
											<span style="color:red">
												<?php echo $row['tx_type'] == "debit" ? $currency . "&nbsp;" . number_format($row['charges'], 2) : "-"; ?>
											</span>
										</td>
									</tr>
							  <?php
										} // end while
									}//if
								else {
							?>
									<tr> 
										<td colspan="6" align="right">
											You have no transaction history yet, seems that you haven't done any transaction yet.
										</td>
									</tr>

									<tr id="closing-balance-row">
										<th class="right" colspan="4">Available Balance: </th>
										<th class="right amount">$ <?php echo number_format($__user['balance'], 2); ?></th>
									</tr>
			  
									<tr id="credit-turnover-row">
										<th class="right" colspan="4">Pending Balance:</th>
										<th class="right amount">$ <?php echo '0.00'; ?></th>
									</tr>
							<?php }//else ?>
			  
								</tbody>
							</table>
							
						</div>
					</div>
				</div>
			</div>
		</div>

<?php template::get_footer(); ?>  