Working on AcceptItem handler .. don't expect this to work just yet
authorChris Cormack <chrisc@catalyst.net.nz>
Wed, 5 Mar 2014 00:03:09 +0000 (13:03 +1300)
committerChris Cormack <chrisc@catalyst.net.nz>
Wed, 5 Mar 2014 00:03:09 +0000 (13:03 +1300)
lib/NCIP/Handler/AcceptItem.pm [new file with mode: 0644]
lib/NCIP/ILS/Koha.pm

diff --git a/lib/NCIP/Handler/AcceptItem.pm b/lib/NCIP/Handler/AcceptItem.pm
new file mode 100644 (file)
index 0000000..3c120eb
--- /dev/null
@@ -0,0 +1,62 @@
+package NCIP::Handler::AccpetItem;
+
+=head1
+
+  NCIP::Handler::AcceptItem
+
+=head1 SYNOPSIS
+
+    Not to be called directly, NCIP::Handler will pick the appropriate Handler 
+    object, given a message type
+
+=head1 FUNCTIONS
+
+=cut
+
+use Modern::Perl;
+
+use NCIP::Handler;
+
+our @ISA = qw(NCIP::Handler);
+
+sub handle {
+    my $self   = shift;
+    my $xmldoc = shift;
+    if ($xmldoc) {
+        my $root = $xmldoc->documentElement();
+        my $xpc  = XML::LibXML::XPathContext->new;
+        $xpc->registerNs( 'ns', $self->namespace() );
+        my $itemid =
+          $xpc->findnodes( 'ns:AcceptItem/UniqueItemId/ItemIdentifierValue',
+            $root );
+
+        # checkin the item
+        my $accepted = $self->ils->acceptitem($itemid);
+        my $output;
+        my $vars;
+        my ( $from, $to ) = $self->get_agencies($xmldoc);
+
+        # we switch these for the templates
+        # because we are responding, to becomes from, from becomes to
+        $vars->{'fromagency'} = $to;
+        $vars->{'toagency'}   = $from;
+
+        $vars->{'messagetype'} = 'AcceptItemResponse';
+        $vars->{'barcode'}     = $itemid;
+        if ( !$accepted->{success} ) {
+            $vars->{'processingerror'}        = 1;
+            $vars->{'processingerrortype'}    = $accepted->{'messages'};
+            $vars->{'processingerrorelement'} = 'UniqueItemIdentifier';
+            $output = $self->render_output( 'problem.tt', $vars );
+        }
+        else {
+            my $elements = $self->get_user_elements($xmldoc);
+            $vars->{'elements'} = $elements;
+            $vars->{'checkin'}  = $checkin;
+            $output = $self->render_output( 'response.tt', $vars );
+        }
+        return $output;
+    }
+}
+
+1;
index 7137082..9132e29 100644 (file)
@@ -23,7 +23,7 @@ use C4::Members qw{ GetMemberDetails };
 use C4::Circulation qw { AddReturn CanBookBeIssued AddIssue };
 use C4::Context;
 use C4::Items qw { GetItem };
-use C4::Reserves qw {CanBookBeReserved AddReserve };
+use C4::Reserves qw {CanBookBeReserved AddReserve GetReservesFromItemnumber};
 
 sub itemdata {
     my $self     = shift;
@@ -139,4 +139,21 @@ sub request {
         return ( 1, "Book can not be requested" );
     }
 }
+
+sub acceptitem {
+    my $self    = shift;
+    my $barcode = shift;
+    my $result;
+
+    # find hold and get branch for that, check in there
+    my $itemdata = GetItem( undef, $barcode );
+    my ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $wait ) =
+      GetReservesFromItemnumber( $itemdata->{'itemnumber'} );
+    unless ($reserve_id) {
+        $result = { success => 0, messages => 'No hold found for that item' };
+        return $result;
+    }
+    $result = $self->checkin( $barcode, $branch );
+    return $result;
+}
 1;