-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransact_other_pay.php
267 lines (220 loc) · 10.7 KB
/
transact_other_pay.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
<?php
session_start();
if(!isset($_SESSION["user_email"]))
{
header('Location: index.php');
}
if (isset($_POST['transfer_other_bank']))
{
require_once('DBCONFIG/dbconfig.php');
if (class_exists('DATABASE_CONNECT'))
{
$obj_conn = new DATABASE_CONNECT;
$host = $obj_conn->connect[0];
$user = $obj_conn->connect[1];
$pass = $obj_conn->connect[2];
$db = $obj_conn->connect[3];
$conn = new mysqli($host,$user,$pass,$db);
if ($conn->connect_error)
{
die ("Cannot connect " .$conn->connect_error);
}
else
{
$name = $_POST['name'];
$account_no = $_POST['account_no'];
$ifsc = $_POST['ifsc'];
$reason = $_POST['reason'];
$main_amount = $_POST['main_amount'];
$otp = $_POST['otp'];
$email = $_SESSION["user_email"];
$sql = "select user_accountno from accounts
where user_email = '$email' ";
$result = $conn->query($sql);
$sql2 = "select Name, IFSC from other_bank
where IFSC = '$ifsc'";
$result2 = $conn->query($sql2);
while ($row = $result->fetch_assoc())
{
$current_customer_acc_no = $row['user_accountno'];
if($current_customer_acc_no == $account_no)
{
echo '<script type="text/javascript">alert("INVALID TRANSFER - YOU CANNOT TRANSFER TO YOUR OWN ACCOUNT");
</script>';
exit;
}
else
{
if ($result2->num_rows>0)
{
while ($row = $result2->fetch_assoc())
{
$name0 = $row['Name'];
$ifsc0 = $row['IFSC'];
if ($name0 == $name && $ifsc0 == $ifsc)
{
}
else
{
echo '<script type="text/javascript">alert("YOUR ELEMENT IS INVALID");
</script>';
exit;
}
}
}
else
{
echo '<script type="text/javascript">alert("YOUR ELEMENT IS INVALID");
</script>';
exit;
}
}
}
$sql = "select limit_per_day_transfer from accounts where user_email = '$email'";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc())
{
if ($main_amount > $row['limit_per_day_transfer'])
{
echo '<script type="text/javascript">alert("You have exceeded the <strong> overtransfer limit.");
</script>';
exit;
}
}
$sql = "select otp, otptime from accounts where user_email = '$email'";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc())
{
if ($otp!= $row['otp'])
{
echo '<script type="text/javascript">alert("OTP error. Please try again.");
</script>';
exit;
}
if ($otp = $row['otp'])
{
$time_db = $row['otptime'];
$time_now = strtotime($time_db);
if (time() - $time_now > 10 * 60)
{
echo '<script type="text/javascript">alert("Verification code expired Get new code to finish transferring.");
</script>';
echo ("<script>location.href='transact_other.php'</script>");
}
$sql2 = "update accounts set otp = null where user_email = '$email'";
$result2 = $conn->query($sql2);
}
else
{
echo'<script type="text/javascript">alert("The verification code is a mistake <strong> You can not make out the transaction.");
</script>';
exit;
}
}
$sql = "select user_balance from accounts where user_email = '$email'";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc())
{
$total_balance = $row['user_balance'];
$amount_reserve = 20;
$total_amount_with_reserve = $main_amount + $amount_reserve;
if ($main_amount < 0)
{
echo '<script type="text/javascript">alert("Negative value is Invalid. Please try again.");
</script>';
exit;
}
else if ($main_amount == 0)
{
echo '<script type="text/javascript">alert("Invalid Value. Please try again.");
</script>';
exit;
}
else if ($total_amount_with_reserve > $total_balance)
{
echo '<script type="text/javascript">alert("You do not have enough balance to do this transfer.");
</script>';
exit;
}
else if ($total_amount_with_reserve <= $total_balance)
{
$sql2 = "update accounts set amounts_transferred = amounts_transferred + $main_amount,
amounts_from_reserve = amounts_from_reserve + $amount_reserve,
user_balance = user_balance - $total_amount_with_reserve
where user_email = '$email'";
$result2 = $conn->query($sql2);
$sql3 = "update other_bank set Amount_from_others = Amount_from_others + $main_amount ,
Balance = Balance + $main_amount
where Name= '$name' and IFSC = '$ifsc' ";
$result3 = $conn->query($sql3);
}
else
{
exit;
}
}
$length_number = 16;
$transaction_number = substr(str_shuffle("0123456789"),0, $length_number);
$sql = "select user_lastname, user_ifsc from users
where user_email = '$email' ";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc())
{
$amount_reserve =20;
$total_amount = $main_amount + $amount_reserve;
$_from_customer_lastname = $row['user_lastname'];
$_from_customer_ifsc = $row['user_ifsc'];
$sql2 = "insert into transactions_other_bank
(_from_customer_lastname, _from_customer_ifsc,
_to_customer_lastname,_to_customer_ifsc,
reason, transaction_number,
amount_from_reserve, amount, total_amount)
values
('$_from_customer_lastname',
'$_from_customer_ifsc',
'$name','$ifsc',
'$reason', '$transaction_number',
'$amount_reserve', '$main_amount', '$total_amount')";
$result2 = $conn->query($sql2);
$sql3 = "insert into transactions_all
(_from_customer_lastname,_from_customer_accno_iban,
_to_customer_lastname,_to_customer_accno_iban,
reason, transaction_number, amount)
values
('$_from_customer_lastname',
'$_from_customer_ifsc',
'$name',
'$ifsc',
'$reason', '$transaction_number', '$total_amount')";
$result3 = $conn->query($sql3);
$sql4 = "insert into soulbank_reserve
(_from_customer_lastname,_from_customer_ifsc,
_to_customer_lastname, _to_customer_ifsc,
transaction_number, amount_reserve)
values
('$_from_customer_lastname',
'$_from_customer_ifsc',
'$name',
'$ifsc',
'$transaction_number', '$amount_reserve')";
$result4 = $conn->query($sql4);
$sql5 = "update soulbank_total_reserves
set total_reserve = total_reserve + '$amount_reserve'
where soul_bank_id = 'SOUL_PAY_1010'";
$result5 = $conn->query($sql5);
if ($result2 == true && $result3 == true && $result4 == true && $result5 == true)
{
echo '<script type="text/javascript">alert("This transfer was held successfully.");
</script>';
echo ("<script>location.href='user_dashboard.php'</script>");
exit;
}
else
{
echo "Error";
}
}
}
}
}
?>