]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
copy details method now returns latest circ, regardless of state
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ.pm
1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
5 use OpenILS::Application::Circ::Circulate;
6 use OpenILS::Application::Circ::Survey;
7 use OpenILS::Application::Circ::StatCat;
8 use OpenILS::Application::Circ::Holds;
9 use OpenILS::Application::Circ::Money;
10 use OpenILS::Application::Circ::NonCat;
11 use OpenILS::Application::Circ::CopyLocations;
12
13 use DateTime;
14 use DateTime::Format::ISO8601;
15
16 use OpenILS::Application::AppUtils;
17
18 use OpenSRF::Utils qw/:datetime/;
19 use OpenILS::Utils::ModsParser;
20 use OpenILS::Event;
21 use OpenSRF::EX qw(:try);
22 use OpenSRF::Utils::Logger qw(:logger);
23 use OpenILS::Utils::Fieldmapper;
24 use OpenILS::Utils::Editor q/:funcs/;
25 use OpenILS::Utils::CStoreEditor q/:funcs/;
26 use OpenILS::Const qw/:const/;
27 use OpenSRF::Utils::SettingsClient;
28
29 my $apputils = "OpenILS::Application::AppUtils";
30 my $U = $apputils;
31
32
33 # ------------------------------------------------------------------------
34 # Top level Circ package;
35 # ------------------------------------------------------------------------
36
37 sub initialize {
38         my $self = shift;
39         OpenILS::Application::Circ::Circulate->initialize();
40 }
41
42
43 __PACKAGE__->register_method(
44         method => 'retrieve_circ',
45         api_name        => 'open-ils.circ.retrieve',
46         signature => q/
47                 Retrieve a circ object by id
48                 @param authtoken Login session key
49                 @pararm circid The id of the circ object
50         /
51 );
52 sub retrieve_circ {
53         my( $s, $c, $a, $i ) = @_;
54         my $e = new_editor(authtoken => $a);
55         return $e->event unless $e->checkauth;
56         my $circ = $e->retrieve_action_circulation($i) or return $e->event;
57         if( $e->requestor->id ne $circ->usr ) {
58                 return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
59         }
60         return $circ;
61 }
62
63
64 __PACKAGE__->register_method(
65         method => 'fetch_circ_mods',
66         api_name => 'open-ils.circ.circ_modifier.retrieve.all');
67 sub fetch_circ_mods {
68         my $conf = OpenSRF::Utils::SettingsClient->new;
69         return $conf->config_value(
70                 'apps', 'open-ils.circ', 'app_settings', 'circ_modifiers', 'mod' );
71 }
72
73 __PACKAGE__->register_method(
74         method => 'fetch_bill_types',
75         api_name => 'open-ils.circ.billing_type.retrieve.all');
76 sub fetch_bill_types {
77         my $conf = OpenSRF::Utils::SettingsClient->new;
78         return $conf->config_value(
79                 'apps', 'open-ils.circ', 'app_settings', 'billing_types', 'type' );
80 }
81
82
83 # ------------------------------------------------------------------------
84 # Returns an array of {circ, record} hashes checked out by the user.
85 # ------------------------------------------------------------------------
86 __PACKAGE__->register_method(
87         method  => "checkouts_by_user",
88         api_name        => "open-ils.circ.actor.user.checked_out",
89         NOTES           => <<"  NOTES");
90         Returns a list of open circulations as a pile of objects.  each object
91         contains the relevant copy, circ, and record
92         NOTES
93
94 sub checkouts_by_user {
95         my( $self, $client, $user_session, $user_id ) = @_;
96
97         my( $requestor, $target, $copy, $record, $evt );
98
99         ( $requestor, $target, $evt ) = 
100                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
101         return $evt if $evt;
102
103         my $circs = $apputils->simplereq(
104                 'open-ils.cstore',
105                 "open-ils.cstore.direct.action.open_circulation.search.atomic", 
106                 { usr => $target->id, checkin_time => undef } );
107 #               { usr => $target->id } );
108
109         my @results;
110         for my $circ (@$circs) {
111
112                 ( $copy, $evt )  = $apputils->fetch_copy($circ->target_copy);
113                 return $evt if $evt;
114
115                 $logger->debug("Retrieving record for copy " . $circ->target_copy);
116
117                 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
118                 return $evt if $evt;
119
120                 my $mods = $apputils->record_to_mvr($record);
121
122                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
123         }
124
125         return \@results;
126
127 }
128
129
130
131 __PACKAGE__->register_method(
132         method  => "checkouts_by_user_slim",
133         api_name        => "open-ils.circ.actor.user.checked_out.slim",
134         NOTES           => <<"  NOTES");
135         Returns a list of open circulation objects
136         NOTES
137
138 # DEPRECAT ME?? XXX
139 sub checkouts_by_user_slim {
140         my( $self, $client, $user_session, $user_id ) = @_;
141
142         my( $requestor, $target, $copy, $record, $evt );
143
144         ( $requestor, $target, $evt ) = 
145                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
146         return $evt if $evt;
147
148         $logger->debug( 'User ' . $requestor->id . 
149                 " retrieving checked out items for user " . $target->id );
150
151         # XXX Make the call correct..
152         return $apputils->simplereq(
153                 'open-ils.cstore',
154                 "open-ils.cstore.direct.action.open_circulation.search.atomic", 
155                 { usr => $target->id, checkin_time => undef } );
156 #               { usr => $target->id } );
157 }
158
159
160 __PACKAGE__->register_method(
161         method  => "checkouts_by_user_opac",
162         api_name        => "open-ils.circ.actor.user.checked_out.opac",);
163
164 # XXX Deprecate Me
165 sub checkouts_by_user_opac {
166         my( $self, $client, $auth, $user_id ) = @_;
167
168         my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
169         return $e->event unless $e->checkauth;
170         $user_id ||= $e->requestor->id;
171         return $e->event unless 
172                 my $patron = $e->retrieve_actor_user($user_id);
173
174         my $data;
175         my $search = {usr => $user_id, stop_fines => undef};
176
177         if( $user_id ne $e->requestor->id ) {
178                 $data = $e->search_action_circulation(
179                         $search, {checkperm=>1, permorg=>$patron->home_ou})
180                         or return $e->event;
181
182         } else {
183                 $data = $e->search_action_circulation($search);
184         }
185
186         return $data;
187 }
188
189
190 __PACKAGE__->register_method(
191         method  => "title_from_transaction",
192         api_name        => "open-ils.circ.circ_transaction.find_title",
193         NOTES           => <<"  NOTES");
194         Returns a mods object for the title that is linked to from the 
195         copy from the hold that created the given transaction
196         NOTES
197
198 sub title_from_transaction {
199         my( $self, $client, $login_session, $transactionid ) = @_;
200
201         my( $user, $circ, $title, $evt );
202
203         ( $user, $evt ) = $apputils->checkses( $login_session );
204         return $evt if $evt;
205
206         ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
207         return $evt if $evt;
208         
209         ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
210         return $evt if $evt;
211
212         return $apputils->record_to_mvr($title);
213 }
214
215
216 __PACKAGE__->register_method(
217         method  => "set_circ_lost",
218         api_name        => "open-ils.circ.circulation.set_lost",
219         NOTES           => <<"  NOTES");
220         Params are login, barcode
221         login must have SET_CIRC_LOST perms
222         Sets a circulation to lost
223         NOTES
224
225 __PACKAGE__->register_method(
226         method  => "set_circ_lost",
227         api_name        => "open-ils.circ.circulation.set_claims_returned",
228         NOTES           => <<"  NOTES");
229         Params are login, barcode
230         login must have SET_CIRC_MISSING perms
231         Sets a circulation to lost
232         NOTES
233
234 sub set_circ_lost {
235         my( $self, $client, $login, $args ) = @_;
236         my( $user, $circ, $copy, $evt );
237
238         my $barcode             = $$args{barcode};
239         my $backdate    = $$args{backdate};
240
241         ( $user, $evt ) = $U->checkses($login);
242         return $evt if $evt;
243
244         # Grab the related copy
245         ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
246         return $evt if $evt;
247
248         my $isclaims    = $self->api_name =~ /claims_returned/;
249         my $islost              = $self->api_name =~ /lost/;
250         my $session             = $U->start_db_session(); 
251
252         # grab the circulation
253         ( $circ ) = $U->fetch_open_circulation( $copy->id );
254         return 1 unless $circ;
255
256         if($islost) {
257                 $evt  = _set_circ_lost($copy, $circ, $user, $session) if $islost;
258                 return $evt if $evt;
259         }
260
261         if($isclaims) {
262                 $evt = _set_circ_claims_returned(
263                         $user, $circ, $session, $backdate );
264                 return $evt if $evt;
265
266         }
267
268         $circ->stop_fines_time('now') unless $circ->stop_fines_time;
269         my $s = $session->request(
270                 "open-ils.storage.direct.action.circulation.update", $circ )->gather(1);
271
272         return $U->DB_UPDATE_FAILED($circ) unless defined($s);
273         $U->commit_db_session($session);
274
275         return 1;
276 }
277
278 sub _set_circ_lost {
279         my( $copy, $circ, $reqr, $session ) = @_;
280
281         my $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'SET_CIRC_LOST');
282         return $evt if $evt;
283
284         $logger->activity("user ".$reqr->id." marking copy ".$copy->id.
285                 " lost  for circ ".  $circ->id. " and checking for necessary charges");
286
287         if( $copy->status ne OILS_COPY_STATUS_LOST ) {
288                 $copy->status(OILS_COPY_STATUS_LOST);
289                 $U->update_copy(
290                         copy            => $copy, 
291                         editor  => $reqr->id, 
292                         session => $session);
293         }
294
295         # if the copy has a price defined and/or a processing fee, bill the patron
296
297         my $copy_price = $copy->price || 0;
298
299         $logger->debug("lost copy has a price of $copy_price");
300
301         # If the copy has a price configured, charge said price to the user
302         if($copy_price and $copy_price > 0) {
303                 $evt = _make_bill($session, $copy_price, 'Lost Materials', $circ->id);
304                 return $evt if $evt;
305         }
306
307         # if the location that owns the copy has a processing fee, charge the user
308         my $owner = $U->fetch_copy_owner($copy->id);
309         $logger->info("circ fetching org settings for $owner to determine processing fee");
310
311         my $settings = $U->simplereq(
312                 'open-ils.actor', 'open-ils.actor.org_unit.settings.retrieve', $owner );
313         my $fee = $settings->{'circ.lost_materials_processing_fee'} || 0;
314
315         if( $fee ) {
316                 $evt = _make_bill($session, $fee, 'Lost Materials Processing Fee', $circ->id);
317                 return $evt if $evt;
318         }
319         
320         $circ->stop_fines(OILS_STOP_FINES_LOST);                
321         return undef;
322 }
323
324 sub _make_bill {
325         my( $session, $amount, $type, $xactid ) = @_;
326
327         $logger->activity("The system is charging $amount ".
328                 " [$type] for lost materials on circulation $xactid");
329
330         my $bill = Fieldmapper::money::billing->new;
331
332         $bill->xact($xactid);
333         $bill->amount($amount);
334         $bill->billing_type($type); # - XXX these strings should be configurable some day
335         $bill->note('SYSTEM GENERATED');
336
337         my $id = $session->request(
338                 'open-ils.storage.direct.money.billing.create', $bill )->gather(1);
339
340         return $U->DB_UPDATE_FAILED($bill) unless defined $id;
341         return undef;
342 }
343
344 sub _set_circ_claims_returned {
345         my( $reqr, $circ, $session, $backdate ) = @_;
346
347         my $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'SET_CIRC_CLAIMS_RETURNED');
348         return $evt if $evt;
349         $circ->stop_fines("CLAIMSRETURNED");
350
351         $logger->activity("user ".$reqr->id.
352                 " marking circ".  $circ->id. " as claims returned");
353
354         # allow the caller to backdate the circulation and void any fines
355         # that occurred after the backdate
356         if($backdate) {
357                 OpenILS::Application::Circ::Circulate::_checkin_handle_backdate(
358                         $backdate, $circ, $reqr, $session );
359         }
360
361         return undef;
362 }
363
364
365
366 __PACKAGE__->register_method (
367         method          => 'set_circ_due_date',
368         api_name                => 'open-ils.circ.circulation.due_date.update',
369         signature       => q/
370                 Updates the due_date on the given circ
371                 @param authtoken
372                 @param circid The id of the circ to update
373                 @param date The timestamp of the new due date
374         /
375 );
376
377 sub set_circ_due_date {
378         my( $s, $c, $authtoken, $circid, $date ) = @_;
379         my ($circ, $evt) = $U->fetch_circulation($circid);
380         return $evt if $evt;
381
382         my $reqr;
383         ($reqr, $evt) = $U->checkses($authtoken);
384         return $evt if $evt;
385
386         $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'CIRC_OVERRIDE_DUE_DATE');
387         return $evt if $evt;
388
389         $date = clense_ISO8601($date);
390         $logger->activity("user ".$reqr->id.
391                 " updating due_date on circ $circid: $date");
392
393         $circ->due_date($date);
394         my $stat = $U->storagereq(
395                 'open-ils.storage.direct.action.circulation.update', $circ);
396         return $U->DB_UPDATE_FAILED unless defined $stat;
397         return $stat;
398 }
399
400
401 __PACKAGE__->register_method(
402         method          => "create_in_house_use",
403         api_name                => 'open-ils.circ.in_house_use.create',
404         signature       =>      q/
405                 Creates an in-house use action.
406                 @param $authtoken The login session key
407                 @param params A hash of params including
408                         'location' The org unit id where the in-house use occurs
409                         'copyid' The copy in question
410                         'count' The number of in-house uses to apply to this copy
411                 @return An array of id's representing the id's of the newly created
412                 in-house use objects or an event on an error
413         /);
414
415 sub create_in_house_use {
416         my( $self, $client, $authtoken, $params ) = @_;
417
418         my( $staff, $evt, $copy );
419         my $org                 = $params->{location};
420         my $copyid              = $params->{copyid};
421         my $count               = $params->{count} || 1;
422         my $use_time    = $params->{use_time} || 'now';
423
424         if(!$copyid) {
425                 my $barcode = $params->{barcode};
426                 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
427                 return $evt if $evt;
428                 $copyid = $copy->id;
429         }
430
431         ($staff, $evt) = $U->checkses($authtoken);
432         return $evt if $evt;
433
434         ($copy, $evt) = $U->fetch_copy($copyid) unless $copy;
435         return $evt if $evt;
436
437         $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
438         return $evt if $evt;
439
440         $logger->activity("User " . $staff->id .
441                 " creating $count in-house use(s) for copy $copyid at location $org");
442
443         if( $use_time ne 'now' ) {
444                 $use_time = clense_ISO8601($use_time);
445                 $logger->debug("in_house_use setting use time to $use_time");
446         }
447
448         my @ids;
449         for(1..$count) {
450                 my $ihu = Fieldmapper::action::in_house_use->new;
451
452                 $ihu->item($copyid);
453                 $ihu->staff($staff->id);
454                 $ihu->org_unit($org);
455                 $ihu->use_time($use_time);
456
457                 my $id = $U->simplereq(
458                         'open-ils.storage',
459                         'open-ils.storage.direct.action.in_house_use.create', $ihu );
460
461                 return $U->DB_UPDATE_FAILED($ihu) unless $id;
462                 push @ids, $id;
463         }
464
465         return \@ids;
466 }
467
468
469
470 __PACKAGE__->register_method(
471         method  => "view_circs",
472         api_name        => "open-ils.circ.copy_checkout_history.retrieve",
473         notes           => q/
474                 Retrieves the last X circs for a given copy
475                 @param authtoken The login session key
476                 @param copyid The copy to check
477                 @param count How far to go back in the item history
478                 @return An array of circ ids
479         /);
480
481
482
483 sub view_circs {
484         my( $self, $client, $authtoken, $copyid, $count ) = @_; 
485
486         my( $requestor, $evt ) = $U->checksesperm(
487                         $authtoken, 'VIEW_COPY_CHECKOUT_HISTORY' );
488         return $evt if $evt;
489
490         return [] unless $count;
491
492         my $circs = $U->cstorereq(
493                 'open-ils.cstore.direct.action.circulation.search.atomic',
494                         { 
495                                 target_copy => $copyid, 
496                         }, 
497                         { 
498                                 limit => $count, 
499                                 order_by => { ac => "xact_start DESC" }
500                         } 
501         );
502
503         return $circs;
504 }
505
506
507 __PACKAGE__->register_method(
508         method  => "circ_count",
509         api_name        => "open-ils.circ.circulation.count",
510         notes           => q/
511                 Returns the number of times the item has circulated
512                 @param copyid The copy to check
513         /);
514
515 sub circ_count {
516         my( $self, $client, $copyid, $range ) = @_; 
517         my $e = OpenILS::Utils::Editor->new;
518         return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
519 }
520
521
522
523 __PACKAGE__->register_method(
524         method          => 'fetch_notes',
525         api_name                => 'open-ils.circ.copy_note.retrieve.all',
526         signature       => q/
527                 Returns an array of copy note objects.  
528                 @param args A named hash of parameters including:
529                         authtoken       : Required if viewing non-public notes
530                         itemid          : The id of the item whose notes we want to retrieve
531                         pub                     : True if all the caller wants are public notes
532                 @return An array of note objects
533         /);
534
535 __PACKAGE__->register_method(
536         method          => 'fetch_notes',
537         api_name                => 'open-ils.circ.call_number_note.retrieve.all',
538         signature       => q/@see open-ils.circ.copy_note.retrieve.all/);
539
540 __PACKAGE__->register_method(
541         method          => 'fetch_notes',
542         api_name                => 'open-ils.circ.title_note.retrieve.all',
543         signature       => q/@see open-ils.circ.copy_note.retrieve.all/);
544
545
546 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
547 sub fetch_notes {
548         my( $self, $connection, $args ) = @_;
549
550         my $id = $$args{itemid};
551         my $authtoken = $$args{authtoken};
552         my( $r, $evt);
553
554         if( $self->api_name =~ /copy/ ) {
555                 if( $$args{pub} ) {
556                         return $U->cstorereq(
557                                 'open-ils.cstore.direct.asset.copy_note.search.atomic',
558                                 { owning_copy => $id, pub => 't' } );
559                 } else {
560                         ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
561                         return $evt if $evt;
562                         return $U->cstorereq(
563                                 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
564                 }
565
566         } elsif( $self->api_name =~ /call_number/ ) {
567                 if( $$args{pub} ) {
568                         return $U->cstorereq(
569                                 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
570                                 { call_number => $id, pub => 't' } );
571                 } else {
572                         ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
573                         return $evt if $evt;
574                         return $U->cstorereq(
575                                 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
576                 }
577
578         } elsif( $self->api_name =~ /title/ ) {
579                 if( $$args{pub} ) {
580                         return $U->cstorereq(
581                                 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
582                                 { record => $id, pub => 't' } );
583                 } else {
584                         ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
585                         return $evt if $evt;
586                         return $U->cstorereq(
587                                 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
588                 }
589         }
590
591         return undef;
592 }
593
594 __PACKAGE__->register_method(
595         method  => 'has_notes',
596         api_name        => 'open-ils.circ.copy.has_notes');
597 __PACKAGE__->register_method(
598         method  => 'has_notes',
599         api_name        => 'open-ils.circ.call_number.has_notes');
600 __PACKAGE__->register_method(
601         method  => 'has_notes',
602         api_name        => 'open-ils.circ.title.has_notes');
603
604
605 sub has_notes {
606         my( $self, $conn, $authtoken, $id ) = @_;
607         my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
608         return $editor->event unless $editor->checkauth;
609
610         my $n = $editor->search_asset_copy_note(
611                 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
612
613         $n = $editor->search_asset_call_number_note(
614                 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
615
616         $n = $editor->search_biblio_record_note(
617                 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
618
619         return scalar @$n;
620 }
621
622 __PACKAGE__->register_method(
623         method          => 'create_copy_note',
624         api_name                => 'open-ils.circ.copy_note.create',
625         signature       => q/
626                 Creates a new copy note
627                 @param authtoken The login session key
628                 @param note     The note object to create
629                 @return The id of the new note object
630         /);
631
632 sub create_copy_note {
633         my( $self, $connection, $authtoken, $note ) = @_;
634         my( $cnowner, $requestor, $evt );
635
636         ($cnowner, $evt) = $U->fetch_copy_owner($note->owning_copy);
637         return $evt if $evt;
638         ($requestor, $evt) = $U->checkses($authtoken);
639         return $evt if $evt;
640         $evt = $U->check_perms($requestor->id, $cnowner, 'CREATE_COPY_NOTE');
641         return $evt if $evt;
642
643         $note->create_date('now');
644         $note->creator($requestor->id);
645         $note->pub( ($note->pub) ? 't' : 'f' );
646
647         my $id = $U->storagereq(
648                 'open-ils.storage.direct.asset.copy_note.create', $note );
649         return $U->DB_UPDATE_FAILED($note) unless $id;
650
651         $logger->activity("User ".$requestor->id." created a new copy ".
652                 "note [$id] for copy ".$note->owning_copy." with text ".$note->value);
653
654         return $id;
655 }
656
657 __PACKAGE__->register_method(
658         method          => 'delete_copy_note',
659         api_name                =>      'open-ils.circ.copy_note.delete',
660         signature       => q/
661                 Deletes an existing copy note
662                 @param authtoken The login session key
663                 @param noteid The id of the note to delete
664                 @return 1 on success - Event otherwise.
665                 /);
666
667 sub delete_copy_note {
668         my( $self, $conn, $authtoken, $noteid ) = @_;
669         my( $requestor, $note, $owner, $evt );
670
671         ($requestor, $evt) = $U->checkses($authtoken);
672         return $evt if $evt;
673
674         ($note, $evt) = $U->fetch_copy_note($noteid);
675         return $evt if $evt;
676
677         if( $note->creator ne $requestor->id ) {
678                 ($owner, $evt) = $U->fetch_copy_onwer($note->owning_copy);
679                 return $evt if $evt;
680                 $evt = $U->check_perms($requestor->id, $owner, 'DELETE_COPY_NOTE');
681                 return $evt if $evt;
682         }
683
684         my $stat = $U->storagereq(
685                 'open-ils.storage.direct.asset.copy_note.delete', $noteid );
686         return $U->DB_UPDATE_FAILED($noteid) unless $stat;
687
688         $logger->activity("User ".$requestor->id." deleted copy note $noteid");
689         return 1;
690 }
691
692
693 __PACKAGE__->register_method(
694         method => 'age_hold_rules',
695         api_name        =>  'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
696 );
697
698 sub age_hold_rules {
699         my( $self, $conn ) = @_;
700         return new_editor()->retrieve_all_config_rules_age_hold_protect();
701 }
702
703
704
705
706 __PACKAGE__->register_method(
707         method => 'copy_details',
708         api_name => 'open-ils.circ.copy_details.retrieve',
709         signature => q/
710         /
711 );
712
713 sub copy_details {
714         my( $self, $conn, $auth, $copy_id ) = @_;
715         my $e = new_editor(authtoken=>$auth);
716         return $e->event unless $e->checkauth;
717
718         my $copy = $e->retrieve_asset_copy($copy_id)
719                 or return $e->event;
720
721         my $hold = $e->search_action_hold_request(
722                 { 
723                         current_copy => $copy_id, 
724                         capture_time => { "!=" => undef },
725                         fulfillment_time => undef,
726                 }
727         )->[0];
728
729         OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
730
731         my $transit = $e->search_action_transit_copy(
732                 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
733
734         # find the latest circ, open or closed
735         my $circ = $e->search_action_circulation(
736                 [
737                         { target_copy => $copy_id },
738                         { order_by => { circ => 'xact_start desc' }, limit => 1 }
739                 ]
740         )->[0];
741
742         return {
743                 copy            => $copy,
744                 hold            => $hold,
745                 transit => $transit,
746                 circ            => $circ,
747         };
748 }
749
750
751
752
753 1;