<?php

require __dir__ . '/init.php';

### [];

if($_SERVER['REQUEST_METHOD'] == 'POST') {
	
	$_POST = help::sanitize($_POST, true);

	$SQL = sQuery::update( 'tbl_transaction', $_POST, "tx_no='{$_GET['refno']}'" );
	
	$status = mysqli_query($link, $SQL);
	
	$msg = $status ? "History Details Edited Successfully!" : "Cannot Edit History Details! ";
	
};

### [];

$SQL = sQuery::select( 'tbl_transaction', "tx_no = '{$_GET['refno']}'" );

$trans = $link->query( $SQL )->fetch_assoc();

template::get_header();;

?>

	<?php template::title( strtoupper('<b>statement</b> @ REFNO: '.$trans['tx_no']) ); ?>
		
	<div class="section-body">
		<div class="card">
			<div class="card-body">
			
				<?php template::alert( $msg, $status ?? null ); ?>
				
				<form action="view-statement.php?refno=<?php echo $trans['tx_no']; ?>" method="POST">
					
					<?php
						
						$statements = array(
						
							"Account Number" => 'account',
							"Reference N<sup>o</sup>" => 'tx_no',
							"Amount (USD)" => 'amount',
							"Beneficiary Account" => 'to_accno',
							
							"Transaction Type" => ['tx_type', 'readonly'],
							"Status" => ['status', 'readonly'],
							"Date" => 'date',
							"Description" => 'comments'
							
						);
						
						foreach( $statements as $label => $data ):
							if( is_string($data) ) $data = [$data, null];
							$key = $data[0];
							$attr = $data[1];
					?>
						<div class='row form-group'>
							<div class='col-md-4'>
								<label class='form-label'><?php echo $label; ?></label>
							</div>
							<div class='col-md-8'>
								<input type='text' name='<?php echo $data[0]; ?>' class='form-control' value='<?php echo $trans[$key]; ?>' <?php echo $attr; ?>>
							</div>
						</div>
					<?php endforeach; ?>
					
					<hr>
					
					<div class='row'>
						<div class='col-md-8 ml-auto text-right'>
							<button  type="submit" class="btn btn-success btn-icon icon-left">
								<i class="fas fa-pencil-alt"></i> Edit History
							</button>
						</div>
					</div>

				</form>
			</div>
		</div>
	</div>


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