adding org unit settings to block or provide default elbow room for circs; logic...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 8 Dec 2009 19:08:32 +0000 (19:08 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 8 Dec 2009 19:08:32 +0000 (19:08 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15104 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Booking.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/095.schema.booking.sql
Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql [new file with mode: 0644]

index 8280fee..7582bfc 100644 (file)
@@ -2507,6 +2507,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Return Time" name="return_time" reporter:datatype="timestamp"/>
                        <field reporter:label="Booking Interval" name="booking_interval" reporter:datatype="interval"/>
                        <field reporter:label="Fine Interval" name="fine_interval" reporter:datatype="interval"/>
+                       <field reporter:label="Inter-booking Interval" name="elbow_room" reporter:datatype="interval"/>
                        <field reporter:label="Fine Amount" name="fine_amount" reporter:datatype="money"/>
                        <field reporter:label="Max Fine Amount" name="max_fine" reporter:datatype="money"/>
                        <field reporter:label="Target Resource Type" name="target_resource_type" reporter:datatype="link"/>
index b81e4ca..4fddac8 100644 (file)
@@ -297,7 +297,7 @@ sub reservation_list_by_filters {
         'select'   => { bresv => [ 'id' ] },
         'from'     => { bresv => {} },
         'where'    => {},
-        'order_by' => [{ class => bresv => field => start_time => direction => 'asc' }]
+        'order_by' => [{ class => bresv => field => start_time => direction => 'asc' }],
         'distinct' => 1
     };
 
index 26ebdea..7a294ce 100644 (file)
@@ -1214,7 +1214,10 @@ sub do_checkout {
     $self->build_checkout_circ_object();
     return if $self->bail_out;
 
-    $self->apply_modified_due_date();
+    my $modify_to_start = $self->booking_adjusted_due_date();
+    return if $self->bail_out;
+
+    $self->apply_modified_due_date($modify_to_start);
     return if $self->bail_out;
 
     return $self->bail_on_events($self->editor->event)
@@ -1589,8 +1592,77 @@ sub build_checkout_circ_object {
 }
 
 
+sub booking_adjusted_due_date {
+    my $self = shift;
+    my $circ = $self->circ;
+    my $copy = $self->copy;
+
+
+    my $changed;
+
+    if( $self->due_date ) {
+
+        return $self->bail_on_events($self->editor->event)
+            unless $self->editor->allowed('CIRC_OVERRIDE_DUE_DATE', $self->circ_lib);
+
+       $circ->due_date(clense_ISO8601($self->due_date));
+
+    } else {
+
+        return unless $copy and $circ->due_date;
+    }
+
+    if (my $booking_item = $self->editor->search_booking_resource( { barcode => $copy->barcode } )) {
+        my $resource_type = $self->editor->retrieve_booking_resource_type( $booking_item->resource_type );
+
+        my $stop_circ_setting = $U->ou_ancestor_setting_value( $self->circ_lib, 'circ.booking_reservation.stop_circ', $self->editor );
+        my $shorten_circ_setting = $resource_type->elbow_room ||
+            $U->ou_ancestor_setting_value( $self->circ_lib, 'circ.booking_reservation.default_elbow_room', $self->editor ) ||
+            '0 seconds';
+
+        my $booking_ses = OpenSRF::AppSession->create( 'open-ils.booking' );
+        my $bookings = $booking_ses->request(
+            'open-ils.booking.reservations.filtered_id_list',
+            { resource => $booking_item->id, start_time => 'now', end_time => $circ->due_date }
+        )->gather(1);
+        $booking_ses->disconnect;
+        
+        my $dt_parser = DateTime::Format::ISO8601->new;
+        my $due_date = $dt_parser->parse_datetime( clense_ISO8601($circ->due_date) );
+
+        for my $bid (@$bookings) {
+
+            my $booking = $self->editor->retrieve_booking_reservation( $bid );
+
+            my $booking_start = $dt_parser->parse_datetime( clense_ISO8601($booking->start_time) );
+            my $booking_end = $dt_parser->parse_datetime( clense_ISO8601($booking->end_time) );
+
+            return $self->bail_on_events( OpenILS::Event->new('COPY_RESERVED') )
+                if ($booking_start < DateTime->now);
+
+
+            if ($U->is_true($stop_circ_setting)) {
+                $self->bail_on_events( OpenILS::Event->new('COPY_RESERVED') ); 
+            } else {
+                $due_date = $booking_start->subtract( seconds => interval_to_seconds($shorten_circ_setting) );
+                $self->bail_on_events( OpenILS::Event->new('COPY_RESERVED') ) if ($due_date < DateTime->now); 
+            }
+            
+            $circ->due_date(clense_ISO8601($due_date->strftime('%FT%T%z')));
+            $self->due_date($circ->due_date);
+            $changed = 1;
+        }
+
+        return $self->bail_on_events($self->editor->event)
+            unless $self->editor->allowed('CIRC_OVERRIDE_DUE_DATE', $self->circ_lib);
+    }
+
+    return $changed;
+}
+
 sub apply_modified_due_date {
     my $self = shift;
+    my $shift_earlier = shift;
     my $circ = $self->circ;
     my $copy = $self->copy;
 
@@ -1625,7 +1697,11 @@ sub apply_modified_due_date {
 
             # XXX make the behavior more dynamic
             # for now, we just push the due date to after the close date
-            $circ->due_date($dateinfo->{end});
+            if ($shift_earlier) {
+                $circ->due_date($dateinfo->{start});
+            } else {
+                $circ->due_date($dateinfo->{end});
+            }
       }
    }
 }
index e29b0ba..9ed28a4 100644 (file)
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0108'); -- berick
+INSERT INTO config.upgrade_log (version) VALUES ('0110'); -- miker
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index 2b31b3b..3a878a8 100644 (file)
@@ -23,6 +23,7 @@ CREATE SCHEMA booking;
 CREATE TABLE booking.resource_type (
        id             SERIAL          PRIMARY KEY,
        name           TEXT            NOT NULL,
+       elbow_room     INTERVAL,
        fine_interval  INTERVAL,
        fine_amount    DECIMAL(8,2)    NOT NULL DEFAULT 0,
        max_fine       DECIMAL(8,2),
diff --git a/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql b/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql
new file mode 100644 (file)
index 0000000..479f615
--- /dev/null
@@ -0,0 +1,20 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0109'); --miker
+
+INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
+    'circ.booking_reservation.stop_circ',
+    'Disallow circulation of items when they are on booking reserve and that reserve overlaps with the checkout period',
+    'When true, items on booking reserve during the proposed checkout period will not be allowed to circulate unless overridden with the COPY_RESERVED.override permission.',
+    'bool'
+);
+
+INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
+    'circ.booking_reservation.default_elbow_room',
+    'Default amount of time by which a circulation should be shortened to allow for booking reservation delivery',
+    'When an item is on booking reserve, and that reservation overlaps with the proposed checkout period, and circulations have not been strictly disallowed on reserved items, Evergreen will attempt to adjust the due date of the circulation for this about of time before the beginning of the reservation period.  If this is not possible because the due date would end up in the past, the circulation is disallowed.',
+    'interval'
+);
+
+COMMIT;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql b/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql
new file mode 100644 (file)
index 0000000..69e98e5
--- /dev/null
@@ -0,0 +1,8 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0110'); --miker
+
+ALTER TABLE booking.resource_type ADD COLUMN elbow_room INTERVAL;
+
+COMMIT;
+