-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.php
313 lines (288 loc) · 13.2 KB
/
transaction.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
<?php
session_start();
require_once("connection.php");
if(!isset($_SESSION['username'])){
header('Location: index.php');
exit;
}
// if(isset($_SESSION['transaction_successfull'])){
// header('Location: receipt.php');
// exit;
// }
//variable declaration
$control = 0;
$recipient_account_num_error = '';
$name_error = '';
$c_account_error = '';
$amount_error = '';
$name = '';
$recipient_account_num = '';
$ifsc_code = '';
$ifsc_code_error = '';
function filterText($str){
$str = strip_tags($str);
$str = trim($str);
$str = addslashes($str);
return $str;
}
//Getting the customer_id from the home page, the customer's data is taken out to be displayed
if(isset($_GET['c_id'])){
$customer_id = $_GET['c_id'];
$sql = "SELECT name, account_num, IFSC_Code, current_balance FROM customers WHERE customer_id='$customer_id'";
$result = $conn->query($sql);
if($result->num_rows == 1){
$row = $result->fetch_assoc();
$sender_name = $row['name'];
$sender_acc_num = $row['account_num'];
$sender_ifsc_code = $row['IFSC_Code'];
$sender_balance = $row['current_balance'];
}
else {
header('Location: index.php');
$_SESSION['message'] = 'Invalid customer ID';
$_SESSION['message-css'] = 'error-msg';
exit;
}
}
//if the customer_id is wrong, the client is redirected back to the home page
else{
$_SESSION['message'] = 'Invalid customer ID';
$_SESSION['message-css'] = 'error-msg';
header('Location: index.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Make Transaction</title>
<link rel="stylesheet" href="public/CSS/styles.css">
<link rel="stylesheet" href="public/CSS/transaction.css">
<?php require 'includes/layout.php'; ?>
</head>
<body>
<?php require 'includes/header.php'; ?>
<div class="flex-row mt-20px pb-50px">
<div class="child">
<div class="flex-col trans-card z-index-10 shadow">
<h3 class="mb-20px t-c">
Sender's details
</h3>
<div class="sender-detail">
<label>Name </label>
<div><?php echo $sender_name; ?></div>
</div>
<div class="sender-detail">
<label>Account number </label>
<div><?php echo $sender_acc_num; ?></div>
</div>
<div class="sender-detail">
<label>IFSC Code </label>
<div><?php echo $sender_ifsc_code; ?></div>
</div>
<div class="sender-detail">
<label>Balance </label>
<div><?php echo $sender_balance; ?> <i class="fas fa-rupee-sign"></i></div>
</div>
</div>
</div>
<div class="partition">
<?php require 'includes/transfer-animation.php'; ?>
</div>
<div class="child">
<div class="flex-col trans-card z-index-10 shadow">
<h3 class="mb-20px ml-20px t-c">
Enter Recipient details
</h3><?php
$sql = "SELECT * FROM customers ORDER BY name";
$result = $conn->query($sql);
?>
<form id="transaction-form" action="" method="post" class="form">
<!-- Choose from listed customers -->
<?php if($result->num_rows > 0){ ?>
<div class="input-container">
<select id="fetch-customer" class="custom-select">
<option value="">Choose from listed customers</option>
<?php
while($row = $result->fetch_assoc()){
?>
<option value="<?php echo $row['customer_id']; ?>"><?php echo $row['name']; ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<script>
function fillCustomerDetails(res){
res = JSON.parse(res)
console.log(res)
let inputs = document.getElementsByClassName('transaction-input')
if(res.success){
let customer = JSON.parse(res.data)
inputs[0].value = customer.name
inputs[1].value = customer.account_num
inputs[3].value = customer.IFSC_Code
}
else{
inputs[0].value = ''
inputs[1].value = ''
inputs[3].value = ''
}
}
$('#fetch-customer').on('change', () => {
let customerId = $('#fetch-customer').val()
let reqData = {
customer_id : customerId
}
let url = 'fetch-customer-details.php'
$.ajax({
url,
type : 'POST',
dataType : 'html',
success : (msg) => {
},
complete : (res) => {
fillCustomerDetails(res.responseText)
},
data : reqData
})
})
</script>
<div class="input-container">
<label for="name" >Name </label>
<input class="transaction-input" type="text" name="name" class="input" value="<?php echo $name; ?>">
<div class="error">
</div>
<?php if($name_error != ''){ ?>
<i class="fas fa-exclamation-circle error-icon"></i>
<?php } ?>
</div>
<div class="input-container">
<label for="account_num">A/C No </label>
<input class="transaction-input" type="number" name="account_num" class="input" value="<?php echo $recipient_account_num; ?>">
<div class="error">
</div>
<?php if($recipient_account_num_error != ''){ ?>
<i class="fas fa-exclamation-circle error-icon"></i>
<?php } ?>
</div>
<div class="input-container">
<label for="c_account_num">Confirm A/C No </label>
<input class="transaction-input" type="number" name="c_account_num" class="input" >
<div class="error">
</div>
<?php if($c_account_error != ''){ ?>
<i class="fas fa-exclamation-circle error-icon"></i>
<?php } ?>
</div>
<div class="input-container">
<label for="ifsc_code">IFSC Code </label>
<input class="transaction-input" type="text" name="ifsc_code" class="input" >
<div class="error">
</div>
<?php if($ifsc_code_error != ''){ ?>
<i class="fas fa-exclamation-circle error-icon"></i>
<?php } ?>
</div>
<div class="input-container">
<label for="amount">Amount </label>
<input class="transaction-input" type="number" step="0.000001" name="amount" class="input" >
<div class="error">
</div>
<?php if($amount_error != ''){ ?>
<i class="fas fa-exclamation-circle error-icon"></i>
<?php } ?>
</div>
<div class="button-container">
<button id="make-transaction-btn" type="submit" class="button">Confirm</button>
</div>
</form>
</div>
</div>
</div>
<script>
function fetch_response(response){
let btn = document.getElementById('make-transaction-btn')
let inputs = document.getElementsByClassName('transaction-input')
let errorIcon = '<i class="fas fa-exclamation-circle error-icon"></i>'
let successIcon = '<i class="fas fa-check success-icon">'
response = JSON.parse(response)
let success = response.success
console.log('success : ' + success)
if(!success){
console.log(response)
let responseErrors = response.error
console.log(responseErrors)
let errors = document.getElementsByClassName('error')
let i = 0
responseErrors.forEach((err) => {
if(err != ''){
errors[i].innerHTML = errorIcon + err
inputs[i].className = 'transaction-input input-error'
}
else {
errors[i].innerHTML = ''
inputs[i].className = 'transaction-input'
if(inputs[i] != ''){
errors[i].innerHTML = successIcon
inputs[i].className = 'transaction-input input-success'
}
}
i++
})
btn.innerHTML = 'Confirm'
btn.disabled = false
}
else{
btn.disabled = true
transactionAnimation()
btn.innerHTML = '<i class="fas fa-sync-alt fa-spin mr-5px"></i> Processing transaction'
setTimeout(() => {
location.href = 'receipt.php'
}, 8000)
}
}
$(document).ready(() => {
$('#transaction-form').submit((e) => {
e.preventDefault()
let btn = document.getElementById('make-transaction-btn')
btn.disabled = true
btn.innerHTML = '<i class="fas fa-sync-alt fa-spin mr-5px"></i> Checking Details'
let inputs = document.getElementsByClassName('transaction-input')
let holderName = inputs[0].value
let accountNumber = inputs[1].value
let confirmAccountNumber = inputs[2].value
let ifscCode = inputs[3].value
let transactionAmount = inputs[4].value
let url = 'make-transaction.php'
let reqData = {
sender_account_num : <?php echo $sender_acc_num; ?>,
sender_balance : <?php echo $sender_balance; ?>,
name : holderName,
account_num : accountNumber,
c_account_num : confirmAccountNumber,
ifsc_code : ifscCode,
amount : transactionAmount
}
setTimeout(() => {
$.ajax({
url,
type : 'POST',
dataType : 'html',
success : (msg) => {
},
complete : (res) => {
fetch_response(res.responseText)
},
data : reqData
})
}, 500)
return false
})
})
</script>
<div id="transaction-response"></div>
</body>
</html>