From 2111d6cb66654966b55f2dbcc6b9f89b6721e668 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 5 Mar 2014 13:03:09 +1300 Subject: [PATCH] Working on AcceptItem handler .. don't expect this to work just yet --- lib/NCIP/Handler/AcceptItem.pm | 62 ++++++++++++++++++++++++++++++++++++++++++ lib/NCIP/ILS/Koha.pm | 19 ++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 lib/NCIP/Handler/AcceptItem.pm diff --git a/lib/NCIP/Handler/AcceptItem.pm b/lib/NCIP/Handler/AcceptItem.pm new file mode 100644 index 0000000..3c120eb --- /dev/null +++ b/lib/NCIP/Handler/AcceptItem.pm @@ -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; diff --git a/lib/NCIP/ILS/Koha.pm b/lib/NCIP/ILS/Koha.pm index 7137082..9132e29 100644 --- a/lib/NCIP/ILS/Koha.pm +++ b/lib/NCIP/ILS/Koha.pm @@ -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; -- 2.11.0