<?php

require __dir__ . '/init.php';

if( isset($_POST['delete']) ) {
	
	$_POST = help::sanitize($_POST);
	
	$SQL = "DELETE FROM tbl_transaction WHERE tx_no = '{$_POST['tx_no']}'";
	$status = $link->query( $SQL );
	$msg = $status ? "The statement was delete" : "The statement was not deleted";
	
};

template::get_header();

?>

	<?php template::title( 'Users Statement Of Account' ); ?>
	
	<?php template::alert( $msg, $status ?? null ); ?>
	
	<div class='card'>
		<div class='card-body'>
		
			<div class="table-responsive">
				<table class="table" data-table='simple'>
					<thead>
						<tr >
							<th>TXN-TYPE</th>
							<th>AMOUNT</th>
							<th>DESCRIPTION</th>
							<th>TO-ACCT/FROM-ACCT</th>
							<th>STATUS</th>
							<th>TXN-DATE</th>
							<th>REFERENCE NO</th>
							<th>ACTION</th>
							<th>ACTION</th>
						</tr>
					</thead>
					<tbody>
						<?php 
							
							$sql = "SELECT * FROM tbl_transaction ORDER BY id DESC LIMIT 1000";
							$result = mysqli_query($link,$sql);
						
							if(mysqli_num_rows($result) > 0){
								while($row = mysqli_fetch_assoc($result)){  
						 
						   
						 ?>
						<tr class="info">
							<td><?php echo $row['tx_type'];?></td>
							<td><?php echo $row['amount'];?></td>
							<td class="center"><?php echo $row['comments'];?></td>
							<td><?php echo $row['to_accno'];?> / <?php echo $row['account']; ?></td>
							<td><?php echo $row['status'];?></td>
							<td><?php echo $row['date'];?></td>
							<td><?php echo $row['tx_no'];?></td>
							<td>
								<form method='post' onsubmit="return confirm('Please click OK to proceed');">
									<input type='hidden' name='tx_no' value='<?php echo $row['tx_no']; ?>'>
									<button type="submit" name="delete" class="btn btn-danger">
										<span class="fas fa-trash"></span>
									</button>
								</form>
							</td>
							<td>
								<a href="view-statement.php?refno=<?php echo $row['tx_no']?>">
									<button  name="view" class="btn btn-info">
										<span class="fas fa-pencil-alt"></span>
									</button>
								</a>
							</td>
						</tr>
						<?php
								};
							}
									  ?>          
					</tbody>
				</table>
			</div>
			
		</div>
	</div> 

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