1 package OpenILS::Application::Circ;
2 use OpenILS::Application;
3 use base qw/OpenILS::Application/;
4 use strict; use warnings;
6 use OpenILS::Application::Circ::Circulate;
7 use OpenILS::Application::Circ::Survey;
8 use OpenILS::Application::Circ::StatCat;
9 use OpenILS::Application::Circ::Holds;
10 use OpenILS::Application::Circ::HoldNotify;
11 use OpenILS::Application::Circ::Money;
12 use OpenILS::Application::Circ::NonCat;
13 use OpenILS::Application::Circ::CopyLocations;
16 use DateTime::Format::ISO8601;
18 use OpenILS::Application::AppUtils;
20 use OpenSRF::Utils qw/:datetime/;
21 use OpenILS::Utils::ModsParser;
23 use OpenSRF::EX qw(:try);
24 use OpenSRF::Utils::Logger qw(:logger);
25 use OpenILS::Utils::Fieldmapper;
26 use OpenILS::Utils::Editor;
27 use OpenILS::Utils::CStoreEditor q/:funcs/;
28 use OpenILS::Const qw/:const/;
29 use OpenSRF::Utils::SettingsClient;
31 my $apputils = "OpenILS::Application::AppUtils";
35 # ------------------------------------------------------------------------
36 # Top level Circ package;
37 # ------------------------------------------------------------------------
41 OpenILS::Application::Circ::Circulate->initialize();
45 __PACKAGE__->register_method(
46 method => 'retrieve_circ',
47 api_name => 'open-ils.circ.retrieve',
49 Retrieve a circ object by id
50 @param authtoken Login session key
51 @pararm circid The id of the circ object
55 my( $s, $c, $a, $i ) = @_;
56 my $e = new_editor(authtoken => $a);
57 return $e->event unless $e->checkauth;
58 my $circ = $e->retrieve_action_circulation($i) or return $e->event;
59 if( $e->requestor->id ne $circ->usr ) {
60 return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
66 __PACKAGE__->register_method(
67 method => 'fetch_circ_mods',
68 api_name => 'open-ils.circ.circ_modifier.retrieve.all');
70 my($self, $conn, $args) = @_;
71 my $mods = new_editor()->retrieve_all_config_circ_modifier;
72 return [ map {$_->code} @$mods ] unless $$args{full};
76 __PACKAGE__->register_method(
77 method => 'fetch_bill_types',
78 api_name => 'open-ils.circ.billing_type.retrieve.all');
79 sub fetch_bill_types {
80 my $conf = OpenSRF::Utils::SettingsClient->new;
81 return $conf->config_value(
82 'apps', 'open-ils.circ', 'app_settings', 'billing_types', 'type' );
86 __PACKAGE__->register_method(
87 method => 'ranged_billing_types',
88 api_name => 'open-ils.circ.billing_type.ranged.retrieve.all');
90 sub ranged_billing_types {
91 my($self, $conn, $auth, $org_id, $depth) = @_;
92 my $e = new_editor(authtoken => $auth);
93 return $e->event unless $e->checkauth;
94 return $e->search_config_billing_type(
95 {owner => $U->get_org_full_path($org_id, $depth)});
100 # ------------------------------------------------------------------------
101 # Returns an array of {circ, record} hashes checked out by the user.
102 # ------------------------------------------------------------------------
103 __PACKAGE__->register_method(
104 method => "checkouts_by_user",
105 api_name => "open-ils.circ.actor.user.checked_out",
106 NOTES => <<" NOTES");
107 Returns a list of open circulations as a pile of objects. each object
108 contains the relevant copy, circ, and record
111 sub checkouts_by_user {
112 my( $self, $client, $user_session, $user_id ) = @_;
114 my( $requestor, $target, $copy, $record, $evt );
116 ( $requestor, $target, $evt ) =
117 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
120 my $circs = $apputils->simplereq(
122 "open-ils.cstore.direct.action.open_circulation.search.atomic",
123 { usr => $target->id, checkin_time => undef } );
124 # { usr => $target->id } );
127 for my $circ (@$circs) {
129 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
132 $logger->debug("Retrieving record for copy " . $circ->target_copy);
134 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
137 my $mods = $apputils->record_to_mvr($record);
139 push( @results, { copy => $copy, circ => $circ, record => $mods } );
148 __PACKAGE__->register_method(
149 method => "checkouts_by_user_slim",
150 api_name => "open-ils.circ.actor.user.checked_out.slim",
151 NOTES => <<" NOTES");
152 Returns a list of open circulation objects
156 sub checkouts_by_user_slim {
157 my( $self, $client, $user_session, $user_id ) = @_;
159 my( $requestor, $target, $copy, $record, $evt );
161 ( $requestor, $target, $evt ) =
162 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
165 $logger->debug( 'User ' . $requestor->id .
166 " retrieving checked out items for user " . $target->id );
168 # XXX Make the call correct..
169 return $apputils->simplereq(
171 "open-ils.cstore.direct.action.open_circulation.search.atomic",
172 { usr => $target->id, checkin_time => undef } );
173 # { usr => $target->id } );
177 __PACKAGE__->register_method(
178 method => "checkouts_by_user_opac",
179 api_name => "open-ils.circ.actor.user.checked_out.opac",);
182 sub checkouts_by_user_opac {
183 my( $self, $client, $auth, $user_id ) = @_;
185 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
186 return $e->event unless $e->checkauth;
187 $user_id ||= $e->requestor->id;
188 return $e->event unless
189 my $patron = $e->retrieve_actor_user($user_id);
192 my $search = {usr => $user_id, stop_fines => undef};
194 if( $user_id ne $e->requestor->id ) {
195 $data = $e->search_action_circulation(
196 $search, {checkperm=>1, permorg=>$patron->home_ou})
200 $data = $e->search_action_circulation($search);
207 __PACKAGE__->register_method(
208 method => "title_from_transaction",
209 api_name => "open-ils.circ.circ_transaction.find_title",
210 NOTES => <<" NOTES");
211 Returns a mods object for the title that is linked to from the
212 copy from the hold that created the given transaction
215 sub title_from_transaction {
216 my( $self, $client, $login_session, $transactionid ) = @_;
218 my( $user, $circ, $title, $evt );
220 ( $user, $evt ) = $apputils->checkses( $login_session );
223 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
226 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
229 return $apputils->record_to_mvr($title);
234 __PACKAGE__->register_method(
235 method => "new_set_circ_lost",
236 api_name => "open-ils.circ.circulation.set_lost",
238 Sets the copy and related open circulation to lost
240 @param args : barcode
245 # ---------------------------------------------------------------------
246 # Sets a circulation to lost. updates copy status to lost
247 # applies copy and/or prcoessing fees depending on org settings
248 # ---------------------------------------------------------------------
249 sub new_set_circ_lost {
250 my( $self, $conn, $auth, $args ) = @_;
252 my $e = new_editor(authtoken=>$auth, xact=>1);
253 return $e->die_event unless $e->checkauth;
255 my $barcode = $$args{barcode};
256 $logger->info("marking item lost $barcode");
258 # ---------------------------------------------------------------------
260 my $copy = $e->search_asset_copy([
261 {barcode=>$barcode, deleted=>'f'},
262 {flesh => 1, flesh_fields => {'acp' => ['call_number']}}])->[0]
263 or return $e->die_event;
266 ($copy->call_number->id == OILS_PRECAT_CALL_NUMBER) ?
267 $copy->circ_lib : $copy->call_number->owning_lib;
269 my $circ = $e->search_action_circulation(
270 {checkin_time => undef, target_copy => $copy->id} )->[0]
271 or return $e->die_event;
273 $e->allowed('SET_CIRC_LOST', $circ->circ_lib) or return $e->die_event;
275 return OpenILS::Event->new('COPY_MARKED_LOST')
276 if $copy->status == OILS_COPY_STATUS_LOST;
278 # ---------------------------------------------------------------------
279 # fetch the related org settings
280 my $proc_fee = $U->ou_ancestor_setting_value(
281 $owning_lib, OILS_SETTING_LOST_PROCESSING_FEE, $e) || 0;
282 my $void_overdue = $U->ou_ancestor_setting_value(
283 $owning_lib, OILS_SETTING_VOID_OVERDUE_ON_LOST, $e) || 0;
285 # ---------------------------------------------------------------------
286 # move the copy into LOST status
287 $copy->status(OILS_COPY_STATUS_LOST);
288 $copy->editor($e->requestor->id);
289 $copy->edit_date('now');
290 $e->update_asset_copy($copy) or return $e->die_event;
292 my $price = $U->get_copy_price($e, $copy, $copy->call_number);
295 my $evt = create_bill($e, $price, 'Lost Materials', $circ->id);
299 # ---------------------------------------------------------------------
300 # if there is a processing fee, charge that too
301 if( $proc_fee > 0 ) {
302 my $evt = create_bill($e, $proc_fee, 'Lost Materials Processing Fee', $circ->id);
306 # ---------------------------------------------------------------------
307 # mark the circ as lost and stop the fines
308 $circ->stop_fines(OILS_STOP_FINES_LOST);
309 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
310 $e->update_action_circulation($circ) or return $e->die_event;
312 # ---------------------------------------------------------------------
313 # void all overdue fines on this circ if configured
314 if( $void_overdue ) {
315 my $evt = void_overdues($e, $circ);
319 my $evt = reopen_xact($e, $circ->id);
327 my($e, $xactid) = @_;
329 # -----------------------------------------------------------------
330 # make sure the transaction is not closed
331 my $xact = $e->retrieve_money_billable_transaction($xactid)
332 or return $e->die_event;
334 if( $xact->xact_finish ) {
335 my ($mbts) = $U->fetch_mbts($xactid, $e);
336 if( $mbts->balance_owed != 0 ) {
337 $logger->info("* re-opening xact $xactid, orig xact_finish is ".$xact->xact_finish);
338 $xact->clear_xact_finish;
339 $e->update_money_billable_transaction($xact)
340 or return $e->die_event;
349 my( $e, $amount, $type, $xactid ) = @_;
351 $logger->info("The system is charging $amount [$type] on xact $xactid");
353 # -----------------------------------------------------------------
354 # now create the billing
355 my $bill = Fieldmapper::money::billing->new;
356 $bill->xact($xactid);
357 $bill->amount($amount);
358 $bill->billing_type($type);
359 $bill->note('SYSTEM GENERATED');
360 $e->create_money_billing($bill) or return $e->die_event;
367 # -----------------------------------------------------------------
368 # Voids overdue fines on the given circ. if a backdate is
369 # provided, then we only void back to the backdate
370 # -----------------------------------------------------------------
372 my( $e, $circ, $backdate ) = @_;
376 billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
380 # ------------------------------------------------------------------
381 # Fines for overdue materials are assessed up to, but not including,
382 # one fine interval after the fines are applicable. Here, we add
383 # one fine interval to the backdate to ensure that we are not
384 # voiding fines that were applicable before the backdate.
385 # ------------------------------------------------------------------
387 # if there is a raw time component (e.g. from postgres),
388 # turn it into an interval that interval_to_seconds can parse
389 my $duration = $circ->fine_interval;
390 $duration =~ s/(\d{2}):(\d{2}):(\d{2})/$1 h $2 m $3 s/o;
391 my $interval = OpenSRF::Utils->interval_to_seconds($duration);
393 my $date = DateTime::Format::ISO8601->parse_datetime($backdate);
394 $backdate = $U->epoch2ISO8601($date->epoch + $interval);
395 $logger->info("applying backdate $backdate in overdue voiding");
396 $$bill_search{billing_ts} = {'>=' => $backdate};
399 my $bills = $e->search_money_billing($bill_search);
401 for my $bill (@$bills) {
402 next if $U->is_true($bill->voided);
403 $logger->info("voiding overdue bill ".$bill->id);
405 $bill->void_time('now');
406 $bill->voider($e->requestor->id);
407 my $n = $bill->note || "";
408 $bill->note("$n\nSystem: VOIDED FOR BACKDATE");
409 $e->update_money_billing($bill) or return $e->die_event;
418 __PACKAGE__->register_method(
419 method => "set_circ_claims_returned",
420 api_name => "open-ils.circ.circulation.set_claims_returned",
422 Sets the circ for the given item as claims returned
423 If a backdate is provided, overdue fines will be voided
426 @param args : barcode, backdate
430 sub set_circ_claims_returned {
431 my( $self, $conn, $auth, $args ) = @_;
433 my $e = new_editor(authtoken=>$auth, xact=>1);
434 return $e->die_event unless $e->checkauth;
436 my $barcode = $$args{barcode};
437 my $backdate = $$args{backdate};
439 $logger->info("marking circ for item $barcode as claims returned".
440 (($backdate) ? " with backdate $backdate" : ''));
442 my $copy = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'})->[0]
443 or return $e->die_event;
445 my $circ = $e->search_action_circulation(
446 {checkin_time => undef, target_copy => $copy->id})->[0]
447 or return $e->die_event;
449 $e->allowed('SET_CIRC_CLAIMS_RETURNED', $circ->circ_lib)
450 or return $e->die_event;
452 $circ->stop_fines(OILS_STOP_FINES_CLAIMSRETURNED);
453 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
456 # make it look like the circ stopped at the cliams returned time
457 $circ->stop_fines_time(clense_ISO8601($backdate));
458 my $evt = void_overdues($e, $circ, $backdate);
462 $e->update_action_circulation($circ) or return $e->die_event;
471 __PACKAGE__->register_method (
472 method => 'set_circ_due_date',
473 api_name => 'open-ils.circ.circulation.due_date.update',
475 Updates the due_date on the given circ
477 @param circid The id of the circ to update
478 @param date The timestamp of the new due date
482 sub set_circ_due_date {
483 my( $self, $conn, $auth, $circ_id, $date ) = @_;
485 my $e = new_editor(xact=>1, authtoken=>$auth);
486 return $e->die_event unless $e->checkauth;
487 my $circ = $e->retrieve_action_circulation($circ_id)
488 or return $e->die_event;
490 return $e->die_event unless $e->allowed('CIRC_OVERRIDE_DUE_DATE', $circ->circ_lib);
491 $date = clense_ISO8601($date);
492 $circ->due_date($date);
493 $e->update_action_circulation($circ) or return $e->die_event;
500 __PACKAGE__->register_method(
501 method => "create_in_house_use",
502 api_name => 'open-ils.circ.in_house_use.create',
504 Creates an in-house use action.
505 @param $authtoken The login session key
506 @param params A hash of params including
507 'location' The org unit id where the in-house use occurs
508 'copyid' The copy in question
509 'count' The number of in-house uses to apply to this copy
510 @return An array of id's representing the id's of the newly created
511 in-house use objects or an event on an error
514 __PACKAGE__->register_method(
515 method => "create_in_house_use",
516 api_name => 'open-ils.circ.non_cat_in_house_use.create',
520 sub create_in_house_use {
521 my( $self, $client, $auth, $params ) = @_;
524 my $org = $params->{location};
525 my $copyid = $params->{copyid};
526 my $count = $params->{count} || 1;
527 my $nc_type = $params->{non_cat_type};
528 my $use_time = $params->{use_time} || 'now';
530 my $e = new_editor(xact=>1,authtoken=>$auth);
531 return $e->event unless $e->checkauth;
532 return $e->event unless $e->allowed('CREATE_IN_HOUSE_USE');
534 my $non_cat = 1 if $self->api_name =~ /non_cat/;
538 $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
540 $copy = $e->search_asset_copy({barcode=>$params->{barcode}, deleted => 'f'})->[0]
546 if( $use_time ne 'now' ) {
547 $use_time = clense_ISO8601($use_time);
548 $logger->debug("in_house_use setting use time to $use_time");
559 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
560 $ihu->item_type($nc_type);
561 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
562 $cmeth = "create_action_non_cat_in_house_use";
565 $ihu = Fieldmapper::action::in_house_use->new;
567 $method = 'open-ils.storage.direct.action.in_house_use.create';
568 $cmeth = "create_action_in_house_use";
571 $ihu->staff($e->requestor->id);
572 $ihu->org_unit($org);
573 $ihu->use_time($use_time);
575 $ihu = $e->$cmeth($ihu) or return $e->event;
576 push( @ids, $ihu->id );
587 __PACKAGE__->register_method(
588 method => "view_circs",
589 api_name => "open-ils.circ.copy_checkout_history.retrieve",
591 Retrieves the last X circs for a given copy
592 @param authtoken The login session key
593 @param copyid The copy to check
594 @param count How far to go back in the item history
595 @return An array of circ ids
598 # ----------------------------------------------------------------------
599 # Returns $count most recent circs. If count exceeds the configured
600 # max, use the configured max instead
601 # ----------------------------------------------------------------------
603 my( $self, $client, $authtoken, $copyid, $count ) = @_;
605 my $e = new_editor(authtoken => $authtoken);
606 return $e->event unless $e->checkauth;
608 my $copy = $e->retrieve_asset_copy([
611 flesh_fields => {acp => ['call_number']}
613 ]) or return $e->event;
615 return $e->event unless $e->allowed(
616 'VIEW_COPY_CHECKOUT_HISTORY',
617 ($copy->call_number == OILS_PRECAT_CALL_NUMBER) ?
618 $copy->circ_lib : $copy->call_number->owning_lib);
620 my $max_history = $U->ou_ancestor_setting_value(
621 $e->requestor->ws_ou, 'circ.item_checkout_history.max', $e);
623 if(defined $max_history) {
624 $count = $max_history unless defined $count and $count < $max_history;
626 $count = 4 unless defined $count;
629 return $e->search_action_circulation([
630 {target_copy => $copyid},
631 {limit => $count, order_by => { circ => "xact_start DESC" }}
636 __PACKAGE__->register_method(
637 method => "circ_count",
638 api_name => "open-ils.circ.circulation.count",
640 Returns the number of times the item has circulated
641 @param copyid The copy to check
645 my( $self, $client, $copyid, $range ) = @_;
646 my $e = OpenILS::Utils::Editor->new;
647 return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
652 __PACKAGE__->register_method(
653 method => 'fetch_notes',
654 api_name => 'open-ils.circ.copy_note.retrieve.all',
656 Returns an array of copy note objects.
657 @param args A named hash of parameters including:
658 authtoken : Required if viewing non-public notes
659 itemid : The id of the item whose notes we want to retrieve
660 pub : True if all the caller wants are public notes
661 @return An array of note objects
664 __PACKAGE__->register_method(
665 method => 'fetch_notes',
666 api_name => 'open-ils.circ.call_number_note.retrieve.all',
667 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
669 __PACKAGE__->register_method(
670 method => 'fetch_notes',
671 api_name => 'open-ils.circ.title_note.retrieve.all',
672 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
675 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
677 my( $self, $connection, $args ) = @_;
679 my $id = $$args{itemid};
680 my $authtoken = $$args{authtoken};
683 if( $self->api_name =~ /copy/ ) {
685 return $U->cstorereq(
686 'open-ils.cstore.direct.asset.copy_note.search.atomic',
687 { owning_copy => $id, pub => 't' } );
689 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
691 return $U->cstorereq(
692 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
695 } elsif( $self->api_name =~ /call_number/ ) {
697 return $U->cstorereq(
698 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
699 { call_number => $id, pub => 't' } );
701 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
703 return $U->cstorereq(
704 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
707 } elsif( $self->api_name =~ /title/ ) {
709 return $U->cstorereq(
710 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
711 { record => $id, pub => 't' } );
713 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
715 return $U->cstorereq(
716 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
723 __PACKAGE__->register_method(
724 method => 'has_notes',
725 api_name => 'open-ils.circ.copy.has_notes');
726 __PACKAGE__->register_method(
727 method => 'has_notes',
728 api_name => 'open-ils.circ.call_number.has_notes');
729 __PACKAGE__->register_method(
730 method => 'has_notes',
731 api_name => 'open-ils.circ.title.has_notes');
735 my( $self, $conn, $authtoken, $id ) = @_;
736 my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
737 return $editor->event unless $editor->checkauth;
739 my $n = $editor->search_asset_copy_note(
740 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
742 $n = $editor->search_asset_call_number_note(
743 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
745 $n = $editor->search_biblio_record_note(
746 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
753 __PACKAGE__->register_method(
754 method => 'create_copy_note',
755 api_name => 'open-ils.circ.copy_note.create',
757 Creates a new copy note
758 @param authtoken The login session key
759 @param note The note object to create
760 @return The id of the new note object
763 sub create_copy_note {
764 my( $self, $connection, $authtoken, $note ) = @_;
766 my $e = new_editor(xact=>1, authtoken=>$authtoken);
767 return $e->event unless $e->checkauth;
768 my $copy = $e->retrieve_asset_copy(
772 flesh_fields => { 'acp' => ['call_number'] }
777 return $e->event unless
778 $e->allowed('CREATE_COPY_NOTE', $copy->call_number->owning_lib);
780 $note->create_date('now');
781 $note->creator($e->requestor->id);
782 $note->pub( ($U->is_true($note->pub)) ? 't' : 'f' );
785 $e->create_asset_copy_note($note) or return $e->event;
791 __PACKAGE__->register_method(
792 method => 'delete_copy_note',
793 api_name => 'open-ils.circ.copy_note.delete',
795 Deletes an existing copy note
796 @param authtoken The login session key
797 @param noteid The id of the note to delete
798 @return 1 on success - Event otherwise.
800 sub delete_copy_note {
801 my( $self, $conn, $authtoken, $noteid ) = @_;
803 my $e = new_editor(xact=>1, authtoken=>$authtoken);
804 return $e->die_event unless $e->checkauth;
806 my $note = $e->retrieve_asset_copy_note([
810 'acpn' => [ 'owning_copy' ],
811 'acp' => [ 'call_number' ],
814 ]) or return $e->die_event;
816 if( $note->creator ne $e->requestor->id ) {
817 return $e->die_event unless
818 $e->allowed('DELETE_COPY_NOTE', $note->owning_copy->call_number->owning_lib);
821 $e->delete_asset_copy_note($note) or return $e->die_event;
827 __PACKAGE__->register_method(
828 method => 'age_hold_rules',
829 api_name => 'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
833 my( $self, $conn ) = @_;
834 return new_editor()->retrieve_all_config_rules_age_hold_protect();
839 __PACKAGE__->register_method(
840 method => 'copy_details_barcode',
842 api_name => 'open-ils.circ.copy_details.retrieve.barcode');
843 sub copy_details_barcode {
844 my( $self, $conn, $auth, $barcode ) = @_;
845 my $e = new_editor();
846 my $cid = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'}, {idlist=>1})->[0];
847 return $e->event unless $cid;
848 return copy_details( $self, $conn, $auth, $cid );
852 __PACKAGE__->register_method(
853 method => 'copy_details',
854 api_name => 'open-ils.circ.copy_details.retrieve');
857 my( $self, $conn, $auth, $copy_id ) = @_;
858 my $e = new_editor(authtoken=>$auth);
859 return $e->event unless $e->checkauth;
861 my $flesh = { flesh => 1 };
863 my $copy = $e->retrieve_asset_copy(
869 acp => ['call_number'],
873 ]) or return $e->event;
876 # De-flesh the copy for backwards compatibility
878 my $vol = $copy->call_number;
880 $copy->call_number($vol->id);
881 my $record = $vol->record;
883 $vol->record($record->id);
884 $mvr = $U->record_to_mvr($record);
889 my $hold = $e->search_action_hold_request(
891 current_copy => $copy_id,
892 capture_time => { "!=" => undef },
893 fulfillment_time => undef,
894 cancel_time => undef,
898 OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
900 my $transit = $e->search_action_transit_copy(
901 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
903 # find the latest circ, open or closed
904 my $circ = $e->search_action_circulation(
906 { target_copy => $copy_id },
907 { order_by => { circ => 'xact_start desc' }, limit => 1 }
925 __PACKAGE__->register_method(
926 method => 'mark_item',
927 api_name => 'open-ils.circ.mark_item_damaged',
929 __PACKAGE__->register_method(
930 method => 'mark_item',
931 api_name => 'open-ils.circ.mark_item_missing',
935 my( $self, $conn, $auth, $copy_id ) = @_;
936 my $e = new_editor(authtoken=>$auth, xact =>1);
937 return $e->event unless $e->checkauth;
939 my $perm = 'MARK_ITEM_MISSING';
940 my $stat = OILS_COPY_STATUS_MISSING;
942 if( $self->api_name =~ /damaged/ ) {
943 $perm = 'MARK_ITEM_DAMAGED';
944 $stat = OILS_COPY_STATUS_DAMAGED;
947 my $copy = $e->retrieve_asset_copy($copy_id)
949 $copy->status($stat);
950 $copy->edit_date('now');
951 $copy->editor($e->requestor->id);
953 $e->update_asset_copy($copy) or return $e->event;
956 my $holds = $e->search_action_hold_request(
958 current_copy => $copy->id,
959 fulfillment_time => undef,
960 cancel_time => undef,
966 $logger->debug("reseting holds that target the marked copy");
967 OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds;
977 # ----------------------------------------------------------------------
978 __PACKAGE__->register_method(
979 method => 'magic_fetch',
980 api_name => 'open-ils.agent.fetch'
983 my @FETCH_ALLOWED = qw/ aou aout acp acn bre /;
986 my( $self, $conn, $auth, $args ) = @_;
987 my $e = new_editor( authtoken => $auth );
988 return $e->event unless $e->checkauth;
990 my $hint = $$args{hint};
993 # Is the call allowed to fetch this type of object?
994 return undef unless grep { $_ eq $hint } @FETCH_ALLOWED;
996 # Find the class the iplements the given hint
998 $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
1000 $class =~ s/Fieldmapper:://og;
1001 $class =~ s/::/_/og;
1002 my $method = "retrieve_$class";
1004 my $obj = $e->$method($id) or return $e->event;
1007 # ----------------------------------------------------------------------
1010 __PACKAGE__->register_method(
1011 method => "fleshed_circ_retrieve",
1013 api_name => "open-ils.circ.fleshed.retrieve",);
1015 sub fleshed_circ_retrieve {
1016 my( $self, $client, $id ) = @_;
1017 my $e = new_editor();
1018 my $circ = $e->retrieve_action_circulation(
1024 circ => [ qw/ target_copy / ],
1025 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect call_number / ],
1026 ascecm => [ qw/ stat_cat stat_cat_entry / ],
1027 acn => [ qw/ record / ],
1031 ) or return $e->event;
1033 my $copy = $circ->target_copy;
1034 my $vol = $copy->call_number;
1035 my $rec = $circ->target_copy->call_number->record;
1037 $vol->record($rec->id);
1038 $copy->call_number($vol->id);
1039 $circ->target_copy($copy->id);
1043 if( $rec->id == OILS_PRECAT_RECORD ) {
1047 $mvr = $U->record_to_mvr($rec);
1048 $rec->marc(''); # drop the bulky marc data
1060 # {"select":{"acp":["id"],"circ":[{"aggregate":true,"transform":"count","alias":"count","column":"id"}]},"from":{"acp":{"circ":{"field":"target_copy","fkey":"id","type":"left"},"acn"{"field":"id","fkey":"call_number"}}},"where":{"+acn":{"record":200057}}