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);
218 __PACKAGE__->register_method(
219 method => "new_set_circ_lost",
220 api_name => "open-ils.circ.circulation.set_lost",
222 Sets the copy and related open circulation to lost
224 @param args : barcode
229 # ---------------------------------------------------------------------
230 # Sets a circulation to lost. updates copy status to lost
231 # applies copy and/or prcoessing fees depending on org settings
232 # ---------------------------------------------------------------------
233 sub new_set_circ_lost {
234 my( $self, $conn, $auth, $args ) = @_;
236 my $e = new_editor(authtoken=>$auth, xact=>1);
237 return $e->die_event unless $e->checkauth;
239 my $barcode = $$args{barcode};
240 $logger->info("marking item lost $barcode");
242 # ---------------------------------------------------------------------
244 my $copy = $e->search_asset_copy([
245 {barcode=>$barcode, deleted=>'f'},
246 {flesh => 1, flesh_fields => {'acp' => ['call_number']}}])->[0]
247 or return $e->die_event;
250 ($copy->call_number == OILS_PRECAT_CALL_NUMBER) ?
251 $copy->circ_lib : $copy->call_number->owning_lib;
253 my $circ = $e->search_action_circulation(
254 {checkin_time => undef, target_copy => $copy->id} )->[0]
255 or return $e->die_event;
257 $e->allowed('SET_CIRC_LOST', $circ->circ_lib) or return $e->die_event;
259 # ---------------------------------------------------------------------
260 # fetch the related org settings
261 my $default_price = $U->ou_ancestor_setting_value(
262 $owning_lib, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
263 my $proc_fee = $U->ou_ancestor_setting_value(
264 $owning_lib, OILS_SETTING_LOST_PROCESSING_FEE, $e) || 0;
265 my $charge_on_0 = $U->ou_ancestor_setting_value(
266 $owning_lib, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0;
267 my $void_overdue = $U->ou_ancestor_setting_value(
268 $owning_lib, OILS_SETTING_VOID_OVERDUE_ON_LOST, $e) || 0;
270 $logger->info("org settings: default price = $default_price, ".
271 "processing fee = $proc_fee, charge on 0 = $charge_on_0, void overdues = $void_overdue");
273 # ---------------------------------------------------------------------
274 # move the copy into LOST status
275 unless( $copy->status == OILS_COPY_STATUS_LOST ) {
276 $copy->status(OILS_COPY_STATUS_LOST);
277 $copy->editor($e->requestor->id);
278 $copy->edit_date('now');
279 $e->update_asset_copy($copy) or return $e->die_event;
282 # ---------------------------------------------------------------------
283 # determine the appropriate item price to charge and create the billing
284 my $price = $copy->price;
285 $price = $default_price unless defined $price;
286 $price = 0 if $price < 0;
287 $price = $default_price if $price == 0 and $charge_on_0;
290 my $evt = create_bill($e, $price, 'Lost Materials', $circ->id);
294 # ---------------------------------------------------------------------
295 # if there is a processing fee, charge that too
296 if( $proc_fee > 0 ) {
297 my $evt = create_bill($e, $proc_fee, 'Lost Materials Processing Fee', $circ->id);
301 # ---------------------------------------------------------------------
302 # mark the circ as lost and stop the fines
303 $circ->stop_fines(OILS_STOP_FINES_LOST);
304 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
305 $e->update_action_circulation($circ) or return $e->die_event;
307 # ---------------------------------------------------------------------
308 # void all overdue fines on this circ if configured
309 if( $void_overdue ) {
310 my $evt = void_overdues($e, $circ);
320 my( $e, $amount, $type, $xactid ) = @_;
322 $logger->info("The system is charging $amount [$type] on xact $xactid");
324 # -----------------------------------------------------------------
325 # make sure the transaction is not closed
326 my $xact = $e->retrieve_money_billable_transaction($xactid)
327 or return $e->die_event;
329 if( $xact->xact_finish ) {
330 my ($mbts) = $U->fetch_mbts($xactid, $e);
331 if( ($mbts->balance_owed + $amount) != 0 ) {
332 $logger->info("* re-opening xact $xactid");
333 $xact->clear_xact_finish;
334 $e->update_money_billable_transaction($xact)
335 or return $e->die_event;
339 # -----------------------------------------------------------------
340 # now create the billing
341 my $bill = Fieldmapper::money::billing->new;
342 $bill->xact($xactid);
343 $bill->amount($amount);
344 $bill->billing_type($type);
345 $bill->note('SYSTEM GENERATED');
346 $e->create_money_billing($bill) or return $e->die_event;
353 # -----------------------------------------------------------------
354 # Voids overdue fines on the given circ. if a backdate is
355 # provided, then we only void back to the backdate
356 # -----------------------------------------------------------------
358 my( $e, $circ, $backdate ) = @_;
362 billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
366 # ------------------------------------------------------------------
367 # Fines for overdue materials are assessed up to, but not including,
368 # one fine interval after the fines are applicable. Here, we add
369 # one fine interval to the backdate to ensure that we are not
370 # voiding fines that were applicable before the backdate.
371 # ------------------------------------------------------------------
372 my $interval = OpenSRF::Utils->interval_to_seconds($circ->fine_interval);
373 my $date = DateTime::Format::ISO8601->parse_datetime($backdate);
374 $backdate = $U->epoch2ISO8601($date->epoch + $interval);
375 $logger->info("applying backdate $backdate in overdue voiding");
376 $$bill_search{billing_ts} = {'>=' => $backdate};
379 my $bills = $e->search_money_billing($bill_search);
381 for my $bill (@$bills) {
382 next if $U->is_true($bill->voided);
383 $logger->info("voiding overdue bill ".$bill->id);
385 $bill->void_time('now');
386 $bill->voider($e->requestor->id);
387 my $n = $bill->note || "";
388 $bill->note("$n\nSystem: VOIDED FOR BACKDATE");
389 $e->update_money_billing($bill) or return $e->die_event;
398 __PACKAGE__->register_method(
399 method => "set_circ_claims_returned",
400 api_name => "open-ils.circ.circulation.set_claims_returned",
402 Sets the circ for the given item as claims returned
403 If a backdate is provided, overdue fines will be voided
406 @param args : barcode, backdate
410 sub set_circ_claims_returned {
411 my( $self, $conn, $auth, $args ) = @_;
413 my $e = new_editor(authtoken=>$auth, xact=>1);
414 return $e->die_event unless $e->checkauth;
416 my $barcode = $$args{barcode};
417 my $backdate = $$args{backdate};
419 $logger->info("marking circ for item $barcode as claims returned");
421 my $copy = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'})->[0]
422 or return $e->die_event;
424 my $circ = $e->search_action_circulation(
425 {checkin_time => undef, target_copy => $copy->id})->[0]
426 or return $e->die_event;
428 $e->allowed('SET_CIRC_CLAIMS_RETURNED', $circ->circ_lib)
429 or return $e->die_event;
431 $circ->stop_fines(OILS_STOP_FINES_CLAIMSRETURNED);
432 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
433 $e->update_action_circulation($circ) or return $e->die_event;
436 # make it look like the circ stopped at the cliams returned time
437 $circ->stop_fines_time(clense_ISO8601($backdate));
438 my $evt = void_overdues($e, $circ, $backdate);
450 __PACKAGE__->register_method (
451 method => 'set_circ_due_date',
452 api_name => 'open-ils.circ.circulation.due_date.update',
454 Updates the due_date on the given circ
456 @param circid The id of the circ to update
457 @param date The timestamp of the new due date
461 sub set_circ_due_date {
462 my( $s, $c, $authtoken, $circid, $date ) = @_;
463 my ($circ, $evt) = $U->fetch_circulation($circid);
467 ($reqr, $evt) = $U->checkses($authtoken);
470 $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'CIRC_OVERRIDE_DUE_DATE');
473 $date = clense_ISO8601($date);
474 $logger->activity("user ".$reqr->id.
475 " updating due_date on circ $circid: $date");
477 $circ->due_date($date);
478 my $stat = $U->storagereq(
479 'open-ils.storage.direct.action.circulation.update', $circ);
480 return $U->DB_UPDATE_FAILED unless defined $stat;
485 __PACKAGE__->register_method(
486 method => "create_in_house_use",
487 api_name => 'open-ils.circ.in_house_use.create',
489 Creates an in-house use action.
490 @param $authtoken The login session key
491 @param params A hash of params including
492 'location' The org unit id where the in-house use occurs
493 'copyid' The copy in question
494 'count' The number of in-house uses to apply to this copy
495 @return An array of id's representing the id's of the newly created
496 in-house use objects or an event on an error
499 __PACKAGE__->register_method(
500 method => "create_in_house_use",
501 api_name => 'open-ils.circ.non_cat_in_house_use.create',
505 sub ___create_in_house_use {
506 my( $self, $client, $authtoken, $params ) = @_;
508 my( $staff, $evt, $copy );
509 my $org = $params->{location};
510 my $copyid = $params->{copyid};
511 my $count = $params->{count} || 1;
512 my $nc_type = $params->{non_cat_type};
513 my $use_time = $params->{use_time} || 'now';
515 my $non_cat = 1 if $self->api_name =~ /non_cat/;
519 my $barcode = $params->{barcode};
520 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
524 ($copy, $evt) = $U->fetch_copy($copyid) unless $copy;
528 ($staff, $evt) = $U->checkses($authtoken);
531 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
534 if( $use_time ne 'now' ) {
535 $use_time = clense_ISO8601($use_time);
536 $logger->debug("in_house_use setting use time to $use_time");
546 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
547 $ihu->noncat_type($nc_type);
548 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
550 $ihu = Fieldmapper::action::in_house_use->new;
552 $method = 'open-ils.storage.direct.action.in_house_use.create';
555 $ihu->staff($staff->id);
556 $ihu->org_unit($org);
557 $ihu->use_time($use_time);
559 my $id = $U->simplereq('open-ils.storage', $method, $ihu );
561 return $U->DB_UPDATE_FAILED($ihu) unless $id;
572 sub create_in_house_use {
573 my( $self, $client, $auth, $params ) = @_;
576 my $org = $params->{location};
577 my $copyid = $params->{copyid};
578 my $count = $params->{count} || 1;
579 my $nc_type = $params->{non_cat_type};
580 my $use_time = $params->{use_time} || 'now';
582 my $e = new_editor(xact=>1,authtoken=>$auth);
583 return $e->event unless $e->checkauth;
584 return $e->event unless $e->allowed('CREATE_IN_HOUSE_USE');
586 my $non_cat = 1 if $self->api_name =~ /non_cat/;
590 $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
592 $copy = $e->search_asset_copy({barcode=>$params->{barcode}, deleted => 'f'})->[0]
598 if( $use_time ne 'now' ) {
599 $use_time = clense_ISO8601($use_time);
600 $logger->debug("in_house_use setting use time to $use_time");
611 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
612 $ihu->item_type($nc_type);
613 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
614 $cmeth = "create_action_non_cat_in_house_use";
617 $ihu = Fieldmapper::action::in_house_use->new;
619 $method = 'open-ils.storage.direct.action.in_house_use.create';
620 $cmeth = "create_action_in_house_use";
623 $ihu->staff($e->requestor->id);
624 $ihu->org_unit($org);
625 $ihu->use_time($use_time);
627 $ihu = $e->$cmeth($ihu) or return $e->event;
628 push( @ids, $ihu->id );
639 __PACKAGE__->register_method(
640 method => "view_circs",
641 api_name => "open-ils.circ.copy_checkout_history.retrieve",
643 Retrieves the last X circs for a given copy
644 @param authtoken The login session key
645 @param copyid The copy to check
646 @param count How far to go back in the item history
647 @return An array of circ ids
653 my( $self, $client, $authtoken, $copyid, $count ) = @_;
655 my( $requestor, $evt ) = $U->checksesperm(
656 $authtoken, 'VIEW_COPY_CHECKOUT_HISTORY' );
659 return [] unless $count;
661 my $circs = $U->cstorereq(
662 'open-ils.cstore.direct.action.circulation.search.atomic',
664 target_copy => $copyid,
668 order_by => { circ => "xact_start DESC" }
676 __PACKAGE__->register_method(
677 method => "circ_count",
678 api_name => "open-ils.circ.circulation.count",
680 Returns the number of times the item has circulated
681 @param copyid The copy to check
685 my( $self, $client, $copyid, $range ) = @_;
686 my $e = OpenILS::Utils::Editor->new;
687 return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
692 __PACKAGE__->register_method(
693 method => 'fetch_notes',
694 api_name => 'open-ils.circ.copy_note.retrieve.all',
696 Returns an array of copy note objects.
697 @param args A named hash of parameters including:
698 authtoken : Required if viewing non-public notes
699 itemid : The id of the item whose notes we want to retrieve
700 pub : True if all the caller wants are public notes
701 @return An array of note objects
704 __PACKAGE__->register_method(
705 method => 'fetch_notes',
706 api_name => 'open-ils.circ.call_number_note.retrieve.all',
707 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
709 __PACKAGE__->register_method(
710 method => 'fetch_notes',
711 api_name => 'open-ils.circ.title_note.retrieve.all',
712 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
715 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
717 my( $self, $connection, $args ) = @_;
719 my $id = $$args{itemid};
720 my $authtoken = $$args{authtoken};
723 if( $self->api_name =~ /copy/ ) {
725 return $U->cstorereq(
726 'open-ils.cstore.direct.asset.copy_note.search.atomic',
727 { owning_copy => $id, pub => 't' } );
729 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
731 return $U->cstorereq(
732 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
735 } elsif( $self->api_name =~ /call_number/ ) {
737 return $U->cstorereq(
738 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
739 { call_number => $id, pub => 't' } );
741 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
743 return $U->cstorereq(
744 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
747 } elsif( $self->api_name =~ /title/ ) {
749 return $U->cstorereq(
750 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
751 { record => $id, pub => 't' } );
753 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
755 return $U->cstorereq(
756 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
763 __PACKAGE__->register_method(
764 method => 'has_notes',
765 api_name => 'open-ils.circ.copy.has_notes');
766 __PACKAGE__->register_method(
767 method => 'has_notes',
768 api_name => 'open-ils.circ.call_number.has_notes');
769 __PACKAGE__->register_method(
770 method => 'has_notes',
771 api_name => 'open-ils.circ.title.has_notes');
775 my( $self, $conn, $authtoken, $id ) = @_;
776 my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
777 return $editor->event unless $editor->checkauth;
779 my $n = $editor->search_asset_copy_note(
780 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
782 $n = $editor->search_asset_call_number_note(
783 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
785 $n = $editor->search_biblio_record_note(
786 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
793 __PACKAGE__->register_method(
794 method => 'create_copy_note',
795 api_name => 'open-ils.circ.copy_note.create',
797 Creates a new copy note
798 @param authtoken The login session key
799 @param note The note object to create
800 @return The id of the new note object
803 sub create_copy_note {
804 my( $self, $connection, $authtoken, $note ) = @_;
806 my $e = new_editor(xact=>1, authtoken=>$authtoken);
807 return $e->event unless $e->checkauth;
808 my $copy = $e->retrieve_asset_copy(
812 flesh_fields => { 'acp' => ['call_number'] }
817 return $e->event unless
818 $e->allowed('CREATE_COPY_NOTE', $copy->call_number->owning_lib);
820 $note->create_date('now');
821 $note->creator($e->requestor->id);
822 $note->pub( ($U->is_true($note->pub)) ? 't' : 'f' );
825 $e->create_asset_copy_note($note) or return $e->event;
831 __PACKAGE__->register_method(
832 method => 'delete_copy_note',
833 api_name => 'open-ils.circ.copy_note.delete',
835 Deletes an existing copy note
836 @param authtoken The login session key
837 @param noteid The id of the note to delete
838 @return 1 on success - Event otherwise.
840 sub delete_copy_note {
841 my( $self, $conn, $authtoken, $noteid ) = @_;
843 my $e = new_editor(xact=>1, authtoken=>$authtoken);
844 return $e->die_event unless $e->checkauth;
846 my $note = $e->retrieve_asset_copy_note([
850 'acpn' => [ 'owning_copy' ],
851 'acp' => [ 'call_number' ],
854 ]) or return $e->die_event;
856 if( $note->creator ne $e->requestor->id ) {
857 return $e->die_event unless
858 $e->allowed('DELETE_COPY_NOTE', $note->owning_copy->call_number->owning_lib);
861 $e->delete_asset_copy_note($note) or return $e->die_event;
867 __PACKAGE__->register_method(
868 method => 'age_hold_rules',
869 api_name => 'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
873 my( $self, $conn ) = @_;
874 return new_editor()->retrieve_all_config_rules_age_hold_protect();
879 __PACKAGE__->register_method(
880 method => 'copy_details_barcode',
881 api_name => 'open-ils.circ.copy_details.retrieve.barcode');
882 sub copy_details_barcode {
883 my( $self, $conn, $auth, $barcode ) = @_;
884 my $e = new_editor();
885 my $cid = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'}, {idlist=>1})->[0];
886 return $e->event unless $cid;
887 return $self->copy_details( $conn, $auth, $cid );
891 __PACKAGE__->register_method(
892 method => 'copy_details',
893 api_name => 'open-ils.circ.copy_details.retrieve');
896 my( $self, $conn, $auth, $copy_id ) = @_;
897 my $e = new_editor(authtoken=>$auth);
898 return $e->event unless $e->checkauth;
900 my $flesh = { flesh => 1 };
902 my $copy = $e->retrieve_asset_copy(
908 acp => ['call_number'],
912 ]) or return $e->event;
915 # De-flesh the copy for backwards compatibility
917 my $vol = $copy->call_number;
919 $copy->call_number($vol->id);
920 my $record = $vol->record;
922 $vol->record($record->id);
923 $mvr = $U->record_to_mvr($record);
928 my $hold = $e->search_action_hold_request(
930 current_copy => $copy_id,
931 capture_time => { "!=" => undef },
932 fulfillment_time => undef,
933 cancel_time => undef,
937 OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
939 my $transit = $e->search_action_transit_copy(
940 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
942 # find the latest circ, open or closed
943 my $circ = $e->search_action_circulation(
945 { target_copy => $copy_id },
946 { order_by => { circ => 'xact_start desc' }, limit => 1 }
964 __PACKAGE__->register_method(
965 method => 'mark_item',
966 api_name => 'open-ils.circ.mark_item_damaged',
968 __PACKAGE__->register_method(
969 method => 'mark_item',
970 api_name => 'open-ils.circ.mark_item_missing',
974 my( $self, $conn, $auth, $copy_id ) = @_;
975 my $e = new_editor(authtoken=>$auth, xact =>1);
976 return $e->event unless $e->checkauth;
978 my $perm = 'MARK_ITEM_MISSING';
979 my $stat = OILS_COPY_STATUS_MISSING;
981 if( $self->api_name =~ /damaged/ ) {
982 $perm = 'MARK_ITEM_DAMAGED';
983 $stat = OILS_COPY_STATUS_DAMAGED;
986 my $copy = $e->retrieve_asset_copy($copy_id)
988 $copy->status($stat);
989 $copy->edit_date('now');
990 $copy->editor($e->requestor->id);
992 $e->update_asset_copy($copy) or return $e->event;
995 my $holds = $e->search_action_hold_request(
997 current_copy => $copy->id,
998 fulfillment_time => undef,
999 cancel_time => undef,
1005 $logger->debug("reseting holds that target the marked copy");
1006 OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds;
1016 # ----------------------------------------------------------------------
1017 __PACKAGE__->register_method(
1018 method => 'magic_fetch',
1019 api_name => 'open-ils.agent.fetch'
1022 my @FETCH_ALLOWED = qw/ aou aout acp acn bre /;
1025 my( $self, $conn, $auth, $args ) = @_;
1026 my $e = new_editor( authtoken => $auth );
1027 return $e->event unless $e->checkauth;
1029 my $hint = $$args{hint};
1030 my $id = $$args{id};
1032 # Is the call allowed to fetch this type of object?
1033 return undef unless grep { $_ eq $hint } @FETCH_ALLOWED;
1035 # Find the class the iplements the given hint
1036 my ($class) = grep {
1037 $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
1039 $class =~ s/Fieldmapper:://og;
1040 $class =~ s/::/_/og;
1041 my $method = "retrieve_$class";
1043 my $obj = $e->$method($id) or return $e->event;
1046 # ----------------------------------------------------------------------
1049 __PACKAGE__->register_method(
1050 method => "fleshed_circ_retrieve",
1051 api_name => "open-ils.circ.fleshed.retrieve",);
1053 sub fleshed_circ_retrieve {
1054 my( $self, $client, $id ) = @_;
1055 my $e = new_editor();
1056 my $circ = $e->retrieve_action_circulation(
1062 circ => [ qw/ target_copy / ],
1063 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect call_number / ],
1064 ascecm => [ qw/ stat_cat stat_cat_entry / ],
1065 acn => [ qw/ record / ],
1069 ) or return $e->event;
1071 my $copy = $circ->target_copy;
1072 my $vol = $copy->call_number;
1073 my $rec = $circ->target_copy->call_number->record;
1075 $vol->record($rec->id);
1076 $copy->call_number($vol->id);
1077 $circ->target_copy($copy->id);
1081 if( $rec->id == OILS_PRECAT_RECORD ) {
1085 $mvr = $U->record_to_mvr($rec);
1086 $rec->marc(''); # drop the bulky marc data