Limit due date by patron expire date user/jeffdavis/lp1046420
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 31 Oct 2012 18:57:08 +0000 (11:57 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 31 Oct 2012 18:57:08 +0000 (11:57 -0700)
This is a fix for Launchpad bug #1046420.

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.data.due-date-patron-expiry-settings.sql [new file with mode: 0644]

index 1be90e9..cd0e320 100644 (file)
     <event code='7027' textcode='PATRON_PASSWORD_WAS_NOT_STRONG'>
         <desc xml:lang='en-US'>The user attempted to set their password to a weak value.</desc>
     </event>
+    <event code='7028' textcode='DUE_DATE_EXCEEDS_PATRON_EXPIRY'>
+        <desc xml:lang='en-US'>The patron account expires before the circulation due date.</desc>
+    </event>
 
 
        <!-- ================================================================ -->
index 83a46a8..c111118 100644 (file)
@@ -1523,6 +1523,9 @@ sub do_checkout {
     $self->apply_modified_due_date($modify_to_start);
     return if $self->bail_out;
 
+    $self->limit_to_expire_date();
+    return if $self->bail_out;
+
     return $self->bail_on_events($self->editor->event)
         unless $self->editor->create_action_circulation($self->circ);
 
@@ -2247,6 +2250,35 @@ sub apply_modified_due_date {
 
 
 
+sub limit_to_expire_date {
+    my $self = shift;
+    my $due_date = DateTime::Format::ISO8601
+        ->new
+        ->parse_datetime( OpenSRF::Utils::clense_ISO8601($self->circ->due_date) )
+        ->epoch;
+    my $expire_date = DateTime::Format::ISO8601
+        ->new
+        ->parse_datetime( OpenSRF::Utils::clense_ISO8601($self->patron->expire_date) )
+        ->epoch;
+
+    if ($expire_date < $due_date) {
+
+        # does this circ lib want to limit due date by expiry date? check settings to find out...
+        my $do_limit = $U->ou_ancestor_setting_value($self->circ->circ_lib, 'circ.limit_to_patron_expire_date');
+        my $warn_on_limit = $U->ou_ancestor_setting_value($self->circ->circ_lib, 'circ.warn_on_limit_by_expire_date');
+
+        # TODO: handle ($do_limit && $warn_on_limit)
+        if ($do_limit) {
+            $self->circ->due_date($self->patron->expire_date);
+        } elsif ($warn_on_limit) {
+            # TODO: permit override, don't just throw an error
+            $self->bail_on_events(OpenILS::Event->new('DUE_DATE_EXCEEDS_PATRON_EXPIRY'));
+        }
+    }
+}
+
+
+
 sub create_due_date {
     my( $self, $duration, $date_ceiling, $force_date ) = @_;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.due-date-patron-expiry-settings.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.due-date-patron-expiry-settings.sql
new file mode 100644 (file)
index 0000000..e72e00c
--- /dev/null
@@ -0,0 +1,20 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO config.org_unit_setting_type (
+    name, label, grp, datatype
+) VALUES (
+    'circ.limit_to_patron_expire_date',
+    'Limit due date by patron expire date',
+    'circ',
+    'bool'
+),
+(
+    'circ.warn_on_limit_by_expire_date',
+    'Warn when limiting due date by patron expire date',
+    'circ',
+    'bool'
+);
+
+COMMIT;