-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
182 lines (177 loc) · 6.84 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
session_start();
if(empty($_SESSION['accesstoken'])) {
exit(header('location: /login.php'));
}
// check the access token is still ive
require_once('inc/settings.php');
require_once('scripts/checkAccessToken.php');
if(tokenExpired($_SESSION['accesstoken'],$api_root)) {
// make them re-auth, their token has expired.
exit(header('location: /login.php?expired'));
}
header("Content-Type: text/html; charset=utf-8");
?>
<!DOCTYPE html>
<html>
<head>
<?php require_once('inc/head.php');?>
<title>Mondo Online Banking</title>
</head>
<body>
<div class="container">
<?php require_once('inc/navbar.php');?>
<div class="row">
<div class="col-sm-9">
<div class="table-responsive">
<table class="table table-hover" id="transactions">
<thead>
<tr>
<th></th>
<th class="no-sort">Amount</th>
<th class="no-sort">Retailer</th>
<th class="no-sort">Date</th>
<th class="no-sort">Balance</th>
</tr>
</thead>
<tbody>
<?php
// loop through transactions
foreach($transactions as $transaction) {
if(!empty($transaction['decline_reason'])) {
$class = 'text-danger';
$styling = 'text-decoration: line-through;';
$amount = '- £'.number_format($transaction['amount_declined']*-1/100,2);
$type = '<span class="label label-danger"><i class="fa fa-times fa-fw"></i></span>';
}
else if($transaction['amount']<0) {
$class = 'text-warning';
$styling = '';
$amount = '- £'.number_format($transaction['amount']*-1/100,2);
$type = '<span class="label label-warning"><i class="fa fa-arrow-down fa-fw"></i></span>';
}
else if($transaction['amount']>0) {
$class = 'text-success';
$styling = '';
$amount = '+ £'.number_format($transaction['amount']/100,2);
$type = '<span class="label label-success"><i class="fa fa-arrow-up fa-fw"></i></span>';
}
else {
$class = 'text-muted';
$styling = '';
$amount = '± £0';
$type = '<span class="label label-default"><i class="fa fa-check"></i></span>';
}
?>
<tr>
<td><?php echo $type;?></td>
<td><?php echo "<span class='$class' style='$styling'>$amount</span>";?></td>
<td>
<?php
if($transaction['is_load']) {
echo '<img src="/assets/img/mondo.png" style="height: 1em;"> ';
$transaction_title = 'Top Up';
}
else if(empty($transaction['merchant']['name'])) {
$transaction_title = $transaction['description'];
}
else {
$transaction_title = $transaction['merchant']['emoji'].' '.$transaction['merchant']['name'];
}
echo $transaction_title;
?>
</td>
<td>
<a href="#" data-toggle="modal" data-target="#transactionModal" data-transaction_title="<?php echo $transaction_title;?>" data-transaction_amount="<?php echo "<span class='$class' style='$styling'>$amount</span>";?>" data-transaction_date="<?php echo date('d\/m\/Y g:i a', strtotime($transaction['created']));?>" data-transaction_notes="<?php echo $transaction['notes'];?>" data-transaction_category="<?php echo $transaction['category'];?>" data-transaction_declined="<?php if(!empty($transaction['amount_declined'])) {echo 'true';} else {echo 'false';}?>" style="color: #333;">
<?php
echo date('d\/m\/Y g:i a', strtotime($transaction['created']));
?>
</a>
</td>
<td><?php echo '£'.number_format($transaction['account_balance']/100,2);?></td>
</tr>
<?php }?>
</tbody>
</table>
<div class="modal fade" id="transactionModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Transaction Name</h4>
</div>
<div class="modal-body">
<center>
<h1 class="transaction_amount"></h1>
<p class="transaction_declined lead text-danger"></p>
<h3 class="transaction_title"></h3>
<p class="notes lead"></p>
<span class="label label-info category"></span>
</center>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<h3>Account Overview</h3>
<?php
require_once('scripts/expenditure.php');
$balanceDetails = currentBalance($_SESSION['accesstoken'], $_SESSION['account_id'], $api_root);
require_once('scripts/accountInfo.php');
$accountInfo = getAccountInfo($_SESSION['accesstoken'], $api_root, true);
?>
<table class="table">
<tr>
<td>
<b>Current Balance: </b>
</td>
<td style="text-align: right;">
<span style="font-size: 1em;" class="label label-success"><?php echo '£'.number_format($balanceDetails['balance']/100,2);?></span>
</td>
</tr>
<tr>
<td>
<b>Spent Today: </b>
</td>
<td style="text-align: right;">
<span style="font-size: 1em;" class="label label-danger"><?php echo '£'.number_format(trim($balanceDetails['spend_today'],'-')/100,2);?></span>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php require_once('inc/foot.php');?>
<script src="/assets/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="/assets/js/dataTables.bootstrap.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#transactions').DataTable(
{
"aoColumnDefs" : [ {
"bSortable" : false,
"aTargets" : [ "no-sort" ]
} ]
}
);
});
</script>
<script>
$('#transactionModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var modal = $(this)
modal.find('.modal-title').text(button.data('transaction_date'))
modal.find('.transaction_amount').html(button.data('transaction_amount'))
modal.find('.transaction_title').text(button.data('transaction_title'))
modal.find('.notes').text(button.data('transaction_notes'))
modal.find('.category').text(button.data('transaction_category')).css('textTransform', 'capitalize')
// declined or not
if (button.data('transaction_declined') == true) {
modal.find('.transaction_declined').text("Transaction declined")
}
})
</script>
</body>
</html>