<?php
/**
* transactions.php -- Transactions page
*/

include '../inc/config.inc.php'; // Configuration

ob_start();
session_start();

//date_default_timezone_set('Africa/Lagos');

error_reporting(E_ALL);
ini_set('display_errors', 1);

if ( !isset($_SESSION['user']) || $_SESSION["loggedin"] !== true || trim($_SESSION['user']) == '' ){
header('Location: ' . $BASE_URL . 'signin');
exit;
}

// User Details
$stmt = $db_con->prepare("SELECT * FROM users WHERE id=:user_id");
$stmt->execute(array(":user_id"=>$_SESSION['user']));
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);

?>

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="description" content="">
<meta name="keywords" content="investment, Forex, Trading, Bitcoin, Cryptocurrency, Global investment, Live Trade, Trading class, indics">
<meta name="author" content="Paul HubWeb & Tech">
<meta name="theme-color" content="#313131" />
<!-- Site Properties -->
<title>Tranactions </title>
<link rel="shortcut icon" href="../img/Signals-Alert-3.png" type="image/x-icon">
<link rel="apple-touch-icon-precomposed" href="../img/Signals-Alert-3.png">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Typography CSS -->
<link rel="stylesheet" href="css/typography.css">
<!-- Style CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- Responsive CSS -->
<link rel="stylesheet" href="css/responsive.css">
<style>
* {
box-sizing: border-box;
}

body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

.header {
overflow: none;
background-color: none;
padding: 20px 10px;
padding-left: 5px;
position: fixed;
}

/*.header a {
float: center;
width:30px;
color: #fff;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px; 
line-height: 25px;
border-radius: 4px;
background-color:rgb(196, 0, 0);
border-color: rgb(196, 0, 0);
}*/

.header a.logo {
font-size: 25px;
font-weight: bold;
}

/*.header a:hover {
background-color:  #010847;
color: #fff;
}*/

/*.header a.active {
background-color: dodgerblue;
color: white;
}*/

.header-center {
float: left;
}

@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}

.header-right {
float: none;
}
}
</style>

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" rel="stylesheet" />
<style>
/*------ Google Font Style ------ */
body {font-family:'Roboto'!important;}
</style>

</head>
<body class="sidebar-main-active right-column-fixed">
<!-- loader Start -->
<!-- loader END -->
<!-- Wrapper Start -->
<div class="wrapper">
<!-- Sidebar  -->
<?php include 'navbar.php' ?>
<!-- Page Content  -->
<div id="content-page" class="content-page" style="margin-top:80px;">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="iq-card">
<div class="iq-card-header d-flex justify-content-between">
<div class="iq-header-title">
<h4 class="card-title" style="font-family: 'Roboto'!important;">Transaction table</h4>
</div>
</div>
<div class="iq-card-body">
<p>All Transactions are saved here for refrencing. You can also <code>print</code> Tranactions</p>
<div class="table-responsive">
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Type</th>
<th>Method</th>
<th>Amount</th>
<!--<th>File</th>-->
<th>Narration</th>
<th>Time</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$transactions = $db_con->prepare("SELECT * FROM user_transactions WHERE user_id='".$_SESSION['user']."' ORDER BY created DESC");
       
if ( $transactions->execute() ){
$i = 0;
while ( $trans = $transactions->fetch(PDO::FETCH_ASSOC) ){
$i++;
// var_dump($trans);   
?>
<tr>
<td><?php echo $trans['type']; ?></td>
<td><?php echo $trans['method']; ?></td>
<td>
<?php echo $userRow['currency'] . number_format($trans['amount'], 2);?>
</td>
<!--<td>
<?php if ( !empty($trans['file']) ){ ?>
<a href="uploads/<?= $trans['file']; ?>" target="_blank">View Image</a>
<?php } else { echo 'Not Available'; } ?>
</td>-->
<td><?php echo $trans['narration']; ?></td>
<td><?php echo date('h:iA', strtotime($trans['time'])); ?></td>
<td><?php echo date('Y/m/d', strtotime($trans['date'])); ?></td>
<?php 
if($trans['status']=='Pending'){
$p = '<b style="color:#ffa500;"><i class="las la-exclamation-circle" style="color:#ffa500;"></i>Pending...</b>';
}else{
if($trans['status']=='Approved'){
$p = '<b style="color:green;"><i class="las la-exclamation-circle" style="color:green;"></i>Approved...</b>';
}else{
if($trans['status']=='Declined'){
$p = '<b style="color:red;"><i class="las la-exclamation-circle" style="color:green;"></i>Declined...</b>';
}
}  
}
?>
<td>
<?php 
echo $p;
?>
</td>
</tr>
<?php
}
}
?>
</tbody>
<tfoot>
<tr>
<th>Type</th>
<th>Method</th>
<th>Amount</th>
<!--<th>File</th>-->
<th>Narration</th>
<th>Time</th>
<th>Date</th>
<th>Status</th>
</tr>
</tfoot>
</table>
<button type="button" class="btn btn-primary mr-2" onclick="window.print()"><i class="las la-download"></i>Print Transactions</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Wrapper END -->
<!-- Footer -->
<?php include 'footer.php' ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/jquery.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Appear JavaScript -->
<script src="js/jquery.appear.js"></script>
<!-- Countdown JavaScript -->
<script src="js/countdown.min.js"></script>
<!-- Counterup JavaScript -->
<script src="js/waypoints.min.js"></script>
<script src="js/jquery.counterup.min.js"></script>
<!-- Wow JavaScript -->
<script src="js/wow.min.js"></script>
<!-- Apexcharts JavaScript -->
<script src="js/apexcharts.js"></script>
<!-- Slick JavaScript -->
<script src="js/slick.min.js"></script>
<!-- Select2 JavaScript -->
<script src="js/select2.min.js"></script>
<!-- Owl Carousel JavaScript -->
<script src="js/owl.carousel.min.js"></script>
<!-- Magnific Popup JavaScript -->
<script src="js/jquery.magnific-popup.min.js"></script>
<!-- Smooth Scrollbar JavaScript -->
<script src="js/smooth-scrollbar.js"></script>
<!-- lottie JavaScript -->
<script src="js/lottie.js"></script>
<!-- am core JavaScript -->
<script src="js/core.js"></script>
<!-- am charts JavaScript -->
<script src="js/charts.js"></script>
<!-- am animated JavaScript -->
<script src="js/animated.js"></script>
<!-- am kelly JavaScript -->
<script src="js/kelly.js"></script>
<!-- am maps JavaScript -->
<script src="js/maps.js"></script>
<!-- am worldLow JavaScript -->
<script src="js/worldLow.js"></script>
<!-- Style Customizer -->
<script src="js/style-customizer.js"></script>
<!-- Chart Custom JavaScript -->
<script src="js/chart-custom.js"></script>
<!-- Custom JavaScript -->
<script src="js/custom.js"></script>

</body>
</html>