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 $conf = OpenSRF::Utils::SettingsClient->new;
71 return $conf->config_value(
72 'apps', 'open-ils.circ', 'app_settings', 'circ_modifiers', 'mod' );
75 __PACKAGE__->register_method(
76 method => 'fetch_bill_types',
77 api_name => 'open-ils.circ.billing_type.retrieve.all');
78 sub fetch_bill_types {
79 my $conf = OpenSRF::Utils::SettingsClient->new;
80 return $conf->config_value(
81 'apps', 'open-ils.circ', 'app_settings', 'billing_types', 'type' );
85 # ------------------------------------------------------------------------
86 # Returns an array of {circ, record} hashes checked out by the user.
87 # ------------------------------------------------------------------------
88 __PACKAGE__->register_method(
89 method => "checkouts_by_user",
90 api_name => "open-ils.circ.actor.user.checked_out",
92 Returns a list of open circulations as a pile of objects. each object
93 contains the relevant copy, circ, and record
96 sub checkouts_by_user {
97 my( $self, $client, $user_session, $user_id ) = @_;
99 my( $requestor, $target, $copy, $record, $evt );
101 ( $requestor, $target, $evt ) =
102 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
105 my $circs = $apputils->simplereq(
107 "open-ils.cstore.direct.action.open_circulation.search.atomic",
108 { usr => $target->id, checkin_time => undef } );
109 # { usr => $target->id } );
112 for my $circ (@$circs) {
114 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
117 $logger->debug("Retrieving record for copy " . $circ->target_copy);
119 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
122 my $mods = $apputils->record_to_mvr($record);
124 push( @results, { copy => $copy, circ => $circ, record => $mods } );
133 __PACKAGE__->register_method(
134 method => "checkouts_by_user_slim",
135 api_name => "open-ils.circ.actor.user.checked_out.slim",
136 NOTES => <<" NOTES");
137 Returns a list of open circulation objects
141 sub checkouts_by_user_slim {
142 my( $self, $client, $user_session, $user_id ) = @_;
144 my( $requestor, $target, $copy, $record, $evt );
146 ( $requestor, $target, $evt ) =
147 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
150 $logger->debug( 'User ' . $requestor->id .
151 " retrieving checked out items for user " . $target->id );
153 # XXX Make the call correct..
154 return $apputils->simplereq(
156 "open-ils.cstore.direct.action.open_circulation.search.atomic",
157 { usr => $target->id, checkin_time => undef } );
158 # { usr => $target->id } );
162 __PACKAGE__->register_method(
163 method => "checkouts_by_user_opac",
164 api_name => "open-ils.circ.actor.user.checked_out.opac",);
167 sub checkouts_by_user_opac {
168 my( $self, $client, $auth, $user_id ) = @_;
170 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
171 return $e->event unless $e->checkauth;
172 $user_id ||= $e->requestor->id;
173 return $e->event unless
174 my $patron = $e->retrieve_actor_user($user_id);
177 my $search = {usr => $user_id, stop_fines => undef};
179 if( $user_id ne $e->requestor->id ) {
180 $data = $e->search_action_circulation(
181 $search, {checkperm=>1, permorg=>$patron->home_ou})
185 $data = $e->search_action_circulation($search);
192 __PACKAGE__->register_method(
193 method => "title_from_transaction",
194 api_name => "open-ils.circ.circ_transaction.find_title",
195 NOTES => <<" NOTES");
196 Returns a mods object for the title that is linked to from the
197 copy from the hold that created the given transaction
200 sub title_from_transaction {
201 my( $self, $client, $login_session, $transactionid ) = @_;
203 my( $user, $circ, $title, $evt );
205 ( $user, $evt ) = $apputils->checkses( $login_session );
208 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
211 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
214 return $apputils->record_to_mvr($title);
219 __PACKAGE__->register_method(
220 method => "new_set_circ_lost",
221 api_name => "open-ils.circ.circulation.set_lost",
223 Sets the copy and related open circulation to lost
225 @param args : barcode
230 # ---------------------------------------------------------------------
231 # Sets a circulation to lost. updates copy status to lost
232 # applies copy and/or prcoessing fees depending on org settings
233 # ---------------------------------------------------------------------
234 sub new_set_circ_lost {
235 my( $self, $conn, $auth, $args ) = @_;
237 my $e = new_editor(authtoken=>$auth, xact=>1);
238 return $e->die_event unless $e->checkauth;
240 my $barcode = $$args{barcode};
241 $logger->info("marking item lost $barcode");
243 # ---------------------------------------------------------------------
245 my $copy = $e->search_asset_copy([
246 {barcode=>$barcode, deleted=>'f'},
247 {flesh => 1, flesh_fields => {'acp' => ['call_number']}}])->[0]
248 or return $e->die_event;
251 ($copy->call_number == OILS_PRECAT_CALL_NUMBER) ?
252 $copy->circ_lib : $copy->call_number->owning_lib;
254 my $circ = $e->search_action_circulation(
255 {checkin_time => undef, target_copy => $copy->id} )->[0]
256 or return $e->die_event;
258 $e->allowed('SET_CIRC_LOST', $circ->circ_lib) or return $e->die_event;
260 return OpenILS::Event->new('COPY_MARKED_LOST')
261 if $copy->status == OILS_COPY_STATUS_LOST;
263 # ---------------------------------------------------------------------
264 # fetch the related org settings
265 my $default_price = $U->ou_ancestor_setting_value(
266 $owning_lib, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
267 my $proc_fee = $U->ou_ancestor_setting_value(
268 $owning_lib, OILS_SETTING_LOST_PROCESSING_FEE, $e) || 0;
269 my $charge_on_0 = $U->ou_ancestor_setting_value(
270 $owning_lib, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0;
271 my $void_overdue = $U->ou_ancestor_setting_value(
272 $owning_lib, OILS_SETTING_VOID_OVERDUE_ON_LOST, $e) || 0;
274 $logger->info("org settings: default price = $default_price, ".
275 "processing fee = $proc_fee, charge on 0 = $charge_on_0, void overdues = $void_overdue");
277 # ---------------------------------------------------------------------
278 # move the copy into LOST status
279 $copy->status(OILS_COPY_STATUS_LOST);
280 $copy->editor($e->requestor->id);
281 $copy->edit_date('now');
282 $e->update_asset_copy($copy) or return $e->die_event;
284 # ---------------------------------------------------------------------
285 # determine the appropriate item price to charge and create the billing
286 my $price = $copy->price;
287 $price = $default_price unless defined $price;
288 $price = 0 if $price < 0;
289 $price = $default_price if $price == 0 and $charge_on_0;
292 my $evt = create_bill($e, $price, 'Lost Materials', $circ->id);
296 # ---------------------------------------------------------------------
297 # if there is a processing fee, charge that too
298 if( $proc_fee > 0 ) {
299 my $evt = create_bill($e, $proc_fee, 'Lost Materials Processing Fee', $circ->id);
303 # ---------------------------------------------------------------------
304 # mark the circ as lost and stop the fines
305 $circ->stop_fines(OILS_STOP_FINES_LOST);
306 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
307 $e->update_action_circulation($circ) or return $e->die_event;
309 # ---------------------------------------------------------------------
310 # void all overdue fines on this circ if configured
311 if( $void_overdue ) {
312 my $evt = void_overdues($e, $circ);
316 my $evt = reopen_xact($e, $circ->id);
324 my($e, $xactid) = @_;
326 # -----------------------------------------------------------------
327 # make sure the transaction is not closed
328 my $xact = $e->retrieve_money_billable_transaction($xactid)
329 or return $e->die_event;
331 if( $xact->xact_finish ) {
332 my ($mbts) = $U->fetch_mbts($xactid, $e);
333 if( $mbts->balance_owed != 0 ) {
334 $logger->info("* re-opening xact $xactid, orig xact_finish is ".$xact->xact_finish);
335 $xact->clear_xact_finish;
336 $e->update_money_billable_transaction($xact)
337 or return $e->die_event;
346 my( $e, $amount, $type, $xactid ) = @_;
348 $logger->info("The system is charging $amount [$type] on xact $xactid");
350 # -----------------------------------------------------------------
351 # now create the billing
352 my $bill = Fieldmapper::money::billing->new;
353 $bill->xact($xactid);
354 $bill->amount($amount);
355 $bill->billing_type($type);
356 $bill->note('SYSTEM GENERATED');
357 $e->create_money_billing($bill) or return $e->die_event;
364 # -----------------------------------------------------------------
365 # Voids overdue fines on the given circ. if a backdate is
366 # provided, then we only void back to the backdate
367 # -----------------------------------------------------------------
369 my( $e, $circ, $backdate ) = @_;
373 billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
377 # ------------------------------------------------------------------
378 # Fines for overdue materials are assessed up to, but not including,
379 # one fine interval after the fines are applicable. Here, we add
380 # one fine interval to the backdate to ensure that we are not
381 # voiding fines that were applicable before the backdate.
382 # ------------------------------------------------------------------
383 my $interval = OpenSRF::Utils->interval_to_seconds($circ->fine_interval);
384 my $date = DateTime::Format::ISO8601->parse_datetime($backdate);
385 $backdate = $U->epoch2ISO8601($date->epoch + $interval);
386 $logger->info("applying backdate $backdate in overdue voiding");
387 $$bill_search{billing_ts} = {'>=' => $backdate};
390 my $bills = $e->search_money_billing($bill_search);
392 for my $bill (@$bills) {
393 next if $U->is_true($bill->voided);
394 $logger->info("voiding overdue bill ".$bill->id);
396 $bill->void_time('now');
397 $bill->voider($e->requestor->id);
398 my $n = $bill->note || "";
399 $bill->note("$n\nSystem: VOIDED FOR BACKDATE");
400 $e->update_money_billing($bill) or return $e->die_event;
409 __PACKAGE__->register_method(
410 method => "set_circ_claims_returned",
411 api_name => "open-ils.circ.circulation.set_claims_returned",
413 Sets the circ for the given item as claims returned
414 If a backdate is provided, overdue fines will be voided
417 @param args : barcode, backdate
421 sub set_circ_claims_returned {
422 my( $self, $conn, $auth, $args ) = @_;
424 my $e = new_editor(authtoken=>$auth, xact=>1);
425 return $e->die_event unless $e->checkauth;
427 my $barcode = $$args{barcode};
428 my $backdate = $$args{backdate};
430 $logger->info("marking circ for item $barcode as claims returned".
431 (($backdate) ? " with backdate $backdate" : ''));
433 my $copy = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'})->[0]
434 or return $e->die_event;
436 my $circ = $e->search_action_circulation(
437 {checkin_time => undef, target_copy => $copy->id})->[0]
438 or return $e->die_event;
440 $e->allowed('SET_CIRC_CLAIMS_RETURNED', $circ->circ_lib)
441 or return $e->die_event;
443 $circ->stop_fines(OILS_STOP_FINES_CLAIMSRETURNED);
444 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
447 # make it look like the circ stopped at the cliams returned time
448 $circ->stop_fines_time(clense_ISO8601($backdate));
449 my $evt = void_overdues($e, $circ, $backdate);
453 $e->update_action_circulation($circ) or return $e->die_event;
462 __PACKAGE__->register_method (
463 method => 'set_circ_due_date',
464 api_name => 'open-ils.circ.circulation.due_date.update',
466 Updates the due_date on the given circ
468 @param circid The id of the circ to update
469 @param date The timestamp of the new due date
473 sub set_circ_due_date {
474 my( $self, $conn, $auth, $circ_id, $date ) = @_;
476 my $e = new_editor(xact=>1, authtoken=>$auth);
477 return $e->die_event unless $e->checkauth;
478 my $circ = $e->retrieve_action_circulation($circ_id)
479 or return $e->die_event;
481 return $e->die_event unless $e->allowed('CIRC_OVERRIDE_DUE_DATE', $circ->circ_lib);
482 $date = clense_ISO8601($date);
483 $circ->due_date($date);
484 $e->update_action_circulation($circ) or return $e->die_event;
491 __PACKAGE__->register_method(
492 method => "create_in_house_use",
493 api_name => 'open-ils.circ.in_house_use.create',
495 Creates an in-house use action.
496 @param $authtoken The login session key
497 @param params A hash of params including
498 'location' The org unit id where the in-house use occurs
499 'copyid' The copy in question
500 'count' The number of in-house uses to apply to this copy
501 @return An array of id's representing the id's of the newly created
502 in-house use objects or an event on an error
505 __PACKAGE__->register_method(
506 method => "create_in_house_use",
507 api_name => 'open-ils.circ.non_cat_in_house_use.create',
511 sub ___create_in_house_use {
512 my( $self, $client, $authtoken, $params ) = @_;
514 my( $staff, $evt, $copy );
515 my $org = $params->{location};
516 my $copyid = $params->{copyid};
517 my $count = $params->{count} || 1;
518 my $nc_type = $params->{non_cat_type};
519 my $use_time = $params->{use_time} || 'now';
521 my $non_cat = 1 if $self->api_name =~ /non_cat/;
525 my $barcode = $params->{barcode};
526 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
530 ($copy, $evt) = $U->fetch_copy($copyid) unless $copy;
534 ($staff, $evt) = $U->checkses($authtoken);
537 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
540 if( $use_time ne 'now' ) {
541 $use_time = clense_ISO8601($use_time);
542 $logger->debug("in_house_use setting use time to $use_time");
552 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
553 $ihu->noncat_type($nc_type);
554 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
556 $ihu = Fieldmapper::action::in_house_use->new;
558 $method = 'open-ils.storage.direct.action.in_house_use.create';
561 $ihu->staff($staff->id);
562 $ihu->org_unit($org);
563 $ihu->use_time($use_time);
565 my $id = $U->simplereq('open-ils.storage', $method, $ihu );
567 return $U->DB_UPDATE_FAILED($ihu) unless $id;
578 sub create_in_house_use {
579 my( $self, $client, $auth, $params ) = @_;
582 my $org = $params->{location};
583 my $copyid = $params->{copyid};
584 my $count = $params->{count} || 1;
585 my $nc_type = $params->{non_cat_type};
586 my $use_time = $params->{use_time} || 'now';
588 my $e = new_editor(xact=>1,authtoken=>$auth);
589 return $e->event unless $e->checkauth;
590 return $e->event unless $e->allowed('CREATE_IN_HOUSE_USE');
592 my $non_cat = 1 if $self->api_name =~ /non_cat/;
596 $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
598 $copy = $e->search_asset_copy({barcode=>$params->{barcode}, deleted => 'f'})->[0]
604 if( $use_time ne 'now' ) {
605 $use_time = clense_ISO8601($use_time);
606 $logger->debug("in_house_use setting use time to $use_time");
617 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
618 $ihu->item_type($nc_type);
619 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
620 $cmeth = "create_action_non_cat_in_house_use";
623 $ihu = Fieldmapper::action::in_house_use->new;
625 $method = 'open-ils.storage.direct.action.in_house_use.create';
626 $cmeth = "create_action_in_house_use";
629 $ihu->staff($e->requestor->id);
630 $ihu->org_unit($org);
631 $ihu->use_time($use_time);
633 $ihu = $e->$cmeth($ihu) or return $e->event;
634 push( @ids, $ihu->id );
645 __PACKAGE__->register_method(
646 method => "view_circs",
647 api_name => "open-ils.circ.copy_checkout_history.retrieve",
649 Retrieves the last X circs for a given copy
650 @param authtoken The login session key
651 @param copyid The copy to check
652 @param count How far to go back in the item history
653 @return An array of circ ids
659 my( $self, $client, $authtoken, $copyid, $count ) = @_;
661 my( $requestor, $evt ) = $U->checksesperm(
662 $authtoken, 'VIEW_COPY_CHECKOUT_HISTORY' );
665 return [] unless $count;
667 my $circs = $U->cstorereq(
668 'open-ils.cstore.direct.action.circulation.search.atomic',
670 target_copy => $copyid,
674 order_by => { circ => "xact_start DESC" }
682 __PACKAGE__->register_method(
683 method => "circ_count",
684 api_name => "open-ils.circ.circulation.count",
686 Returns the number of times the item has circulated
687 @param copyid The copy to check
691 my( $self, $client, $copyid, $range ) = @_;
692 my $e = OpenILS::Utils::Editor->new;
693 return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
698 __PACKAGE__->register_method(
699 method => 'fetch_notes',
700 api_name => 'open-ils.circ.copy_note.retrieve.all',
702 Returns an array of copy note objects.
703 @param args A named hash of parameters including:
704 authtoken : Required if viewing non-public notes
705 itemid : The id of the item whose notes we want to retrieve
706 pub : True if all the caller wants are public notes
707 @return An array of note objects
710 __PACKAGE__->register_method(
711 method => 'fetch_notes',
712 api_name => 'open-ils.circ.call_number_note.retrieve.all',
713 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
715 __PACKAGE__->register_method(
716 method => 'fetch_notes',
717 api_name => 'open-ils.circ.title_note.retrieve.all',
718 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
721 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
723 my( $self, $connection, $args ) = @_;
725 my $id = $$args{itemid};
726 my $authtoken = $$args{authtoken};
729 if( $self->api_name =~ /copy/ ) {
731 return $U->cstorereq(
732 'open-ils.cstore.direct.asset.copy_note.search.atomic',
733 { owning_copy => $id, pub => 't' } );
735 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
737 return $U->cstorereq(
738 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
741 } elsif( $self->api_name =~ /call_number/ ) {
743 return $U->cstorereq(
744 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
745 { call_number => $id, pub => 't' } );
747 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
749 return $U->cstorereq(
750 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
753 } elsif( $self->api_name =~ /title/ ) {
755 return $U->cstorereq(
756 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
757 { record => $id, pub => 't' } );
759 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
761 return $U->cstorereq(
762 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
769 __PACKAGE__->register_method(
770 method => 'has_notes',
771 api_name => 'open-ils.circ.copy.has_notes');
772 __PACKAGE__->register_method(
773 method => 'has_notes',
774 api_name => 'open-ils.circ.call_number.has_notes');
775 __PACKAGE__->register_method(
776 method => 'has_notes',
777 api_name => 'open-ils.circ.title.has_notes');
781 my( $self, $conn, $authtoken, $id ) = @_;
782 my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
783 return $editor->event unless $editor->checkauth;
785 my $n = $editor->search_asset_copy_note(
786 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
788 $n = $editor->search_asset_call_number_note(
789 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
791 $n = $editor->search_biblio_record_note(
792 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
799 __PACKAGE__->register_method(
800 method => 'create_copy_note',
801 api_name => 'open-ils.circ.copy_note.create',
803 Creates a new copy note
804 @param authtoken The login session key
805 @param note The note object to create
806 @return The id of the new note object
809 sub create_copy_note {
810 my( $self, $connection, $authtoken, $note ) = @_;
812 my $e = new_editor(xact=>1, authtoken=>$authtoken);
813 return $e->event unless $e->checkauth;
814 my $copy = $e->retrieve_asset_copy(
818 flesh_fields => { 'acp' => ['call_number'] }
823 return $e->event unless
824 $e->allowed('CREATE_COPY_NOTE', $copy->call_number->owning_lib);
826 $note->create_date('now');
827 $note->creator($e->requestor->id);
828 $note->pub( ($U->is_true($note->pub)) ? 't' : 'f' );
831 $e->create_asset_copy_note($note) or return $e->event;
837 __PACKAGE__->register_method(
838 method => 'delete_copy_note',
839 api_name => 'open-ils.circ.copy_note.delete',
841 Deletes an existing copy note
842 @param authtoken The login session key
843 @param noteid The id of the note to delete
844 @return 1 on success - Event otherwise.
846 sub delete_copy_note {
847 my( $self, $conn, $authtoken, $noteid ) = @_;
849 my $e = new_editor(xact=>1, authtoken=>$authtoken);
850 return $e->die_event unless $e->checkauth;
852 my $note = $e->retrieve_asset_copy_note([
856 'acpn' => [ 'owning_copy' ],
857 'acp' => [ 'call_number' ],
860 ]) or return $e->die_event;
862 if( $note->creator ne $e->requestor->id ) {
863 return $e->die_event unless
864 $e->allowed('DELETE_COPY_NOTE', $note->owning_copy->call_number->owning_lib);
867 $e->delete_asset_copy_note($note) or return $e->die_event;
873 __PACKAGE__->register_method(
874 method => 'age_hold_rules',
875 api_name => 'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
879 my( $self, $conn ) = @_;
880 return new_editor()->retrieve_all_config_rules_age_hold_protect();
885 __PACKAGE__->register_method(
886 method => 'copy_details_barcode',
888 api_name => 'open-ils.circ.copy_details.retrieve.barcode');
889 sub copy_details_barcode {
890 my( $self, $conn, $auth, $barcode ) = @_;
891 my $e = new_editor();
892 my $cid = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'}, {idlist=>1})->[0];
893 return $e->event unless $cid;
894 return copy_details( $self, $conn, $auth, $cid );
898 __PACKAGE__->register_method(
899 method => 'copy_details',
900 api_name => 'open-ils.circ.copy_details.retrieve');
903 my( $self, $conn, $auth, $copy_id ) = @_;
904 my $e = new_editor(authtoken=>$auth);
905 return $e->event unless $e->checkauth;
907 my $flesh = { flesh => 1 };
909 my $copy = $e->retrieve_asset_copy(
915 acp => ['call_number'],
919 ]) or return $e->event;
922 # De-flesh the copy for backwards compatibility
924 my $vol = $copy->call_number;
926 $copy->call_number($vol->id);
927 my $record = $vol->record;
929 $vol->record($record->id);
930 $mvr = $U->record_to_mvr($record);
935 my $hold = $e->search_action_hold_request(
937 current_copy => $copy_id,
938 capture_time => { "!=" => undef },
939 fulfillment_time => undef,
940 cancel_time => undef,
944 OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
946 my $transit = $e->search_action_transit_copy(
947 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
949 # find the latest circ, open or closed
950 my $circ = $e->search_action_circulation(
952 { target_copy => $copy_id },
953 { order_by => { circ => 'xact_start desc' }, limit => 1 }
971 __PACKAGE__->register_method(
972 method => 'mark_item',
973 api_name => 'open-ils.circ.mark_item_damaged',
975 __PACKAGE__->register_method(
976 method => 'mark_item',
977 api_name => 'open-ils.circ.mark_item_missing',
981 my( $self, $conn, $auth, $copy_id ) = @_;
982 my $e = new_editor(authtoken=>$auth, xact =>1);
983 return $e->event unless $e->checkauth;
985 my $perm = 'MARK_ITEM_MISSING';
986 my $stat = OILS_COPY_STATUS_MISSING;
988 if( $self->api_name =~ /damaged/ ) {
989 $perm = 'MARK_ITEM_DAMAGED';
990 $stat = OILS_COPY_STATUS_DAMAGED;
993 my $copy = $e->retrieve_asset_copy($copy_id)
995 $copy->status($stat);
996 $copy->edit_date('now');
997 $copy->editor($e->requestor->id);
999 $e->update_asset_copy($copy) or return $e->event;
1002 my $holds = $e->search_action_hold_request(
1004 current_copy => $copy->id,
1005 fulfillment_time => undef,
1006 cancel_time => undef,
1012 $logger->debug("reseting holds that target the marked copy");
1013 OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds;
1023 # ----------------------------------------------------------------------
1024 __PACKAGE__->register_method(
1025 method => 'magic_fetch',
1026 api_name => 'open-ils.agent.fetch'
1029 my @FETCH_ALLOWED = qw/ aou aout acp acn bre /;
1032 my( $self, $conn, $auth, $args ) = @_;
1033 my $e = new_editor( authtoken => $auth );
1034 return $e->event unless $e->checkauth;
1036 my $hint = $$args{hint};
1037 my $id = $$args{id};
1039 # Is the call allowed to fetch this type of object?
1040 return undef unless grep { $_ eq $hint } @FETCH_ALLOWED;
1042 # Find the class the iplements the given hint
1043 my ($class) = grep {
1044 $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
1046 $class =~ s/Fieldmapper:://og;
1047 $class =~ s/::/_/og;
1048 my $method = "retrieve_$class";
1050 my $obj = $e->$method($id) or return $e->event;
1053 # ----------------------------------------------------------------------
1056 __PACKAGE__->register_method(
1057 method => "fleshed_circ_retrieve",
1059 api_name => "open-ils.circ.fleshed.retrieve",);
1061 sub fleshed_circ_retrieve {
1062 my( $self, $client, $id ) = @_;
1063 my $e = new_editor();
1064 my $circ = $e->retrieve_action_circulation(
1070 circ => [ qw/ target_copy / ],
1071 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect call_number / ],
1072 ascecm => [ qw/ stat_cat stat_cat_entry / ],
1073 acn => [ qw/ record / ],
1077 ) or return $e->event;
1079 my $copy = $circ->target_copy;
1080 my $vol = $copy->call_number;
1081 my $rec = $circ->target_copy->call_number->record;
1083 $vol->record($rec->id);
1084 $copy->call_number($vol->id);
1085 $circ->target_copy($copy->id);
1089 if( $rec->id == OILS_PRECAT_RECORD ) {
1093 $mvr = $U->record_to_mvr($rec);
1094 $rec->marc(''); # drop the bulky marc data