-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookReturnTranscation.php
74 lines (57 loc) · 1.91 KB
/
bookReturnTranscation.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
<?php
require "dbConnect.php";
require "books.php";
require "student.php";
require "Transcations.php";
$databaseConnection = new DatabaseConnection;
$book = new Books;
$student = new Students;
$transcation = new Transcations;
$databaseConnection->tempConnection();
$transcationId = $returnDate = $bookId =$updatedBookCopies = $stdId = "";
$dueDate = "";
if(!empty($_GET["transcationId"])){
$transcationId = $_GET["transcationId"];
$returnDate = $_GET["returnDate"];
}
echo $transcationId;
$sql = "SELECT * from Transcation WHERE transcationId = $transcationId ";
$result = mysqli_query($databaseConnection->conn1, $sql);
if(mysqli_num_rows($result) > 0) {
while($row=mysqli_fetch_assoc($result)){
$bookId = $row['bookID'];
$stdId = $row['stdid'];
$dueDate = $row['dueDate'];
}
}
$sqlBook = "SELECT * from Book where bookID = $bookId ";
$resultBook = mysqli_query($databaseConnection->conn1, $sqlBook);
if(mysqli_num_rows($resultBook) > 0) {
while($row=mysqli_fetch_assoc($resultBook)){
$updatedBookCopies = $row['NumOfCopies'];
$updatedBookCopies = $updatedBookCopies + 1;
}
}
$sqlStudent = "SELECT * from Student where stdid = $stdId ";
$resultStudent = mysqli_query($databaseConnection->conn1, $sqlStudent);
if(mysqli_num_rows($resultStudent) > 0) {
while($row=mysqli_fetch_assoc($resultStudent)){
$numOfBooksRent = $row['numOfBooksRent'];
$numOfBooksRent = $numOfBooksRent + 1;
}
}
// if($returnDate>$dueDate){
// }else{
// }
// $returnDate = '2017-11-29';
// $fineAmount = 3.0 * (($returnDate - $dueDate)/(1000 * 60 * 60 * 24));
// echo $fineAmount;
$transcation->updateTranscationReturnDate($transcationId,$returnDate);
$book->updateBookQuantity($bookId,$updatedBookCopies);
$student->updateStudentBookQuantity($stdId,$numOfBooksRent);
echo "<script>
alert('Book Returned Succesfully');
window.location.href='userIndex.php';
</script>";
exit();
?>