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 # ------------------------------------------------------------------------
87 # Returns an array of {circ, record} hashes checked out by the user.
88 # ------------------------------------------------------------------------
89 __PACKAGE__->register_method(
90 method => "checkouts_by_user",
91 api_name => "open-ils.circ.actor.user.checked_out",
93 Returns a list of open circulations as a pile of objects. each object
94 contains the relevant copy, circ, and record
97 sub checkouts_by_user {
98 my( $self, $client, $user_session, $user_id ) = @_;
100 my( $requestor, $target, $copy, $record, $evt );
102 ( $requestor, $target, $evt ) =
103 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
106 my $circs = $apputils->simplereq(
108 "open-ils.cstore.direct.action.open_circulation.search.atomic",
109 { usr => $target->id, checkin_time => undef } );
110 # { usr => $target->id } );
113 for my $circ (@$circs) {
115 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
118 $logger->debug("Retrieving record for copy " . $circ->target_copy);
120 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
123 my $mods = $apputils->record_to_mvr($record);
125 push( @results, { copy => $copy, circ => $circ, record => $mods } );
134 __PACKAGE__->register_method(
135 method => "checkouts_by_user_slim",
136 api_name => "open-ils.circ.actor.user.checked_out.slim",
137 NOTES => <<" NOTES");
138 Returns a list of open circulation objects
142 sub checkouts_by_user_slim {
143 my( $self, $client, $user_session, $user_id ) = @_;
145 my( $requestor, $target, $copy, $record, $evt );
147 ( $requestor, $target, $evt ) =
148 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
151 $logger->debug( 'User ' . $requestor->id .
152 " retrieving checked out items for user " . $target->id );
154 # XXX Make the call correct..
155 return $apputils->simplereq(
157 "open-ils.cstore.direct.action.open_circulation.search.atomic",
158 { usr => $target->id, checkin_time => undef } );
159 # { usr => $target->id } );
163 __PACKAGE__->register_method(
164 method => "checkouts_by_user_opac",
165 api_name => "open-ils.circ.actor.user.checked_out.opac",);
168 sub checkouts_by_user_opac {
169 my( $self, $client, $auth, $user_id ) = @_;
171 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
172 return $e->event unless $e->checkauth;
173 $user_id ||= $e->requestor->id;
174 return $e->event unless
175 my $patron = $e->retrieve_actor_user($user_id);
178 my $search = {usr => $user_id, stop_fines => undef};
180 if( $user_id ne $e->requestor->id ) {
181 $data = $e->search_action_circulation(
182 $search, {checkperm=>1, permorg=>$patron->home_ou})
186 $data = $e->search_action_circulation($search);
193 __PACKAGE__->register_method(
194 method => "title_from_transaction",
195 api_name => "open-ils.circ.circ_transaction.find_title",
196 NOTES => <<" NOTES");
197 Returns a mods object for the title that is linked to from the
198 copy from the hold that created the given transaction
201 sub title_from_transaction {
202 my( $self, $client, $login_session, $transactionid ) = @_;
204 my( $user, $circ, $title, $evt );
206 ( $user, $evt ) = $apputils->checkses( $login_session );
209 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
212 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
215 return $apputils->record_to_mvr($title);
220 __PACKAGE__->register_method(
221 method => "new_set_circ_lost",
222 api_name => "open-ils.circ.circulation.set_lost",
224 Sets the copy and related open circulation to lost
226 @param args : barcode
231 # ---------------------------------------------------------------------
232 # Sets a circulation to lost. updates copy status to lost
233 # applies copy and/or prcoessing fees depending on org settings
234 # ---------------------------------------------------------------------
235 sub new_set_circ_lost {
236 my( $self, $conn, $auth, $args ) = @_;
238 my $e = new_editor(authtoken=>$auth, xact=>1);
239 return $e->die_event unless $e->checkauth;
241 my $barcode = $$args{barcode};
242 $logger->info("marking item lost $barcode");
244 # ---------------------------------------------------------------------
246 my $copy = $e->search_asset_copy([
247 {barcode=>$barcode, deleted=>'f'},
248 {flesh => 1, flesh_fields => {'acp' => ['call_number']}}])->[0]
249 or return $e->die_event;
252 ($copy->call_number == OILS_PRECAT_CALL_NUMBER) ?
253 $copy->circ_lib : $copy->call_number->owning_lib;
255 my $circ = $e->search_action_circulation(
256 {checkin_time => undef, target_copy => $copy->id} )->[0]
257 or return $e->die_event;
259 $e->allowed('SET_CIRC_LOST', $circ->circ_lib) or return $e->die_event;
261 return OpenILS::Event->new('COPY_MARKED_LOST')
262 if $copy->status == OILS_COPY_STATUS_LOST;
264 # ---------------------------------------------------------------------
265 # fetch the related org settings
266 my $default_price = $U->ou_ancestor_setting_value(
267 $owning_lib, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
268 my $proc_fee = $U->ou_ancestor_setting_value(
269 $owning_lib, OILS_SETTING_LOST_PROCESSING_FEE, $e) || 0;
270 my $charge_on_0 = $U->ou_ancestor_setting_value(
271 $owning_lib, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0;
272 my $void_overdue = $U->ou_ancestor_setting_value(
273 $owning_lib, OILS_SETTING_VOID_OVERDUE_ON_LOST, $e) || 0;
275 $logger->info("org settings: default price = $default_price, ".
276 "processing fee = $proc_fee, charge on 0 = $charge_on_0, void overdues = $void_overdue");
278 # ---------------------------------------------------------------------
279 # move the copy into LOST status
280 $copy->status(OILS_COPY_STATUS_LOST);
281 $copy->editor($e->requestor->id);
282 $copy->edit_date('now');
283 $e->update_asset_copy($copy) or return $e->die_event;
285 # ---------------------------------------------------------------------
286 # determine the appropriate item price to charge and create the billing
287 my $price = $copy->price;
288 $price = $default_price unless defined $price;
289 $price = 0 if $price < 0;
290 $price = $default_price if $price == 0 and $charge_on_0;
293 my $evt = create_bill($e, $price, 'Lost Materials', $circ->id);
297 # ---------------------------------------------------------------------
298 # if there is a processing fee, charge that too
299 if( $proc_fee > 0 ) {
300 my $evt = create_bill($e, $proc_fee, 'Lost Materials Processing Fee', $circ->id);
304 # ---------------------------------------------------------------------
305 # mark the circ as lost and stop the fines
306 $circ->stop_fines(OILS_STOP_FINES_LOST);
307 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
308 $e->update_action_circulation($circ) or return $e->die_event;
310 # ---------------------------------------------------------------------
311 # void all overdue fines on this circ if configured
312 if( $void_overdue ) {
313 my $evt = void_overdues($e, $circ);
317 my $evt = reopen_xact($e, $circ->id);
325 my($e, $xactid) = @_;
327 # -----------------------------------------------------------------
328 # make sure the transaction is not closed
329 my $xact = $e->retrieve_money_billable_transaction($xactid)
330 or return $e->die_event;
332 if( $xact->xact_finish ) {
333 my ($mbts) = $U->fetch_mbts($xactid, $e);
334 if( $mbts->balance_owed != 0 ) {
335 $logger->info("* re-opening xact $xactid, orig xact_finish is ".$xact->xact_finish);
336 $xact->clear_xact_finish;
337 $e->update_money_billable_transaction($xact)
338 or return $e->die_event;
347 my( $e, $amount, $type, $xactid ) = @_;
349 $logger->info("The system is charging $amount [$type] on xact $xactid");
351 # -----------------------------------------------------------------
352 # now create the billing
353 my $bill = Fieldmapper::money::billing->new;
354 $bill->xact($xactid);
355 $bill->amount($amount);
356 $bill->billing_type($type);
357 $bill->note('SYSTEM GENERATED');
358 $e->create_money_billing($bill) or return $e->die_event;
365 # -----------------------------------------------------------------
366 # Voids overdue fines on the given circ. if a backdate is
367 # provided, then we only void back to the backdate
368 # -----------------------------------------------------------------
370 my( $e, $circ, $backdate ) = @_;
374 billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
378 # ------------------------------------------------------------------
379 # Fines for overdue materials are assessed up to, but not including,
380 # one fine interval after the fines are applicable. Here, we add
381 # one fine interval to the backdate to ensure that we are not
382 # voiding fines that were applicable before the backdate.
383 # ------------------------------------------------------------------
385 # if there is a raw time component (e.g. from postgres),
386 # turn it into an interval that interval_to_seconds can parse
387 my $duration = $circ->fine_interval;
388 $duration =~ s/(\d{2}):(\d{2}):(\d{2})/$1 h $2 m $3 s/o;
389 my $interval = OpenSRF::Utils->interval_to_seconds($duration);
391 my $date = DateTime::Format::ISO8601->parse_datetime($backdate);
392 $backdate = $U->epoch2ISO8601($date->epoch + $interval);
393 $logger->info("applying backdate $backdate in overdue voiding");
394 $$bill_search{billing_ts} = {'>=' => $backdate};
397 my $bills = $e->search_money_billing($bill_search);
399 for my $bill (@$bills) {
400 next if $U->is_true($bill->voided);
401 $logger->info("voiding overdue bill ".$bill->id);
403 $bill->void_time('now');
404 $bill->voider($e->requestor->id);
405 my $n = $bill->note || "";
406 $bill->note("$n\nSystem: VOIDED FOR BACKDATE");
407 $e->update_money_billing($bill) or return $e->die_event;
416 __PACKAGE__->register_method(
417 method => "set_circ_claims_returned",
418 api_name => "open-ils.circ.circulation.set_claims_returned",
420 Sets the circ for the given item as claims returned
421 If a backdate is provided, overdue fines will be voided
424 @param args : barcode, backdate
428 sub set_circ_claims_returned {
429 my( $self, $conn, $auth, $args ) = @_;
431 my $e = new_editor(authtoken=>$auth, xact=>1);
432 return $e->die_event unless $e->checkauth;
434 my $barcode = $$args{barcode};
435 my $backdate = $$args{backdate};
437 $logger->info("marking circ for item $barcode as claims returned".
438 (($backdate) ? " with backdate $backdate" : ''));
440 my $copy = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'})->[0]
441 or return $e->die_event;
443 my $circ = $e->search_action_circulation(
444 {checkin_time => undef, target_copy => $copy->id})->[0]
445 or return $e->die_event;
447 $e->allowed('SET_CIRC_CLAIMS_RETURNED', $circ->circ_lib)
448 or return $e->die_event;
450 $circ->stop_fines(OILS_STOP_FINES_CLAIMSRETURNED);
451 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
454 # make it look like the circ stopped at the cliams returned time
455 $circ->stop_fines_time(clense_ISO8601($backdate));
456 my $evt = void_overdues($e, $circ, $backdate);
460 $e->update_action_circulation($circ) or return $e->die_event;
469 __PACKAGE__->register_method (
470 method => 'set_circ_due_date',
471 api_name => 'open-ils.circ.circulation.due_date.update',
473 Updates the due_date on the given circ
475 @param circid The id of the circ to update
476 @param date The timestamp of the new due date
480 sub set_circ_due_date {
481 my( $self, $conn, $auth, $circ_id, $date ) = @_;
483 my $e = new_editor(xact=>1, authtoken=>$auth);
484 return $e->die_event unless $e->checkauth;
485 my $circ = $e->retrieve_action_circulation($circ_id)
486 or return $e->die_event;
488 return $e->die_event unless $e->allowed('CIRC_OVERRIDE_DUE_DATE', $circ->circ_lib);
489 $date = clense_ISO8601($date);
490 $circ->due_date($date);
491 $e->update_action_circulation($circ) or return $e->die_event;
498 __PACKAGE__->register_method(
499 method => "create_in_house_use",
500 api_name => 'open-ils.circ.in_house_use.create',
502 Creates an in-house use action.
503 @param $authtoken The login session key
504 @param params A hash of params including
505 'location' The org unit id where the in-house use occurs
506 'copyid' The copy in question
507 'count' The number of in-house uses to apply to this copy
508 @return An array of id's representing the id's of the newly created
509 in-house use objects or an event on an error
512 __PACKAGE__->register_method(
513 method => "create_in_house_use",
514 api_name => 'open-ils.circ.non_cat_in_house_use.create',
518 sub ___create_in_house_use {
519 my( $self, $client, $authtoken, $params ) = @_;
521 my( $staff, $evt, $copy );
522 my $org = $params->{location};
523 my $copyid = $params->{copyid};
524 my $count = $params->{count} || 1;
525 my $nc_type = $params->{non_cat_type};
526 my $use_time = $params->{use_time} || 'now';
528 my $non_cat = 1 if $self->api_name =~ /non_cat/;
532 my $barcode = $params->{barcode};
533 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
537 ($copy, $evt) = $U->fetch_copy($copyid) unless $copy;
541 ($staff, $evt) = $U->checkses($authtoken);
544 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
547 if( $use_time ne 'now' ) {
548 $use_time = clense_ISO8601($use_time);
549 $logger->debug("in_house_use setting use time to $use_time");
559 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
560 $ihu->noncat_type($nc_type);
561 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
563 $ihu = Fieldmapper::action::in_house_use->new;
565 $method = 'open-ils.storage.direct.action.in_house_use.create';
568 $ihu->staff($staff->id);
569 $ihu->org_unit($org);
570 $ihu->use_time($use_time);
572 my $id = $U->simplereq('open-ils.storage', $method, $ihu );
574 return $U->DB_UPDATE_FAILED($ihu) unless $id;
585 sub create_in_house_use {
586 my( $self, $client, $auth, $params ) = @_;
589 my $org = $params->{location};
590 my $copyid = $params->{copyid};
591 my $count = $params->{count} || 1;
592 my $nc_type = $params->{non_cat_type};
593 my $use_time = $params->{use_time} || 'now';
595 my $e = new_editor(xact=>1,authtoken=>$auth);
596 return $e->event unless $e->checkauth;
597 return $e->event unless $e->allowed('CREATE_IN_HOUSE_USE');
599 my $non_cat = 1 if $self->api_name =~ /non_cat/;
603 $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
605 $copy = $e->search_asset_copy({barcode=>$params->{barcode}, deleted => 'f'})->[0]
611 if( $use_time ne 'now' ) {
612 $use_time = clense_ISO8601($use_time);
613 $logger->debug("in_house_use setting use time to $use_time");
624 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
625 $ihu->item_type($nc_type);
626 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
627 $cmeth = "create_action_non_cat_in_house_use";
630 $ihu = Fieldmapper::action::in_house_use->new;
632 $method = 'open-ils.storage.direct.action.in_house_use.create';
633 $cmeth = "create_action_in_house_use";
636 $ihu->staff($e->requestor->id);
637 $ihu->org_unit($org);
638 $ihu->use_time($use_time);
640 $ihu = $e->$cmeth($ihu) or return $e->event;
641 push( @ids, $ihu->id );
652 __PACKAGE__->register_method(
653 method => "view_circs",
654 api_name => "open-ils.circ.copy_checkout_history.retrieve",
656 Retrieves the last X circs for a given copy
657 @param authtoken The login session key
658 @param copyid The copy to check
659 @param count How far to go back in the item history
660 @return An array of circ ids
666 my( $self, $client, $authtoken, $copyid, $count ) = @_;
668 my( $requestor, $evt ) = $U->checksesperm(
669 $authtoken, 'VIEW_COPY_CHECKOUT_HISTORY' );
672 return [] unless $count;
674 my $circs = $U->cstorereq(
675 'open-ils.cstore.direct.action.circulation.search.atomic',
677 target_copy => $copyid,
681 order_by => { circ => "xact_start DESC" }
689 __PACKAGE__->register_method(
690 method => "circ_count",
691 api_name => "open-ils.circ.circulation.count",
693 Returns the number of times the item has circulated
694 @param copyid The copy to check
698 my( $self, $client, $copyid, $range ) = @_;
699 my $e = OpenILS::Utils::Editor->new;
700 return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
705 __PACKAGE__->register_method(
706 method => 'fetch_notes',
707 api_name => 'open-ils.circ.copy_note.retrieve.all',
709 Returns an array of copy note objects.
710 @param args A named hash of parameters including:
711 authtoken : Required if viewing non-public notes
712 itemid : The id of the item whose notes we want to retrieve
713 pub : True if all the caller wants are public notes
714 @return An array of note objects
717 __PACKAGE__->register_method(
718 method => 'fetch_notes',
719 api_name => 'open-ils.circ.call_number_note.retrieve.all',
720 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
722 __PACKAGE__->register_method(
723 method => 'fetch_notes',
724 api_name => 'open-ils.circ.title_note.retrieve.all',
725 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
728 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
730 my( $self, $connection, $args ) = @_;
732 my $id = $$args{itemid};
733 my $authtoken = $$args{authtoken};
736 if( $self->api_name =~ /copy/ ) {
738 return $U->cstorereq(
739 'open-ils.cstore.direct.asset.copy_note.search.atomic',
740 { owning_copy => $id, pub => 't' } );
742 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
744 return $U->cstorereq(
745 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
748 } elsif( $self->api_name =~ /call_number/ ) {
750 return $U->cstorereq(
751 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
752 { call_number => $id, pub => 't' } );
754 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
756 return $U->cstorereq(
757 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
760 } elsif( $self->api_name =~ /title/ ) {
762 return $U->cstorereq(
763 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
764 { record => $id, pub => 't' } );
766 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
768 return $U->cstorereq(
769 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
776 __PACKAGE__->register_method(
777 method => 'has_notes',
778 api_name => 'open-ils.circ.copy.has_notes');
779 __PACKAGE__->register_method(
780 method => 'has_notes',
781 api_name => 'open-ils.circ.call_number.has_notes');
782 __PACKAGE__->register_method(
783 method => 'has_notes',
784 api_name => 'open-ils.circ.title.has_notes');
788 my( $self, $conn, $authtoken, $id ) = @_;
789 my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
790 return $editor->event unless $editor->checkauth;
792 my $n = $editor->search_asset_copy_note(
793 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
795 $n = $editor->search_asset_call_number_note(
796 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
798 $n = $editor->search_biblio_record_note(
799 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
806 __PACKAGE__->register_method(
807 method => 'create_copy_note',
808 api_name => 'open-ils.circ.copy_note.create',
810 Creates a new copy note
811 @param authtoken The login session key
812 @param note The note object to create
813 @return The id of the new note object
816 sub create_copy_note {
817 my( $self, $connection, $authtoken, $note ) = @_;
819 my $e = new_editor(xact=>1, authtoken=>$authtoken);
820 return $e->event unless $e->checkauth;
821 my $copy = $e->retrieve_asset_copy(
825 flesh_fields => { 'acp' => ['call_number'] }
830 return $e->event unless
831 $e->allowed('CREATE_COPY_NOTE', $copy->call_number->owning_lib);
833 $note->create_date('now');
834 $note->creator($e->requestor->id);
835 $note->pub( ($U->is_true($note->pub)) ? 't' : 'f' );
838 $e->create_asset_copy_note($note) or return $e->event;
844 __PACKAGE__->register_method(
845 method => 'delete_copy_note',
846 api_name => 'open-ils.circ.copy_note.delete',
848 Deletes an existing copy note
849 @param authtoken The login session key
850 @param noteid The id of the note to delete
851 @return 1 on success - Event otherwise.
853 sub delete_copy_note {
854 my( $self, $conn, $authtoken, $noteid ) = @_;
856 my $e = new_editor(xact=>1, authtoken=>$authtoken);
857 return $e->die_event unless $e->checkauth;
859 my $note = $e->retrieve_asset_copy_note([
863 'acpn' => [ 'owning_copy' ],
864 'acp' => [ 'call_number' ],
867 ]) or return $e->die_event;
869 if( $note->creator ne $e->requestor->id ) {
870 return $e->die_event unless
871 $e->allowed('DELETE_COPY_NOTE', $note->owning_copy->call_number->owning_lib);
874 $e->delete_asset_copy_note($note) or return $e->die_event;
880 __PACKAGE__->register_method(
881 method => 'age_hold_rules',
882 api_name => 'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
886 my( $self, $conn ) = @_;
887 return new_editor()->retrieve_all_config_rules_age_hold_protect();
892 __PACKAGE__->register_method(
893 method => 'copy_details_barcode',
895 api_name => 'open-ils.circ.copy_details.retrieve.barcode');
896 sub copy_details_barcode {
897 my( $self, $conn, $auth, $barcode ) = @_;
898 my $e = new_editor();
899 my $cid = $e->search_asset_copy({barcode=>$barcode, deleted=>'f'}, {idlist=>1})->[0];
900 return $e->event unless $cid;
901 return copy_details( $self, $conn, $auth, $cid );
905 __PACKAGE__->register_method(
906 method => 'copy_details',
907 api_name => 'open-ils.circ.copy_details.retrieve');
910 my( $self, $conn, $auth, $copy_id ) = @_;
911 my $e = new_editor(authtoken=>$auth);
912 return $e->event unless $e->checkauth;
914 my $flesh = { flesh => 1 };
916 my $copy = $e->retrieve_asset_copy(
922 acp => ['call_number'],
926 ]) or return $e->event;
929 # De-flesh the copy for backwards compatibility
931 my $vol = $copy->call_number;
933 $copy->call_number($vol->id);
934 my $record = $vol->record;
936 $vol->record($record->id);
937 $mvr = $U->record_to_mvr($record);
942 my $hold = $e->search_action_hold_request(
944 current_copy => $copy_id,
945 capture_time => { "!=" => undef },
946 fulfillment_time => undef,
947 cancel_time => undef,
951 OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
953 my $transit = $e->search_action_transit_copy(
954 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
956 # find the latest circ, open or closed
957 my $circ = $e->search_action_circulation(
959 { target_copy => $copy_id },
960 { order_by => { circ => 'xact_start desc' }, limit => 1 }
978 __PACKAGE__->register_method(
979 method => 'mark_item',
980 api_name => 'open-ils.circ.mark_item_damaged',
982 __PACKAGE__->register_method(
983 method => 'mark_item',
984 api_name => 'open-ils.circ.mark_item_missing',
988 my( $self, $conn, $auth, $copy_id ) = @_;
989 my $e = new_editor(authtoken=>$auth, xact =>1);
990 return $e->event unless $e->checkauth;
992 my $perm = 'MARK_ITEM_MISSING';
993 my $stat = OILS_COPY_STATUS_MISSING;
995 if( $self->api_name =~ /damaged/ ) {
996 $perm = 'MARK_ITEM_DAMAGED';
997 $stat = OILS_COPY_STATUS_DAMAGED;
1000 my $copy = $e->retrieve_asset_copy($copy_id)
1001 or return $e->event;
1002 $copy->status($stat);
1003 $copy->edit_date('now');
1004 $copy->editor($e->requestor->id);
1006 $e->update_asset_copy($copy) or return $e->event;
1009 my $holds = $e->search_action_hold_request(
1011 current_copy => $copy->id,
1012 fulfillment_time => undef,
1013 cancel_time => undef,
1019 $logger->debug("reseting holds that target the marked copy");
1020 OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds;
1030 # ----------------------------------------------------------------------
1031 __PACKAGE__->register_method(
1032 method => 'magic_fetch',
1033 api_name => 'open-ils.agent.fetch'
1036 my @FETCH_ALLOWED = qw/ aou aout acp acn bre /;
1039 my( $self, $conn, $auth, $args ) = @_;
1040 my $e = new_editor( authtoken => $auth );
1041 return $e->event unless $e->checkauth;
1043 my $hint = $$args{hint};
1044 my $id = $$args{id};
1046 # Is the call allowed to fetch this type of object?
1047 return undef unless grep { $_ eq $hint } @FETCH_ALLOWED;
1049 # Find the class the iplements the given hint
1050 my ($class) = grep {
1051 $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
1053 $class =~ s/Fieldmapper:://og;
1054 $class =~ s/::/_/og;
1055 my $method = "retrieve_$class";
1057 my $obj = $e->$method($id) or return $e->event;
1060 # ----------------------------------------------------------------------
1063 __PACKAGE__->register_method(
1064 method => "fleshed_circ_retrieve",
1066 api_name => "open-ils.circ.fleshed.retrieve",);
1068 sub fleshed_circ_retrieve {
1069 my( $self, $client, $id ) = @_;
1070 my $e = new_editor();
1071 my $circ = $e->retrieve_action_circulation(
1077 circ => [ qw/ target_copy / ],
1078 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect call_number / ],
1079 ascecm => [ qw/ stat_cat stat_cat_entry / ],
1080 acn => [ qw/ record / ],
1084 ) or return $e->event;
1086 my $copy = $circ->target_copy;
1087 my $vol = $copy->call_number;
1088 my $rec = $circ->target_copy->call_number->record;
1090 $vol->record($rec->id);
1091 $copy->call_number($vol->id);
1092 $circ->target_copy($copy->id);
1096 if( $rec->id == OILS_PRECAT_RECORD ) {
1100 $mvr = $U->record_to_mvr($rec);
1101 $rec->marc(''); # drop the bulky marc data
1113 # {"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}}