From ec2519da160ecd2c258c4e630aa1d5bda043275d Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 28 Jan 2014 11:35:13 +1300 Subject: [PATCH] Got CheckOutItem going --- lib/NCIP/Handler/CheckOutItem.pm | 9 +++-- lib/NCIP/ILS/Koha.pm | 56 ++++++++++++++++++++++------- templates/includes/CheckOutItemResponse.inc | 5 ++- templates/problem.tt | 6 +++- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/lib/NCIP/Handler/CheckOutItem.pm b/lib/NCIP/Handler/CheckOutItem.pm index 4c40a9f..c4d6052 100644 --- a/lib/NCIP/Handler/CheckOutItem.pm +++ b/lib/NCIP/Handler/CheckOutItem.pm @@ -31,20 +31,23 @@ sub handle { my @elements = $root->findnodes('CheckOutItem/ItemElementType/Value'); # checkout the item - my ( $error, $messages ) = $self->ils->checkout( $userid, $itemid ); + my ( $error, $messages, $datedue ) = $self->ils->checkout( $userid, $itemid ); my $vars; my $output; - my $vars->{'barcode'}=$itemid; + $vars->{'barcode'}=$itemid; $vars->{'messagetype'} = 'CheckOutItemResponse'; if ($error) { + warn "Error!!!"; $vars->{'processingerror'} = 1; + use Data::Dumper; + warn Dumper $messages; $vars->{'processingerrortype'} = $messages; $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; $output = $self->render_output( 'problem.tt', $vars ); } else { $vars->{'elements'} = \@elements; - + $vars->{'datedue'} = $datedue; $output = $self->render_output( 'response.tt', $vars ); } return $output; diff --git a/lib/NCIP/ILS/Koha.pm b/lib/NCIP/ILS/Koha.pm index cff9fed..f43f4a1 100644 --- a/lib/NCIP/ILS/Koha.pm +++ b/lib/NCIP/ILS/Koha.pm @@ -21,6 +21,7 @@ use Object::Tiny qw{ name }; use C4::Members qw{ GetMemberDetails }; use C4::Circulation qw { AddReturn CanBookBeIssued AddIssue }; +use C4::Context; sub itemdata { my $self = shift; @@ -35,11 +36,11 @@ sub userdata { } sub checkin { - my $self = shift; - my $barcode = shift; - my $branch = shift; + my $self = shift; + my $barcode = shift; + my $branch = shift; my $exemptfine = undef; - my $dropbox = undef; + my $dropbox = undef; my ( $success, $messages, $issue, $borrower ) = AddReturn( $barcode, $branch, $exemptfine, $dropbox ); my $result = { @@ -52,21 +53,50 @@ sub checkin { } sub checkout { - my $self = shift; - my $userid = shift; - my $barcode = shift; - my ( $error, $confirm ) = CanBookBeIssued( $userid, $barcode ); + my $self = shift; + my $userid = shift; + my $barcode = shift; + my $borrower = GetMemberDetails( undef, $userid ); + my $error; + my $confirm; + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona)= @_; + my @USERENV = ( + 1, + 'test', + 'MASTERTEST', + 'Test', + 'Test', + 'AS', #branchcode need to set this properly + 'Auckland', + 0, + ); + +C4::Context->_new_userenv ('DUMMY_SESSION_ID'); +C4::Context->set_userenv ( @USERENV ); + + + if ($borrower) { + + ( $error, $confirm ) = CanBookBeIssued( $borrower, $barcode ); #( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, # $barcode, $duedatespec, $inprocess, $ignore_reserves ); - if ( $error || $confirm ) { + if (%$error) { - # Can't issue item, return error hash - return ( 1, $error || $confirm ); + # Can't issue item, return error hash + return ( 1, $error ); + } + elsif (%$confirm) { + return ( 1, $confirm ); + } + else { + my $datedue = AddIssue( $borrower, $barcode ); + return (0, undef, $datedue); #successfully issued + } } else { - AddIssue( $userid, $barcode ); - return (0); #successfully issued + $error->{'badborrower'} = 1; + return ( 1, $error ); } } diff --git a/templates/includes/CheckOutItemResponse.inc b/templates/includes/CheckOutItemResponse.inc index 9659b3f..48e36c5 100644 --- a/templates/includes/CheckOutItemResponse.inc +++ b/templates/includes/CheckOutItemResponse.inc @@ -1,3 +1,6 @@ -[% date_due %] +[% datedue %] + +[% barcode %] + diff --git a/templates/problem.tt b/templates/problem.tt index 18c779d..0c007b4 100644 --- a/templates/problem.tt +++ b/templates/problem.tt @@ -12,8 +12,12 @@ We could not find an item with that barcode [% CASE 'NotIssued' %] The item is not on loan + [% CASE 'RESERVED' %] + The item is on hold for another borrower + [% CASE 'RENEW_ISSUE' %] + This item is already on loan to this borrower [% END %] - + [% END %] -- 2.11.0