-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcron.php
More file actions
30 lines (19 loc) · 938 Bytes
/
cron.php
File metadata and controls
30 lines (19 loc) · 938 Bytes
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
<?php
$FINE_AMT = "0.25";
include('config.php');
echo "Cron for updating daily fine.\n";
$query = "SELECT *, DATEDIFF(NOW(), due_date) AS due_days, (DATEDIFF(CURDATE(), due_date)* $FINE_AMT) AS fine FROM `book_loans` WHERE date_in = '0000-00-00' AND due_date < NOW()";
$result = mysql_query($query);
$num = mysql_num_rows($result);
echo "Found $num pending fines\n";
while ($row = mysql_fetch_array($result)) {
print "Updating fine for loan_id #{$row['loan_id']} fine {$row['fine']}\n";
$query = "SELECT * FROM fines WHERE loan_id = {$row['loan_id']} AND paid = 0";
$rs = mysql_query($query);
$query = "INSERT INTO fines (loan_id, fine_amt, paid) VALUES ( {$row['loan_id']}, {$row['fine']}, 0 )";
if(mysql_num_rows($rs) > 0) {
$query = "UPDATE fines SET fine_amt = {$row['fine']} WHERE loan_id = {$row['loan_id']} AND paid = 0";
}
echo "Updated\n";
mysql_query($query);
}