-
Notifications
You must be signed in to change notification settings - Fork 13
/
transactions.php
320 lines (222 loc) · 9.15 KB
/
transactions.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
/* Avoid multiple sessions warning
Check if session is set before starting a new one. */
if(!isset($_SESSION)) {
session_start();
}
include "validate_admin.php";
include "connect.php";
include "header.php";
include "user_navbar.php";
include "admin_sidebar.php";
include "session_timeout.php";
if (isset($_GET['cust_id'])) {
$_SESSION['cust_id'] = $_GET['cust_id'];
}
$sql0 = "SELECT * FROM passbook".$_SESSION['cust_id'];
// Recive sort variables as $_GET
if (isset($_GET['sort'])) {
$sort = $_GET['sort'];
}
// Recieve filter variables as session variables
if (isset($_POST['search_term'])) {
$_SESSION['search_term'] = $_POST['search_term'];
}
if (isset($_POST['date_from'])) {
$_SESSION['date_from'] = $_POST['date_from'];
}
if (isset($_POST['date_to'])) {
$_SESSION['date_to'] = $_POST['date_to'];
}
// Filter indicator variable
$filter_indicator = "None";
// Queries when search is set
if (!empty($_SESSION['search_term'])) {
$sql0 .= " WHERE remarks COLLATE latin1_GENERAL_CI LIKE '%".$_SESSION['search_term']."%'";
$filter_indicator = "Remarks";
if (!empty($_SESSION['date_from']) && empty($_SESSION['date_to'])) {
$sql0 .= " AND trans_date > '".$_SESSION['date_from']." 00:00:00'";
$filter_indicator = "Remarks & Date From";
}
if (empty($_SESSION['date_from']) && !empty($_SESSION['date_to']))
{
$sql0 .= " AND trans_date < '".$_SESSION['date_to']." 23:59:59'";
$filter_indicator = "Remarks & Date To";
}
if (!empty($_SESSION['date_from']) && !empty($_SESSION['date_to'])) {
$sql0 .= " AND trans_date BETWEEN '".$_SESSION['date_from']." 00:00:00' AND
'".$_SESSION['date_to']." 23:59:59'";
$filter_indicator = "Remarks, Date From & Date To";
}
}
// Queries when search is not set
if (empty($_SESSION['search_term'])) {
if (!empty($_SESSION['date_from']) && empty($_SESSION['date_to']))
{
$sql0 .= " WHERE trans_date > '".$_SESSION['date_from']." 00:00:00'";
$filter_indicator = "Date From";
}
if (empty($_SESSION['date_from']) && !empty($_SESSION['date_to'])) {
$sql0 .= " WHERE trans_date < '".$_SESSION['date_to']." 23:59:59'";
$filter_indicator = "Date To";
}
if (!empty($_SESSION['date_from']) && !empty($_SESSION['date_to'])) {
$sql0 .= " WHERE trans_date BETWEEN '".$_SESSION['date_from']." 00:00:00' AND '".$_SESSION['date_to']." 23:59:59'";
$filter_indicator = "Date From & Date To";
}
}
// Sort Queries
// Sort acts independent of the filter
if (isset($_GET['sort'])) {
if ($sort == 'tid_down') {
$sql0 .= " ORDER BY trans_id ASC";
}
if ($sort == 'tid_up') {
$sql0 .= " ORDER BY trans_id DESC";
}
if ($sort == 'date_down') {
$sql0 .= " ORDER BY trans_date ASC";
}
if ($sort == 'date_up') {
$sql0 .= " ORDER BY trans_date DESC";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="transactions_style.css">
</head>
<body>
<div class="search-bar-wrapper">
<div class="search-bar" id="the-search-bar">
<div class="flex-item-search-bar" id="fi-search-bar">
<button id="search" onclick="document.getElementById('id01').style.display='block'">Filter</button>
<div class="flex-item-by">
<label id="sort">Sort By :</label>
</div>
<div class="flex-item-search-by">
<select name="by" onChange="window.location.href=this.value">
<option selected disabled hidden>
<?php if (empty($_GET['sort'])) {?>Tn. ID ↓<?php } else { ?>
<?php if ($sort == 'tid_down') {?>Tn. ID ↓<?php } ?>
<?php if ($sort == 'tid_up') {?>Tn. ID ↑<?php } ?>
<?php if ($sort == 'date_down') {?>Date ↓<?php } ?>
<?php if ($sort == 'date_up') {?>Date ↑<?php } ?>
<?php } ?>
</option>
<option value="transactions.php?sort=tid_down">Tn. ID ↓</option>
<option value="transactions.php?sort=tid_up">Tn. ID ↑</option>
<option value="transactions.php?sort=date_down">Date ↓</option>
<option value="transactions.php?sort=date_up">Date ↑</option>
</select>
</div>
</div>
</div>
</div>
<div id="id01" class="modal">
<form class="modal-content animate" action="" method="post">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Filter">×</span>
</div>
<div class="container">
<h1 id="filter">Filter</h1>
<p id="filter">(Leave blank to remove filter)</p>
<label>Trans. Remarks :</label>
<input type="text" placeholder="Enter Remarks" name="search_term">
<label>Duration (yyyy-mm-dd) :</label>
<div class="duration-container">
<div class="date-container">
<input id="date" type="text" placeholder="From" name="date_from">
</div>
<p id="minus">−<b</p>
<div class="date-container">
<input id="date" type="text" placeholder="Upto" name="date_to">
</div>
</div>
<button id="submit" type="submit">Go</button>
</div>
</form>
</div>
<div class="flex-container">
<p id="none">Filter : <?php echo $filter_indicator ?></p>
</div>
<div class="flex-container">
<?php
$result = $conn->query($sql0);
if ($result->num_rows > 1) {?>
<table id="transactions">
<tr>
<th>Trans. ID</th>
<th>Date & Time (IST)</th>
<th>Remarks</th>
<th>Debit (INR)</th>
<th>Credit (INR)</th>
<th>Balance (INR)</th>
</tr>
<?php
// output data of each row
while($row = $result->fetch_assoc()) {?>
<tr>
<td><?php echo $row["trans_id"]; ?></td>
<td>
<?php
$time = strtotime($row["trans_date"]);
$sanitized_time = date("d/m/Y, g:i A", $time);
echo $sanitized_time;
?>
</td>
<td><?php echo $row["remarks"]; ?></td>
<td><?php echo number_format($row["debit"]); ?></td>
<td><?php echo number_format($row["credit"]); ?></td>
<td><?php echo number_format($row["balance"]); ?></td>
</tr>
<?php } ?>
</table>
<?php
} else { ?>
<p id="none"> No results found :(</p>
<?php }
$conn->close(); ?>
</div>
<script>
// Sticky search-bar
$(document).ready(function() {
var curr_scroll;
$(window).scroll(function () {
curr_scroll = $(window).scrollTop();
if ($(window).scrollTop() > 120) {
$("#the-search-bar").addClass('search-bar-fixed');
if ($(window).width() > 855) {
$("#fi-search-bar").addClass('fi-search-bar-fixed');
}
}
if ($(window).scrollTop() < 121) {
$("#the-search-bar").removeClass('search-bar-fixed');
if ($(window).width() > 855) {
$("#fi-search-bar").removeClass('fi-search-bar-fixed');
}
}
});
$(window).resize(function () {
var class_name = $("#fi-search-bar").attr('class');
if ((class_name == "flex-item-search-bar fi-search-bar-fixed") && ($(window).width() < 856)) {
$("#fi-search-bar").removeClass('fi-search-bar-fixed');
}
if ((class_name == "flex-item-search-bar") && ($(window).width() > 855) && (curr_scroll > 120)) {
$("#fi-search-bar").addClass('fi-search-bar-fixed');
}
});
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
});
</script>
</body>
</html>