1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
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::HoldNotify;
10 use OpenILS::Application::Circ::Money;
11 use OpenILS::Application::Circ::NonCat;
12 use OpenILS::Application::Circ::CopyLocations;
15 use DateTime::Format::ISO8601;
17 use OpenILS::Application::AppUtils;
19 use OpenSRF::Utils qw/:datetime/;
20 use OpenILS::Utils::ModsParser;
22 use OpenSRF::EX qw(:try);
23 use OpenSRF::Utils::Logger qw(:logger);
24 use OpenILS::Utils::Fieldmapper;
25 use OpenILS::Utils::Editor;
26 use OpenILS::Utils::CStoreEditor q/:funcs/;
27 use OpenILS::Const qw/:const/;
28 use OpenSRF::Utils::SettingsClient;
30 my $apputils = "OpenILS::Application::AppUtils";
34 # ------------------------------------------------------------------------
35 # Top level Circ package;
36 # ------------------------------------------------------------------------
40 OpenILS::Application::Circ::Circulate->initialize();
44 __PACKAGE__->register_method(
45 method => 'retrieve_circ',
46 api_name => 'open-ils.circ.retrieve',
48 Retrieve a circ object by id
49 @param authtoken Login session key
50 @pararm circid The id of the circ object
54 my( $s, $c, $a, $i ) = @_;
55 my $e = new_editor(authtoken => $a);
56 return $e->event unless $e->checkauth;
57 my $circ = $e->retrieve_action_circulation($i) or return $e->event;
58 if( $e->requestor->id ne $circ->usr ) {
59 return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
65 __PACKAGE__->register_method(
66 method => 'fetch_circ_mods',
67 api_name => 'open-ils.circ.circ_modifier.retrieve.all');
69 my $conf = OpenSRF::Utils::SettingsClient->new;
70 return $conf->config_value(
71 'apps', 'open-ils.circ', 'app_settings', 'circ_modifiers', 'mod' );
74 __PACKAGE__->register_method(
75 method => 'fetch_bill_types',
76 api_name => 'open-ils.circ.billing_type.retrieve.all');
77 sub fetch_bill_types {
78 my $conf = OpenSRF::Utils::SettingsClient->new;
79 return $conf->config_value(
80 'apps', 'open-ils.circ', 'app_settings', 'billing_types', 'type' );
84 # ------------------------------------------------------------------------
85 # Returns an array of {circ, record} hashes checked out by the user.
86 # ------------------------------------------------------------------------
87 __PACKAGE__->register_method(
88 method => "checkouts_by_user",
89 api_name => "open-ils.circ.actor.user.checked_out",
91 Returns a list of open circulations as a pile of objects. each object
92 contains the relevant copy, circ, and record
95 sub checkouts_by_user {
96 my( $self, $client, $user_session, $user_id ) = @_;
98 my( $requestor, $target, $copy, $record, $evt );
100 ( $requestor, $target, $evt ) =
101 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
104 my $circs = $apputils->simplereq(
106 "open-ils.cstore.direct.action.open_circulation.search.atomic",
107 { usr => $target->id, checkin_time => undef } );
108 # { usr => $target->id } );
111 for my $circ (@$circs) {
113 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
116 $logger->debug("Retrieving record for copy " . $circ->target_copy);
118 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
121 my $mods = $apputils->record_to_mvr($record);
123 push( @results, { copy => $copy, circ => $circ, record => $mods } );
132 __PACKAGE__->register_method(
133 method => "checkouts_by_user_slim",
134 api_name => "open-ils.circ.actor.user.checked_out.slim",
135 NOTES => <<" NOTES");
136 Returns a list of open circulation objects
140 sub checkouts_by_user_slim {
141 my( $self, $client, $user_session, $user_id ) = @_;
143 my( $requestor, $target, $copy, $record, $evt );
145 ( $requestor, $target, $evt ) =
146 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
149 $logger->debug( 'User ' . $requestor->id .
150 " retrieving checked out items for user " . $target->id );
152 # XXX Make the call correct..
153 return $apputils->simplereq(
155 "open-ils.cstore.direct.action.open_circulation.search.atomic",
156 { usr => $target->id, checkin_time => undef } );
157 # { usr => $target->id } );
161 __PACKAGE__->register_method(
162 method => "checkouts_by_user_opac",
163 api_name => "open-ils.circ.actor.user.checked_out.opac",);
166 sub checkouts_by_user_opac {
167 my( $self, $client, $auth, $user_id ) = @_;
169 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
170 return $e->event unless $e->checkauth;
171 $user_id ||= $e->requestor->id;
172 return $e->event unless
173 my $patron = $e->retrieve_actor_user($user_id);
176 my $search = {usr => $user_id, stop_fines => undef};
178 if( $user_id ne $e->requestor->id ) {
179 $data = $e->search_action_circulation(
180 $search, {checkperm=>1, permorg=>$patron->home_ou})
184 $data = $e->search_action_circulation($search);
191 __PACKAGE__->register_method(
192 method => "title_from_transaction",
193 api_name => "open-ils.circ.circ_transaction.find_title",
194 NOTES => <<" NOTES");
195 Returns a mods object for the title that is linked to from the
196 copy from the hold that created the given transaction
199 sub title_from_transaction {
200 my( $self, $client, $login_session, $transactionid ) = @_;
202 my( $user, $circ, $title, $evt );
204 ( $user, $evt ) = $apputils->checkses( $login_session );
207 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
210 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
213 return $apputils->record_to_mvr($title);
217 __PACKAGE__->register_method(
218 method => "set_circ_lost",
219 api_name => "open-ils.circ.circulation.set_lost",
220 NOTES => <<" NOTES");
221 Params are login, barcode
222 login must have SET_CIRC_LOST perms
223 Sets a circulation to lost
226 __PACKAGE__->register_method(
227 method => "set_circ_lost",
228 api_name => "open-ils.circ.circulation.set_claims_returned",
229 NOTES => <<" NOTES");
230 Params are login, barcode
231 login must have SET_CIRC_MISSING perms
232 Sets a circulation to lost
236 my( $self, $client, $login, $args ) = @_;
237 my( $user, $circ, $copy, $evt );
239 my $barcode = $$args{barcode};
240 my $backdate = $$args{backdate};
242 ( $user, $evt ) = $U->checkses($login);
245 # Grab the related copy
246 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
249 my $isclaims = $self->api_name =~ /claims_returned/;
250 my $islost = $self->api_name =~ /lost/;
251 my $session = $U->start_db_session();
253 # grab the circulation
254 # ( $circ ) = $U->fetch_open_circulation( $copy->id );
255 # return 1 unless $circ;
257 $circ = new_editor()->search_action_circulation(
258 { checkin_time => undef, target_copy => $copy->id } )->[0];
259 return 1 unless $circ;
262 $evt = _set_circ_lost($copy, $circ, $user, $session) if $islost;
267 $evt = _set_circ_claims_returned(
268 $user, $circ, $session, $backdate );
273 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
274 my $s = $session->request(
275 "open-ils.storage.direct.action.circulation.update", $circ )->gather(1);
277 return $U->DB_UPDATE_FAILED($circ) unless defined($s);
278 $U->commit_db_session($session);
284 my( $copy, $circ, $reqr, $session ) = @_;
286 my $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'SET_CIRC_LOST');
289 $logger->activity("user ".$reqr->id." marking copy ".$copy->id.
290 " lost for circ ". $circ->id. " and checking for necessary charges");
292 if( $copy->status ne OILS_COPY_STATUS_LOST ) {
293 $copy->status(OILS_COPY_STATUS_LOST);
297 session => $session);
300 # if the copy has a price defined and/or a processing fee, bill the patron
302 # if the location that owns the copy has a processing fee, charge the user
303 my $owner = $U->fetch_copy_owner($copy->id);
304 $logger->info("circ fetching org settings for $owner ".
305 "to determine processing fee and default copy price");
307 my $settings = $U->simplereq(
308 'open-ils.actor', 'open-ils.actor.org_unit.settings.retrieve', $owner );
309 my $fee = $settings->{'circ.lost_materials_processing_fee'} || 0;
311 # If the copy has a price configured, charge said price to the user
312 # otherwise use the default price
313 my $s = OILS_SETTING_DEF_ITEM_PRICE;
314 my $copy_price = $copy->price;
315 $copy_price = $settings->{$s} unless defined $copy_price;
316 if($copy_price and $copy_price > 0) {
317 $logger->debug("lost copy has a price of $copy_price");
318 $evt = _make_bill($session, $copy_price, 'Lost Materials', $circ->id);
324 $evt = _make_bill($session, $fee, 'Lost Materials Processing Fee', $circ->id);
328 $circ->stop_fines(OILS_STOP_FINES_LOST);
333 my( $session, $amount, $type, $xactid ) = @_;
335 $logger->info("The system is charging $amount ".
336 " [$type] for lost materials on circulation $xactid");
338 # -----------------------------------------------------------------
339 # make sure the transaction is not closed
340 my $e = new_editor(xact=>1);
341 my $xact = $e->retrieve_money_billable_transaction($xactid)
342 or return $e->die_event;
344 if( $xact->xact_finish ) {
345 my ($mbts) = $U->fetch_mbts($xactid, $e);
346 if( ($mbts->balance_owed + $amount) != 0 ) {
347 $logger->info("re-opening xact $xactid");
348 $xact->clear_xact_finish;
349 $e->update_money_billable_transaction($xact)
350 or return $e->die_event;
355 $e->rollback; # has no effect if it's already been comitted
356 # -----------------------------------------------------------------
359 my $bill = Fieldmapper::money::billing->new;
360 $bill->xact($xactid);
361 $bill->amount($amount);
362 $bill->billing_type($type);
363 $bill->note('SYSTEM GENERATED');
365 my $id = $session->request(
366 'open-ils.storage.direct.money.billing.create', $bill )->gather(1);
368 return $U->DB_UPDATE_FAILED($bill) unless defined $id;
372 sub _set_circ_claims_returned {
373 my( $reqr, $circ, $session, $backdate ) = @_;
375 my $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'SET_CIRC_CLAIMS_RETURNED');
377 $circ->stop_fines("CLAIMSRETURNED");
379 $logger->info("user ".$reqr->id.
380 " marking circ". $circ->id. " as claims returned with backdate $backdate");
382 # allow the caller to backdate the circulation and void any fines
383 # that occurred after the backdate
385 my $s = cr_handle_backdate($backdate, $circ, $reqr, $session );
386 $logger->debug("backdate method returned $s");
387 $circ->stop_fines_time(clense_ISO8601($backdate))
393 sub cr_handle_backdate {
394 my( $backdate, $circ, $requestor, $session, $closecirc ) = @_;
397 $bd =~ s/^(\d{4}-\d{2}-\d{2}).*/$1/og;
398 $bd = "${bd}T23:59:59";
400 my $bills = $session->request(
401 "open-ils.storage.direct.money.billing.search_where.atomic",
402 billing_ts => { '>=' => $bd },
404 billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
407 $logger->debug("backdate found ".scalar(@$bills)." bills to void");
410 for my $bill (@$bills) {
411 unless( $U->is_true($bill->voided) ) {
412 $logger->info("voiding bill ".$bill->id);
414 $bill->void_time('now');
415 $bill->voider($requestor->id);
416 my $n = $bill->note || "";
417 $bill->note($n . "\nSystem: VOIDED FOR BACKDATE");
418 my $s = $session->request(
419 "open-ils.storage.direct.money.billing.update", $bill)->gather(1);
420 return $U->DB_UPDATE_FAILED($bill) unless $s;
432 __PACKAGE__->register_method (
433 method => 'set_circ_due_date',
434 api_name => 'open-ils.circ.circulation.due_date.update',
436 Updates the due_date on the given circ
438 @param circid The id of the circ to update
439 @param date The timestamp of the new due date
443 sub set_circ_due_date {
444 my( $s, $c, $authtoken, $circid, $date ) = @_;
445 my ($circ, $evt) = $U->fetch_circulation($circid);
449 ($reqr, $evt) = $U->checkses($authtoken);
452 $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'CIRC_OVERRIDE_DUE_DATE');
455 $date = clense_ISO8601($date);
456 $logger->activity("user ".$reqr->id.
457 " updating due_date on circ $circid: $date");
459 $circ->due_date($date);
460 my $stat = $U->storagereq(
461 'open-ils.storage.direct.action.circulation.update', $circ);
462 return $U->DB_UPDATE_FAILED unless defined $stat;
467 __PACKAGE__->register_method(
468 method => "create_in_house_use",
469 api_name => 'open-ils.circ.in_house_use.create',
471 Creates an in-house use action.
472 @param $authtoken The login session key
473 @param params A hash of params including
474 'location' The org unit id where the in-house use occurs
475 'copyid' The copy in question
476 'count' The number of in-house uses to apply to this copy
477 @return An array of id's representing the id's of the newly created
478 in-house use objects or an event on an error
481 __PACKAGE__->register_method(
482 method => "create_in_house_use",
483 api_name => 'open-ils.circ.non_cat_in_house_use.create',
487 sub ___create_in_house_use {
488 my( $self, $client, $authtoken, $params ) = @_;
490 my( $staff, $evt, $copy );
491 my $org = $params->{location};
492 my $copyid = $params->{copyid};
493 my $count = $params->{count} || 1;
494 my $nc_type = $params->{non_cat_type};
495 my $use_time = $params->{use_time} || 'now';
497 my $non_cat = 1 if $self->api_name =~ /non_cat/;
501 my $barcode = $params->{barcode};
502 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
506 ($copy, $evt) = $U->fetch_copy($copyid) unless $copy;
510 ($staff, $evt) = $U->checkses($authtoken);
513 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
516 if( $use_time ne 'now' ) {
517 $use_time = clense_ISO8601($use_time);
518 $logger->debug("in_house_use setting use time to $use_time");
528 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
529 $ihu->noncat_type($nc_type);
530 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
532 $ihu = Fieldmapper::action::in_house_use->new;
534 $method = 'open-ils.storage.direct.action.in_house_use.create';
537 $ihu->staff($staff->id);
538 $ihu->org_unit($org);
539 $ihu->use_time($use_time);
541 my $id = $U->simplereq('open-ils.storage', $method, $ihu );
543 return $U->DB_UPDATE_FAILED($ihu) unless $id;
554 sub create_in_house_use {
555 my( $self, $client, $auth, $params ) = @_;
558 my $org = $params->{location};
559 my $copyid = $params->{copyid};
560 my $count = $params->{count} || 1;
561 my $nc_type = $params->{non_cat_type};
562 my $use_time = $params->{use_time} || 'now';
564 my $e = new_editor(xact=>1,authtoken=>$auth);
565 return $e->event unless $e->checkauth;
566 return $e->event unless $e->allowed('CREATE_IN_HOUSE_USE');
568 my $non_cat = 1 if $self->api_name =~ /non_cat/;
572 $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
574 $copy = $e->search_asset_copy({barcode=>$params->{barcode}, deleted => 'f'})->[0]
580 if( $use_time ne 'now' ) {
581 $use_time = clense_ISO8601($use_time);
582 $logger->debug("in_house_use setting use time to $use_time");
593 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
594 $ihu->item_type($nc_type);
595 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
596 $cmeth = "create_action_non_cat_in_house_use";
599 $ihu = Fieldmapper::action::in_house_use->new;
601 $method = 'open-ils.storage.direct.action.in_house_use.create';
602 $cmeth = "create_action_in_house_use";
605 $ihu->staff($e->requestor->id);
606 $ihu->org_unit($org);
607 $ihu->use_time($use_time);
609 $ihu = $e->$cmeth($ihu) or return $e->event;
610 push( @ids, $ihu->id );
621 __PACKAGE__->register_method(
622 method => "view_circs",
623 api_name => "open-ils.circ.copy_checkout_history.retrieve",
625 Retrieves the last X circs for a given copy
626 @param authtoken The login session key
627 @param copyid The copy to check
628 @param count How far to go back in the item history
629 @return An array of circ ids
635 my( $self, $client, $authtoken, $copyid, $count ) = @_;
637 my( $requestor, $evt ) = $U->checksesperm(
638 $authtoken, 'VIEW_COPY_CHECKOUT_HISTORY' );
641 return [] unless $count;
643 my $circs = $U->cstorereq(
644 'open-ils.cstore.direct.action.circulation.search.atomic',
646 target_copy => $copyid,
650 order_by => { circ => "xact_start DESC" }
658 __PACKAGE__->register_method(
659 method => "circ_count",
660 api_name => "open-ils.circ.circulation.count",
662 Returns the number of times the item has circulated
663 @param copyid The copy to check
667 my( $self, $client, $copyid, $range ) = @_;
668 my $e = OpenILS::Utils::Editor->new;
669 return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
674 __PACKAGE__->register_method(
675 method => 'fetch_notes',
676 api_name => 'open-ils.circ.copy_note.retrieve.all',
678 Returns an array of copy note objects.
679 @param args A named hash of parameters including:
680 authtoken : Required if viewing non-public notes
681 itemid : The id of the item whose notes we want to retrieve
682 pub : True if all the caller wants are public notes
683 @return An array of note objects
686 __PACKAGE__->register_method(
687 method => 'fetch_notes',
688 api_name => 'open-ils.circ.call_number_note.retrieve.all',
689 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
691 __PACKAGE__->register_method(
692 method => 'fetch_notes',
693 api_name => 'open-ils.circ.title_note.retrieve.all',
694 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
697 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
699 my( $self, $connection, $args ) = @_;
701 my $id = $$args{itemid};
702 my $authtoken = $$args{authtoken};
705 if( $self->api_name =~ /copy/ ) {
707 return $U->cstorereq(
708 'open-ils.cstore.direct.asset.copy_note.search.atomic',
709 { owning_copy => $id, pub => 't' } );
711 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
713 return $U->cstorereq(
714 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
717 } elsif( $self->api_name =~ /call_number/ ) {
719 return $U->cstorereq(
720 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
721 { call_number => $id, pub => 't' } );
723 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
725 return $U->cstorereq(
726 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
729 } elsif( $self->api_name =~ /title/ ) {
731 return $U->cstorereq(
732 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
733 { record => $id, pub => 't' } );
735 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
737 return $U->cstorereq(
738 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
745 __PACKAGE__->register_method(
746 method => 'has_notes',
747 api_name => 'open-ils.circ.copy.has_notes');
748 __PACKAGE__->register_method(
749 method => 'has_notes',
750 api_name => 'open-ils.circ.call_number.has_notes');
751 __PACKAGE__->register_method(
752 method => 'has_notes',
753 api_name => 'open-ils.circ.title.has_notes');
757 my( $self, $conn, $authtoken, $id ) = @_;
758 my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
759 return $editor->event unless $editor->checkauth;
761 my $n = $editor->search_asset_copy_note(
762 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
764 $n = $editor->search_asset_call_number_note(
765 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
767 $n = $editor->search_biblio_record_note(
768 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
775 __PACKAGE__->register_method(
776 method => 'create_copy_note',
777 api_name => 'open-ils.circ.copy_note.create',
779 Creates a new copy note
780 @param authtoken The login session key
781 @param note The note object to create
782 @return The id of the new note object
785 sub create_copy_note {
786 my( $self, $connection, $authtoken, $note ) = @_;
788 my $e = new_editor(xact=>1, authtoken=>$authtoken);
789 return $e->event unless $e->checkauth;
790 my $copy = $e->retrieve_asset_copy(
794 flesh_fields => { 'acp' => ['call_number'] }
799 return $e->event unless
800 $e->allowed('CREATE_COPY_NOTE', $copy->call_number->owning_lib);
802 $note->create_date('now');
803 $note->creator($e->requestor->id);
804 $note->pub( ($U->is_true($note->pub)) ? 't' : 'f' );
807 $e->create_asset_copy_note($note) or return $e->event;
813 __PACKAGE__->register_method(
814 method => 'delete_copy_note',
815 api_name => 'open-ils.circ.copy_note.delete',
817 Deletes an existing copy note
818 @param authtoken The login session key
819 @param noteid The id of the note to delete
820 @return 1 on success - Event otherwise.
822 sub delete_copy_note {
823 my( $self, $conn, $authtoken, $noteid ) = @_;
825 my $e = new_editor(xact=>1, authtoken=>$authtoken);
826 return $e->die_event unless $e->checkauth;
828 my $note = $e->retrieve_asset_copy_note([
832 'acpn' => [ 'owning_copy' ],
833 'acp' => [ 'call_number' ],
836 ]) or return $e->die_event;
838 if( $note->creator ne $e->requestor->id ) {
839 return $e->die_event unless
840 $e->allowed('DELETE_COPY_NOTE', $note->owning_copy->call_number->owning_lib);
843 $e->delete_asset_copy_note($note) or return $e->die_event;
849 __PACKAGE__->register_method(
850 method => 'age_hold_rules',
851 api_name => 'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
855 my( $self, $conn ) = @_;
856 return new_editor()->retrieve_all_config_rules_age_hold_protect();
861 __PACKAGE__->register_method(
862 method => 'copy_details_barcode',
863 api_name => 'open-ils.circ.copy_details.retrieve.barcode');
864 sub copy_details_barcode {
865 my( $self, $conn, $auth, $barcode ) = @_;
866 return $self->copy_details( $conn, $auth,
867 new_editor()->search_asset_copy({barcode=>$barcode,deleted=>'f'},{idlist=>1})->[0]);
871 __PACKAGE__->register_method(
872 method => 'copy_details',
873 api_name => 'open-ils.circ.copy_details.retrieve');
876 my( $self, $conn, $auth, $copy_id ) = @_;
877 my $e = new_editor(authtoken=>$auth);
878 return $e->event unless $e->checkauth;
880 my $flesh = { flesh => 1 };
882 my $copy = $e->retrieve_asset_copy(
888 acp => ['call_number'],
892 ]) or return $e->event;
895 # De-flesh the copy for backwards compatibility
897 my $vol = $copy->call_number;
899 $copy->call_number($vol->id);
900 my $record = $vol->record;
902 $vol->record($record->id);
903 $mvr = $U->record_to_mvr($record);
908 my $hold = $e->search_action_hold_request(
910 current_copy => $copy_id,
911 capture_time => { "!=" => undef },
912 fulfillment_time => undef,
913 cancel_time => undef,
917 OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
919 my $transit = $e->search_action_transit_copy(
920 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
922 # find the latest circ, open or closed
923 my $circ = $e->search_action_circulation(
925 { target_copy => $copy_id },
926 { order_by => { circ => 'xact_start desc' }, limit => 1 }
944 __PACKAGE__->register_method(
945 method => 'mark_item',
946 api_name => 'open-ils.circ.mark_item_damaged',
948 __PACKAGE__->register_method(
949 method => 'mark_item',
950 api_name => 'open-ils.circ.mark_item_missing',
954 my( $self, $conn, $auth, $copy_id ) = @_;
955 my $e = new_editor(authtoken=>$auth, xact =>1);
956 return $e->event unless $e->checkauth;
958 my $perm = 'MARK_ITEM_MISSING';
959 my $stat = OILS_COPY_STATUS_MISSING;
961 if( $self->api_name =~ /damaged/ ) {
962 $perm = 'MARK_ITEM_DAMAGED';
963 $stat = OILS_COPY_STATUS_DAMAGED;
966 my $copy = $e->retrieve_asset_copy($copy_id)
968 $copy->status($stat);
969 $copy->edit_date('now');
970 $copy->editor($e->requestor->id);
972 $e->update_asset_copy($copy) or return $e->event;
975 my $holds = $e->search_action_hold_request(
977 current_copy => $copy->id,
978 fulfillment_time => undef,
979 cancel_time => undef,
985 $logger->debug("reseting holds that target the marked copy");
986 OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds;
996 # ----------------------------------------------------------------------
997 __PACKAGE__->register_method(
998 method => 'magic_fetch',
999 api_name => 'open-ils.agent.fetch'
1002 my @FETCH_ALLOWED = qw/ aou aout acp acn bre /;
1005 my( $self, $conn, $auth, $args ) = @_;
1006 my $e = new_editor( authtoken => $auth );
1007 return $e->event unless $e->checkauth;
1009 my $hint = $$args{hint};
1010 my $id = $$args{id};
1012 # Is the call allowed to fetch this type of object?
1013 return undef unless grep { $_ eq $hint } @FETCH_ALLOWED;
1015 # Find the class the iplements the given hint
1016 my ($class) = grep {
1017 $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
1019 $class =~ s/Fieldmapper:://og;
1020 $class =~ s/::/_/og;
1021 my $method = "retrieve_$class";
1023 my $obj = $e->$method($id) or return $e->event;
1026 # ----------------------------------------------------------------------
1029 __PACKAGE__->register_method(
1030 method => "fleshed_circ_retrieve",
1031 api_name => "open-ils.circ.fleshed.retrieve",);
1033 sub fleshed_circ_retrieve {
1034 my( $self, $client, $id ) = @_;
1035 my $e = new_editor();
1036 my $circ = $e->retrieve_action_circulation(
1042 circ => [ qw/ target_copy / ],
1043 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect call_number / ],
1044 ascecm => [ qw/ stat_cat stat_cat_entry / ],
1045 acn => [ qw/ record / ],
1049 ) or return $e->event;
1051 my $copy = $circ->target_copy;
1052 my $vol = $copy->call_number;
1053 my $rec = $circ->target_copy->call_number->record;
1055 $vol->record($rec->id);
1056 $copy->call_number($vol->id);
1057 $circ->target_copy($copy->id);
1061 if( $rec->id == OILS_PRECAT_RECORD ) {
1065 $mvr = $U->record_to_mvr($rec);
1066 $rec->marc(''); # drop the bulky marc data