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 };
30 qw {CanBookBeReserved AddReserve GetReservesFromItemnumber CancelReserve};
31 use C4::Biblio qw {AddBiblio GetMarcFromKohaField GetBiblioData};
32 use C4::Barcodes::ValueBuilder;
33 use C4::Items qw{AddItem};
38 my $itemdata = GetItem( undef, $barcode );
40 return ( $itemdata, undef );
43 return ( undef, 1 ); # item not found error
50 my $userdata = GetMemberDetails( undef, $userid );
62 'AS', #branchcode need to set this properly
67 C4::Context->_new_userenv('DUMMY_SESSION_ID');
68 C4::Context->set_userenv(@USERENV);
76 my $exemptfine = undef;
79 my ( $success, $messages, $issue, $borrower ) =
80 AddReturn( $barcode, $branch, $exemptfine, $dropbox );
83 messages => $messages,
84 iteminformation => $issue,
95 my $borrower = GetMemberDetails( undef, $userid );
101 ( $error, $confirm ) = CanBookBeIssued( $borrower, $barcode );
103 #( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower,
104 # $barcode, $duedatespec, $inprocess, $ignore_reserves );
107 # Can't issue item, return error hash
108 return ( 1, $error );
111 return ( 1, $confirm );
114 my $datedue = AddIssue( $borrower, $barcode );
115 return ( 0, undef, $datedue ); #successfully issued
119 $error->{'badborrower'} = 1;
120 return ( 1, $error );
128 my $borrower = GetMemberDetails( undef, $userid );
130 my $datedue = AddRenewal( $barcode, $borrower->{'borrowernumber'} );
145 my $cardnumber = shift;
147 my $biblionumber = shift;
148 my $borrower = GetMemberDetails( undef, $cardnumber );
151 $result = { success => 0, messages => { 'BORROWER_NOT_FOUND' => 1 } };
156 $itemdata = GetItem( undef, $barcode );
159 $itemdata = GetBiblioData($biblionumber);
162 $result = { success => 0, messages => {'ITEM_NOT_FOUND'} };
168 $borrower->{borrowernumber},
169 $itemdata->{biblionumber}
173 my $biblioitemnumber = $itemdata->{biblionumber};
174 my $branchcode = 'AS';
178 $branchcode, $borrower->{borrwerborrowernumber},
179 $itemdata->{biblionumber}, 'a',
180 [$biblioitemnumber], 1,
183 $itemdata->{'itemnumber'}, undef
185 my ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $wait ) =
186 GetReservesFromItemnumber( $itemdata->{'itemnumber'} );
189 messages => { request_id => $reserve_id }
194 $result = { success => 0, messages => { CANNOT_REQUEST => 1 } };
202 my $requestid = shift;
203 CancelReserve( { reserve_id => $requestid } );
205 my $result = { success => 1 };
210 my $self = shift || die "Not called as a method, we must bail out";
211 my $barcode = shift || die "No barcode passed can not continue";
215 my $iteminfo = shift;
218 $self->userenv(); # set userenvironment
219 my ( $biblionumber, $biblioitemnumber );
222 my $frameworkcode = 'FA'; # we should get this from config
224 # we must make the item first
225 # Autographics workflow is to make the item each time
226 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
230 elsif ( C4::Context->preference('marcflavour') eq 'NORMARC' ) {
236 # create a marc record
237 $record = MARC::Record->new();
238 $record->leader(' nac 22 1u 4500');
239 $record->insert_fields_ordered(
240 MARC::Field->new( '100', '1', '0', 'a' => $iteminfo->{author} ),
241 MARC::Field->new( '245', '1', '0', 'a' => $iteminfo->{title} ),
244 'b' => $iteminfo->{publisher},
245 'c' => $iteminfo->{publicationdate}
248 '942', '1', '0', 'c' => $iteminfo->{mediumtype}
254 ( $biblionumber, $biblioitemnumber ) =
255 AddBiblio( $record, $frameworkcode );
259 ( $args{tag}, $args{subfield} ) =
260 GetMarcFromKohaField( "items.barcode", '' );
261 my ( $nextnum, $scr ) =
262 C4::Barcodes::ValueBuilder::incremental::get_barcode( \%args );
263 my $item = { 'barcode' => $nextnum };
264 ( $biblionumber, $biblioitemnumber, $itemnumber ) =
265 AddItem( $item, $biblionumber );
269 # find hold and get branch for that, check in there
270 my $itemdata = GetItem( undef, $barcode );
272 my ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $wait ) =
273 GetReservesFromItemnumber( $itemdata->{'itemnumber'} );
275 # now we have to check the requested action
276 if ( $action =~ /^Hold For Pickup And Notify/ ) {
277 unless ($reserve_id) {
278 $branchcode = 'AS'; # set this properly
279 # no reserve, place one
281 my $borrower = GetMemberDetails( undef, $user );
285 $borrower->{'borrowernumber'},
294 $itemdata->{'itemnumber'},
301 { success => 0, messages => { NO_BORROWER => 1 } };
307 { success => 0, messages => { NO_HOLD_BORROWER => 1 } };
313 unless ($reserve_id) {
314 $result = { success => 0, messages => { NO_HOLD => 1 } };
318 my ( $success, $messages, $issue, $borrower ) =
319 AddReturn( $barcode, $branchcode, undef, undef );
320 if ( $messages->{'NotIssued'} ) {
322 ; # we do this because we are only doing the return to trigger the reserve
327 messages => $messages,
328 iteminformation => $issue,
329 borrower => $borrower,
330 newbarcode => $barcode