[open-ils-commits] r1456 - hekman (dbwells)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue May 24 12:02:52 EDT 2011
Author: dbwells
Date: 2011-05-24 12:02:49 -0400 (Tue, 24 May 2011)
New Revision: 1456
Added:
hekman/void_backdate_into_grace_bills.pl
Log:
Basic (i.e. hard-coded and quickly written) script for finding and voiding
any backdate-into-grace fines. If you wish to try it, you should (at least):
1. get a real $dbh for your DB
2. change the '3 days' in the SQL to match your grace period
3. change the 'default' for recurring_fine_rule to match your rule name
Added: hekman/void_backdate_into_grace_bills.pl
===================================================================
--- hekman/void_backdate_into_grace_bills.pl (rev 0)
+++ hekman/void_backdate_into_grace_bills.pl 2011-05-24 16:02:49 UTC (rev 1456)
@@ -0,0 +1,83 @@
+#!/usr/bin/perl
+# When we backdate into a grace period (3 days), we must void bills which happened in that period
+# By Dan Wells & Remington Steed
+
+use strict;
+use Data::Dumper;
+use HekmanDBI;
+
+my $dbh = HekmanDBI->get_dbh();
+
+my $date = `date`;
+chomp($date);
+print "'Void Backdate-into-Grace Billings' started $date.\n\n";
+
+# main function
+my ($bill_count, $trans_count) = &void_backdate_billings();
+print "Updated $bill_count billings and $trans_count transactions.\n\n";
+
+$date = `date`;
+chomp($date);
+print "'Void Backdate-into-Grace Billings' finished $date.\n";
+
+exit;
+
+
+sub void_backdate_billings {
+ my $bill_count = 0;
+ my $trans_count = 0;
+
+ my $sql = <<" SQL";
+ SELECT mb.id,ac.id,stop_fines
+ FROM action.circulation ac
+ JOIN money.billing mb
+ ON mb.xact = ac.id
+ WHERE stop_fines_time - due_date <= '3 days'
+ AND stop_fines_time > due_date
+ AND voided IS FALSE
+ AND xact_finish IS NULL
+ AND checkin_time IS NOT NULL
+ AND btype = 1
+ AND recurring_fine_rule = 'default';
+ SQL
+
+ my $sth = $dbh->prepare_cached($sql);
+ $sth->execute();
+
+ my $bill_rows = $sth->fetchall_arrayref;
+
+ $sql = <<" SQL";
+ UPDATE money.billing
+ SET voided = 't',
+ voider = 1,
+ void_time = now(),
+ note = note || '\nSystem: VOIDED FOR BACKDATE-INTO-GRACE'
+ WHERE id = ?;
+ SQL
+
+ $sth = $dbh->prepare($sql);
+ my %checkin_xacts;
+ foreach my $bill (@$bill_rows) {
+ $bill_count++;
+ print "Voiding ",$bill->[0],"\n";
+ $sth->execute($bill->[0]);
+ if ($bill->[2] eq 'CHECKIN') {
+ $checkin_xacts{$bill->[1]} = 1;
+ }
+ }
+
+ $sql = <<" SQL";
+ UPDATE action.circulation
+ SET xact_finish = now()
+ WHERE id = ?;
+ SQL
+
+ $sth = $dbh->prepare($sql);
+ foreach my $xact_id (keys %checkin_xacts) {
+ print "Closing $xact_id \n";
+ $trans_count++;
+ $sth->execute($xact_id);
+ }
+
+ return $bill_count, $trans_count;
+}
Property changes on: hekman/void_backdate_into_grace_bills.pl
___________________________________________________________________
Name: svn:executable
+ *
More information about the open-ils-commits
mailing list