From 1fc74df81c30fa4a0b48d2a8bbec02ccaa8ce8c0 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 22 Dec 2009 21:30:14 +0000 Subject: [PATCH] check-in time booking reservation transit receive and op-capture ... no, gmcharlt, say THAT 3 times fast! git-svn-id: svn://svn.open-ils.org/ILS/trunk@15228 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Circ/Circulate.pm | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 4fbdc74687..b67443db7f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -2,10 +2,12 @@ package OpenILS::Application::Circ::Circulate; use strict; use warnings; use base 'OpenILS::Application'; use OpenSRF::EX qw(:try); +use OpenSRF::AppSession; use OpenSRF::Utils::SettingsClient; use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Const qw/:const/; use OpenILS::Application::AppUtils; +use DateTime; my $U = "OpenILS::Application::AppUtils"; my %scripts; @@ -176,6 +178,92 @@ sub run_method { return circ_events($circulator) if $circulator->bail_out; # -------------------------------------------------------------------------- + # First, check for a booking transit, as the barcode may not be a copy + # barcode, but a resource barcode, and nothing else in here will work + # -------------------------------------------------------------------------- + + if (my $bc = $circulator->copy_barcode) { # do we have a barcode? + my $resources = $circulator->editor->search_booking_resource( { barcode => $bc } ); # any resources by this barcode? + if (@$resources) { # yes! + + my $res_id_list = [ map { $_->id } @$resources ]; + my $transit = $circulator->editor->search_action_reservation_transit_copy( + [ + { target_copy => $res_id_list, dest => $circulator->circ_lib }, + { order_by => { artc => 'source_send_time' }, limit => 1 } + ] + )->[0]; # Any transit for this barcode? + + if ($transit) { # yes! unwrap it. + + my $reservation = $circulator->editor->retrieve_booking_reservation( $transit->reservation ); + my $res_type = $circulator->editor->retrieve_booking_resource_type( $reservation->target_reservation_type ); + + if ($U->is_true($res_type->catalog_item)) { # is there a copy to be had here? + if (my $copy = circulator->editor->search_asset_copy({ barcode => $bc, deleted => 'f' })->[0]) { # got a copy + $copy->status( $transit->copy_status ); + $copy->editor($self->editor->requestor->id); + $copy->edit_date('now'); + $circulator->editor->update_asset_copy( $copy ); + } + } + + $transit->dest_recv_time('now'); + $circulator->editor->update_action_reservation_transit_copy( $transit ); + + $circulator->editor->commit; + + #XXX need to return here, with info about the resource/copy and the "put it on the booking shelf" message + + } else { # no transit, look for an upcoming reservation to capture for + + my $reservation = $circulator->editor->search_booking_reservation( + [ + { current_resource => $res_id_list, + pickup_lib => $circulator->circ_lib, + cancel_time => undef, + capture_time => undef + }, + { order_by => { bresv => 'start_time' }, limit => 1 } + ] + )->[0]; + + if ($reservation) { # we have a reservation for which we could capture this resource. wheee! + my $res_type = $circulator->editor->retrieve_booking_resource_type( $reservation->target_reservation_type ); + my $elbow_room = $res_type->elbow_room || + $U->ou_ancestor_setting_value( $circulator->circ_lib, 'circ.booking_reservation.default_elbow_room', $circulator->editor ); + + if ($elbow_room) { + $reservation = $circulator->editor->search_booking_reservation( + [ + { id => $reservation->id, start_time => { '<=' => DateTime->now->add( seconds => interval_to_seconds($elbow_room) )->strftime('%FT%T%z') } }, + { order_by => { bresv => 'start_time' }, limit => 1 } + ] + )->[0]; + } + + if ($reservation) { # no elbow room specified, or we still have a reservation within the elbow_room time + my $b_ses = OpenSRF::AppSession->create('open-ils.booking'); + my $result = $b_ses->request( + 'open-ils.booking.reservation.capture', + $auth => $reservation->id + )->gather(1); + + if (ref($result) && $result->{ilsevent} == 0) { # captured! + #XXX what to return here??? + return $result; # the booking capture success + } else { + #XXX how to fail??? Probably, just move on. + } + } + } + } + } + } + + + + # -------------------------------------------------------------------------- # Go ahead and load the script runner to make sure we have all # of the objects we need # -------------------------------------------------------------------------- -- 2.11.0