Expand the conditions where we set the due_time to 23:59:59.
authordbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 9 Jul 2009 20:41:44 +0000 (20:41 +0000)
committerdbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 9 Jul 2009 20:41:44 +0000 (20:41 +0000)
Starting to wonder whether I should just change the edit due date function to set 23:59 instead...

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/trunk@575 6d9bc8c9-1ec2-4278-b937-99fde70a366f

tools/end_of_the_day.pl

index d3d84ca..fafe56d 100644 (file)
@@ -7,6 +7,13 @@
 # with an overdue charge at 48 hours + 5 minutes rather than at the end of the
 # day that 48 hours falls on.
 
+# We also found that editing the due date for a given item sets the corresponding
+# due time to 00:00 - which isn't great, as that means that it is due the minute
+# the day starts. So, for now, we'll set all daily / weekly loans or those loans
+# that are due exactly at midnight to being due at 23:59:59 - the very last second
+# of the day on which it is due. This probably meets our patrons' expectations a bit
+# better.
+
 use DBI;
 use Getopt::Long;
 use OpenSRF::EX qw/:try/;
@@ -43,34 +50,55 @@ $dbh->disconnect;
 sub end_of_day {
        my $set_due_time = shift;
 
-       my $select_stmt = <<STMT;
+        my $select_stmt = <<STMT;
                SELECT id
                FROM action.circulation
                WHERE checkin_time IS NULL
-               AND due_date::TIME WITH TIME ZONE != '23:59:59-04'
-                AND duration_rule = '48_hours_2_renew'
-               AND circ_lib = 103
+               AND (
+                       (
+                               due_date::TIME != '23:59:59'
+                               AND duration_rule LIKE ('%days%')
+                               OR duration_rule LIKE ('%weeks%')
+                               OR duration_rule = '48_hours_2_renew'
+                       ) OR (
+                               due_date::TIME = '00:00:00'
+                       )
+               ) AND circ_lib IN (
+                       SELECT id
+                       FROM actor.org_unit
+                       WHERE parent_ou = 105
+               )
 STMT
 
-       my $update_stmt = <<UPDATE;
-               UPDATE action.circulation
-               SET due_date = CAST(due_date::DATE || ' ' || '23:59:59-04' AS TIMESTAMP WITH TIME ZONE) 
+        my $update_stmt = <<UPDATE;
+                UPDATE action.circulation
+                SET due_date = CAST(due_date::DATE || ' ' || '23:59:59-04' AS TIMESTAMP WITH TIME ZONE)
                WHERE checkin_time IS NULL
-               AND due_date::TIME WITH TIME ZONE != '23:59:59-04'
-               AND duration_rule = '48_hours_2_renew'
-               AND circ_lib = 103
-UPDATE
-
-
-       my @results = $dbh->selectrow_array($select_stmt);
-       print localtime() . " - found " . scalar(@results) . " circulation transactions to update:\n";
-       foreach (@results) {
-               print "\t$_\n";
-       }
-       if ($set_due_time) {
-               my $stmt = $dbh->prepare($update_stmt);
-               my $updates = $stmt->execute();
-               print "Updated $updates circulation transactions.\n";
-       }
+               AND (
+                       (
+                               due_date::TIME != '23:59:59'
+                               AND duration_rule LIKE ('%days%')
+                               OR duration_rule LIKE ('%weeks%')
+                               OR duration_rule = '48_hours_2_renew'
+                       ) OR (
+                               due_date::TIME = '00:00:00'
+                       )
+               ) AND circ_lib IN (
+                       SELECT id
+                       FROM actor.org_unit
+                       WHERE parent_ou = 105
+               )
+UPDATE  
+
+
+        my $results = $dbh->selectcol_arrayref($select_stmt);
+        print localtime() . " - found " . scalar(@$results) . " circulation transactions to update:\n";
+        foreach (@$results) {
+                print "\t$_\n";
+        }
+        if ($set_due_time) {
+                my $stmt = $dbh->prepare($update_stmt);
+                my $updates = $stmt->execute();
+                print "Updated $updates circulation transactions.\n";
+        }
 }
-