2 #===============================================================================
11 # AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz
12 # ORGANIZATION: Koha Development Team
14 # CREATED: 05/11/13 11:14:09
16 #===============================================================================
17 package NCIP::ILS::Koha;
20 use Object::Tiny qw{ name };
25 use C4::Members qw{ GetMemberDetails };
26 use C4::Circulation qw { AddReturn CanBookBeIssued AddIssue };
28 use C4::Items qw { GetItem };
29 use C4::Reserves qw {CanBookBeReserved AddReserve GetReservesFromItemnumber};
30 use C4::Biblio qw {AddBiblio GetMarcFromKohaField};
31 use C4::Barcodes::ValueBuilder;
32 use C4::Items qw{AddItem};
37 my $itemdata = GetItem( undef, $barcode );
39 return ( $itemdata, undef );
42 return ( undef, 1 ); # item not found error
49 my $userdata = GetMemberDetails( undef, $userid );
61 'AS', #branchcode need to set this properly
66 C4::Context->_new_userenv('DUMMY_SESSION_ID');
67 C4::Context->set_userenv(@USERENV);
75 my $exemptfine = undef;
78 my ( $success, $messages, $issue, $borrower ) =
79 AddReturn( $barcode, $branch, $exemptfine, $dropbox );
82 messages => $messages,
83 iteminformation => $issue,
94 my $borrower = GetMemberDetails( undef, $userid );
100 ( $error, $confirm ) = CanBookBeIssued( $borrower, $barcode );
102 #( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower,
103 # $barcode, $duedatespec, $inprocess, $ignore_reserves );
106 # Can't issue item, return error hash
107 return ( 1, $error );
110 return ( 1, $confirm );
113 my $datedue = AddIssue( $borrower, $barcode );
114 return ( 0, undef, $datedue ); #successfully issued
118 $error->{'badborrower'} = 1;
119 return ( 1, $error );
127 my $borrower = GetMemberDetails( undef, $userid );
129 my $datedue = AddRenewal( $barcode, $borrower->{'borrowernumber'} );
144 my $biblionumber = shift;
145 my $borrowernumber = shift;
146 if ( CanBookBeReserved( $borrowernumber, $biblionumber ) ) {
149 return ( undef, "Requested" );
152 return ( 1, "Book can not be requested" );
157 my $self = shift || die "Not called as a method, we must bail out";
158 my $barcode = shift || die "No barcode passed can not continue";
162 my $iteminfo = shift;
165 $self->userenv(); # set userenvironment
166 my ( $biblionumber, $biblioitemnumber );
169 my $frameworkcode = 'FA'; # we should get this from config
171 warn $iteminfo->{title};
173 # we must make the item first
174 # Autographics workflow is to make the item each time
175 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
179 elsif ( C4::Context->preference('marcflavour') eq 'NORMARC' ) {
185 # create a marc record
186 $record = MARC::Record->new();
187 $record->leader(' nac 22 1u 4500');
188 $record->insert_fields_ordered(
189 MARC::Field->new( '100', '1', '0', 'a' => $iteminfo->{author} ),
190 MARC::Field->new( '245', '1', '0', 'a' => $iteminfo->{title} ),
193 'b' => $iteminfo->{publisher},
194 'c' => $iteminfo->{publicationdate}
197 '942', '1', '0', 'c' => $iteminfo->{mediumtype}
203 ( $biblionumber, $biblioitemnumber ) =
204 AddBiblio( $record, $frameworkcode );
208 ( $args{tag}, $args{subfield} ) =
209 GetMarcFromKohaField( "items.barcode", '' );
210 my ( $nextnum, $scr ) =
211 C4::Barcodes::ValueBuilder::incremental::get_barcode( \%args );
212 my $item = { 'barcode' => $nextnum };
213 ( $biblionumber, $biblioitemnumber, $itemnumber ) =
214 AddItem( $item, $biblionumber );
218 # find hold and get branch for that, check in there
219 my $itemdata = GetItem( undef, $barcode );
220 warn $itemdata->{'itemnumber'};
222 my ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $wait ) =
223 GetReservesFromItemnumber( $itemdata->{'itemnumber'} );
224 warn "barcode $barcode";
225 # now we have to check the requested action
226 if ( $action =~ /^Hold For Pickup And Notify/ ) {
227 unless ($reserve_id) {
228 $branchcode = 'AS'; # set this properly
229 # no reserve, place one
231 my $borrower = GetMemberDetails( undef, $user );
235 $borrower->{'borrowernumber'},
244 $itemdata->{'itemnumber'},
251 { success => 0, messages => { NO_BORROWER => 1 } };
257 { success => 0, messages => { NO_HOLD_BORROWER => 1 } };
263 unless ($reserve_id) {
264 $result = { success => 0, messages => { NO_HOLD => 1 } };
268 my ( $success, $messages, $issue, $borrower ) =
269 AddReturn( $barcode, $branchcode, undef, undef );
270 if ( $messages->{'NotIssued'} ) {
272 ; # we do this because we are only doing the return to trigger the reserve
277 messages => $messages,
278 iteminformation => $issue,
279 borrower => $borrower,
280 newbarcode => $barcode