-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApproveLoans1.php
123 lines (95 loc) · 4.09 KB
/
ApproveLoans1.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
<?php
session_start();
if(!isset($_SESSION["User"]) & empty($_SESSION["User"])){
header('location:login.php');
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
$AccNo=$_GET['AccNo'];
$Branch=$_GET['Branch'];
$Amount=$_GET['Amount'];
$Time_Period=$_GET['Time'];
$Installment=$_GET['Installment'];
$RequestID=$_GET['RequestID'];
$RequestBy=$_GET['RequestBy'];
$User=$_SESSION['Employee_ID'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Bank"; // Create connection
$conn = new mysqli($servername, $username, $password, $dbname); // Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
try {
$conn->autocommit(FALSE); // i.e., start transaction
// assume that the TABLE groups has an auto_increment id field
$query = "INSERT INTO loan(Account_No,Loan_Type,Amount,Branch_ID,Time_Period,Installment) VALUES($AccNo,1,$Amount,$Branch,$Time_Period,$Installment)";
$result = $conn->query($query);
if ( !$result ) {
//$result->free();
throw new Exception($conn->error);
}
$Loan_ID = $conn->insert_id; // last auto_inc id from *this* connection
$query = "INSERT INTO bank_visit_loan(Loan_ID,Approved_By,Requested_BY) VALUES($Loan_ID,$User,$RequestBy) ";
$result = $conn->query($query);
if ( !$result ) {
//$result->free();
throw new Exception($conn->error);
}
$query = "INSERT INTO transaction_detail(Account_No,Amount,Withdraw,Balance,Detail,Teller) VALUES($AccNo,$Amount,False,1000,'Loan Granted','self')";
$result = $conn->query($query);
if ( !$result ) {
// $result->free();
throw new Exception($conn->error);
}
$query = "UPDATE requested_loan SET Request_Status='Approved' WHERE Request_ID=$RequestID";
$result = $conn->query($query);
if ( !$result ) {
//$result->free();
throw new Exception($conn->error);
}
$query = "UPDATE account SET Balance=Balance+".$Amount." WHERE Account_No=$AccNo";
$result = $conn->query($query);
if ( !$result ) {
//$result->free();
throw new Exception($conn->error);
}
$query = "CREATE EVENT settleInstallment5 ON SCHEDULE EVERY 1 MINUTE STARTS '2020-01-02 00:00:00' DO INSERT INTO transaction_details(Account_No,Amount,Withdraw,Balance,Detail,Teller) VALUES($AccNo,$Amount,True,1000,'Installment','Self');
SET GLOBAL event_scheduler='ON';";
$result = $conn->multi_query($query);
if ( !$result ) {
$result->free();
throw new Exception($conn->error);
}
// our SQL queries have been successful. commit them
// and go back to non-transaction mode.
$conn->commit();
$conn->autocommit(TRUE); // i.e., end transaction
echo "<h1>Loan Approved</h1>";
echo '<br><b>Loan Details</b>';
echo '<br>Loan ID : '.$Loan_ID;
echo '<br>Account No : '.$AccNo;
echo '<br>Amount: '.$Amount;
echo '<br>Branch ID : '.$Branch;
echo '<br>Time Period : '.$Time_Period;
echo '<br>Installment : '.$Installment;
echo '<br>Date Created : '.date("Y-m-d");
unset($_SESSION['AccNo']);
echo '<br>';
echo '<button onclick="myFunction()">Print this page</button>';
echo '<br><br>';
echo '<button onclick="window.location.href = \'home.php\';">Home</button>';
}
catch ( Exception $e ) {
// before rolling back the transaction, you'd want
// to make sure that the exception was db-related
$conn->rollback();
$conn->autocommit(TRUE); // i.e., end transaction
}
?>
</body>
</html>