-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfines.php
More file actions
268 lines (214 loc) · 9.47 KB
/
fines.php
File metadata and controls
268 lines (214 loc) · 9.47 KB
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
<html>
<head> <center> <h1>Library Management System</h1> </center>
<link rel="stylesheet" type="text/css" href="style.css">
<title> Library Management System </title>
</head>
<body>
<h2><left><a href="Page1.html">Homepage</a></left></h2>
<form name="check" method="post">
<h1> <center> Fines </center> </h1>
<center> <table>
<tr>
<th>Name</th>
<th>Card No.</th>
<th>Fine</th>
<th>Paid</th>
</tr>
<?php
$con = mysql_connect("localhost", "root", "");
if ($con) {
mysql_select_db("library");
} else {
echo 'could not connect' . "<br/>";
}
if($_POST)
{
if(isset($_POST['refresh']))
{
refresh();
}
elseif (isset($_POST['filter_fines']))
{
filter_fine();
}
/*elseif (isset ($_POST['estimate']))
{
estimate_fine();
}
elseif(isset ($_POST['fine_paid']))
{
pay_fine();
}*/
}
function refresh()
{
$query_fine_insert = "insert into fines(loan_id,fine_amt) select loan_id, datediff(date_in,due_date)*0.25 as amt from book_loans
where date_in > due_date or current_date> due_date;";
mysql_query($query_fine_insert);
$query_update = "update fines set paid = 1 where fine_amt > 0.0";
mysql_query($query_update);
$query_refresh = "select c.loan_id,b.card_no,sum(c.fine_amt) as total_fine, a.fname , a.lname, c.paid
from borrower a,book_loans b ,fines c
where a.card_no = b.card_no
and c.loan_id = b.loan_id
group by b.card_no;";
$result = mysql_query($query_refresh);
if($result === FALSE)
{
mysql_error();
echo "<script type='text/javascript'> alert('no data');</script>";
}
else{
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" .$row['fname']. ' ' .$row['lname']. "</td>";
echo "<td><center>" .$row['card_no']. "</center></td>";
echo "<td>" .$row['total_fine']. "</td>";
echo "<td><center>" .$row['paid']. "</center></td>";
echo "</tr>";
}
}
}
function filter_fine()
{
$query_filter = "select c.loan_id,b.card_no,sum(c.fine_amt) as total_fine, a.fname , a.lname, c.paid
from borrower a,book_loans b ,fines c
where a.card_no = b.card_no
and c.loan_id = b.loan_id and c.paid = 0
group by b.card_no;";
$result = mysql_query($query_filter);
if($result === FALSE)
{
mysql_error();
echo "<script type='text/javascript'> alert('no data');</script>";
}
else{
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" .$row['fname']. ' ' .$row['lname']. "</td>";
echo "<td><center>" .$row['card_no']. "</center></td>";
echo "<td>$" .$row['total_fine']. "</td>";
echo "<td><center>" .$row['paid']. "</center></td>";
echo "</tr>";
}
}
}
?>
<tr>
<td><input type="submit" name="refresh" value="Refresh"/></td>
<td><input type="submit" name="filter_fines" value="Previous Fines"</td>
</tr>
<tr>
<td> 0 - Paid</td>
<td>1 - Unpaid</td>
</tr>
</table></center>
<br><br><br><br>
<center><table cellspacing="15">
<tr>
<td>Card No.</td>
<td>Total Fine</td>
</tr>
<?php
if($_POST)
{
if (isset ($_POST['estimate']))
{
estimate_fine();
}
elseif(isset ($_POST['fine_paid']))
{
pay_fine();
}
}
function estimate_fine()
{
$cardno = $_POST['card_no'];
$estimate = "Select a.card_no, sum(b.fine_amt) as total_fine, a.date_in from book_loans a,fines b
where a.card_no = '$cardno' and a.loan_id = b.loan_id
group by a.card_no;";
$result = mysql_query($estimate);
if($result === FALSE)
{
mysql_error();
echo "<script type='text/javascript'> alert('no data');</script>";
}
else{
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td><center>" .$row['card_no']. "</center></td>";
echo "<td>$" .$row['total_fine']. "</td>";
//echo "<td>" .$row['date_in']. "</td>";
echo "</tr>";
}
}
}
function pay_fine()
{
$cardno = $_POST['card_no'];
$check = "select date_in from book_loans where card_no in('$cardno')";
$check_result = mysql_query($check);
if($check_result === FALSE)
{
echo mysql_error();
}
else{
while($rows = mysql_fetch_assoc($check_result))
{
if($rows['date_in'] === NULL)
{
echo "<script type='text/javascript'> alert('Book is yet to be checked in')</script>";
}
else{
pay_fine_final($cardno);
}
}
}
}
function pay_fine_final($cardno1)
{
$cardno = $cardno1;
$pay = "update fines set fine_amt=0.0, paid= 0 where loan_id IN (
Select loan_id from book_loans where card_no = '$cardno' group by card_no);";
$result = mysql_query($pay);
if($result === FALSE)
{
mysql_error();
echo "<script type='text/javascript'> alert('no data');</script>";
}
else{
$check = "select paid from fines where loan_id in (select loan_id from book_loans where card_no= '$cardno' group by card_no);";
$result1 = mysql_query($check);
while($row = mysql_fetch_assoc($result1))
{
if($row['paid'] === '0')
{
echo "<script type='text/javascript'> alert('Fine Already Paid')</script>";
}
else
{
echo "<script type='text/javascript'> alert('Fine Paid')</script>";
}
}
}
}
?>
<tr>
<td>Card No:</td>
<td> <input type="text" name="card_no" id="card_no"/> </td>
</tr>
<tr>
<td> </td>
<td><!--<input type="submit" name="search" value="Search"/>-->
<input type="submit" name="estimate" value="Estimate"/>
<input type="submit" name="fine_paid" value="Pay"/></td>
</tr>
</table></center>
</form>
<?php
?>
</body>
</html>