1 package OpenILS::Application::Cat::AssetCommon;
2 use strict; use warnings;
3 use OpenILS::Application::Cat::BibCommon;
4 use OpenILS::Utils::CStoreEditor q/:funcs/;
5 use OpenSRF::Utils::Logger qw($logger);
6 use OpenILS::Application::Cat::Merge;
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Const qw/:const/;
10 use OpenSRF::AppSession;
12 use OpenILS::Utils::Penalty;
13 use OpenILS::Application::Circ::CircCommon;
14 my $U = 'OpenILS::Application::AppUtils';
17 # ---------------------------------------------------------------------------
18 # Shared copy mangling code. Do not publish methods from here.
19 # ---------------------------------------------------------------------------
21 sub org_cannot_have_vols {
22 my($class, $e, $org_id) = @_;
23 my $org = $e->retrieve_actor_org_unit([
26 flesh_fields => {aou => ['ou_type']}
27 }]) or return $e->event;
29 return OpenILS::Event->new('ORG_CANNOT_HAVE_VOLS')
30 unless $U->is_true($org->ou_type->can_have_vols);
39 if(defined $copy->price) {
40 my $p = $copy->price || 0;
45 my $d = $copy->deposit_amount || 0;
47 $copy->deposit_amount($d);
51 my($class, $editor, $vol, $copy) = @_;
53 my $existing = $editor->search_asset_copy(
54 { barcode => $copy->barcode, deleted => 'f' } );
56 return OpenILS::Event->new('ITEM_BARCODE_EXISTS') if @$existing;
58 my $copy_loc = $editor->search_asset_copy_location(
59 { id => $copy->location, deleted => 'f' } );
61 return OpenILS::Event->new('COPY_LOCATION_NOT_FOUND') unless @$copy_loc;
63 # see if the volume this copy references is marked as deleted
64 return OpenILS::Event->new('VOLUME_DELETED', vol => $vol->id)
65 if $U->is_true($vol->deleted);
68 my $org = (ref $copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;
69 return $evt if ($evt = $class->org_cannot_have_vols($editor, $org));
72 $copy->editor($editor->requestor->id);
73 $copy->creator($editor->requestor->id);
74 $copy->create_date('now');
75 $copy->call_number($vol->id);
76 $class->fix_copy_price($copy);
78 my $cp = $editor->create_asset_copy($copy) or return $editor->die_event;
84 # 'delete_stats' is somewhat of a misnomer. With no flags set, this method
85 # still deletes any existing maps not represented in $copy->stat_cat_entries,
86 # but aborts when $copy->stat_cat_entries is empty or undefined. If
87 # 'delete_stats' is true, this method will delete all the maps when
88 # $copy->stat_cat_entries is empty or undefined.
90 # The 'add_or_update_only' flag is more straightforward. It adds missing
91 # maps, updates present maps with any new values, and leaves the rest
93 sub update_copy_stat_entries {
94 my($class, $editor, $copy, $delete_stats, $add_or_update_only) = @_;
96 return undef if $copy->isdeleted;
97 return undef unless $copy->ischanged or $copy->isnew;
100 my $entries = $copy->stat_cat_entries;
102 if( $delete_stats ) {
103 $entries = ($entries and @$entries) ? $entries : [];
105 return undef unless ($entries and @$entries);
108 my $maps = $editor->search_asset_stat_cat_entry_copy_map({owning_copy=>$copy->id});
111 # if there is no stat cat entry on the copy who's id matches the
112 # current map's id, remove the map from the database
113 for my $map (@$maps) {
114 if (!$add_or_update_only) {
115 if(! grep { $_->id == $map->stat_cat_entry } @$entries ) {
117 $logger->info("copy update found stale ".
118 "stat cat entry map ".$map->id. " on copy ".$copy->id);
120 $editor->delete_asset_stat_cat_entry_copy_map($map)
121 or return $editor->event;
124 if( grep { $_->stat_cat == $map->stat_cat and $_->id != $map->stat_cat_entry } @$entries ) {
126 $logger->info("copy update found ".
127 "stat cat entry map ".$map->id. " needing update on copy ".$copy->id);
129 $editor->delete_asset_stat_cat_entry_copy_map($map)
130 or return $editor->event;
136 # go through the stat cat update/create process
137 for my $entry (@$entries) {
140 # if this link already exists in the DB, don't attempt to re-create it
141 next if( grep{$_->stat_cat_entry == $entry->id} @$maps );
143 my $new_map = Fieldmapper::asset::stat_cat_entry_copy_map->new();
145 my $sc = ref($entry->stat_cat) ? $entry->stat_cat->id : $entry->stat_cat;
147 $new_map->stat_cat( $sc );
148 $new_map->stat_cat_entry( $entry->id );
149 $new_map->owning_copy( $copy->id );
151 $editor->create_asset_stat_cat_entry_copy_map($new_map)
152 or return $editor->event;
154 $logger->info("copy update created new stat cat entry map ".$editor->data);
160 # if 'delete_maps' is true, the copy->parts data is treated as the
161 # authoritative list for the copy. existing part maps not targeting
162 # these parts will be deleted from the DB
163 sub update_copy_parts {
164 my($class, $editor, $copy, $delete_maps, $create_parts) = @_;
166 return undef if $copy->isdeleted;
167 return undef unless $copy->ischanged or $copy->isnew;
170 my $incoming_parts = $copy->parts;
173 $incoming_parts = ($incoming_parts and @$incoming_parts) ? $incoming_parts : [];
175 return undef unless ($incoming_parts and @$incoming_parts);
178 my $maps = $editor->search_asset_copy_part_map({target_copy=>$copy->id});
181 # if there is no part map on the copy who's id matches the
182 # current map's id, remove the map from the database
183 for my $map (@$maps) {
184 if(! grep { $_->id == $map->part } @$incoming_parts ) {
186 $logger->info("copy update found stale ".
187 "monographic part map ".$map->id. " on copy ".$copy->id);
189 $editor->delete_asset_copy_part_map($map)
190 or return $editor->event;
195 # go through the part map update/create process
196 for my $incoming_part (@$incoming_parts) {
197 next unless $incoming_part;
199 # if this link already exists in the DB, don't attempt to re-create it
200 next if( grep{$_->part == $incoming_part->id} @$maps );
202 if ($incoming_part->isnew) {
203 next unless $create_parts;
204 my $new_part = Fieldmapper::biblio::monograph_part->new();
205 $new_part->record( $incoming_part->record );
206 $new_part->label( $incoming_part->label );
207 $incoming_part = $editor->create_biblio_monograph_part($new_part)
208 or return $editor->event;
211 my $new_map = Fieldmapper::asset::copy_part_map->new();
213 $new_map->part( $incoming_part->id );
214 $new_map->target_copy( $copy->id );
216 $editor->create_asset_copy_part_map($new_map)
217 or return $editor->event;
219 $logger->info("copy update created new monographic part copy map ".$editor->data);
227 sub update_copy_notes {
228 my($class, $editor, $copy) = @_;
230 return undef if $copy->isdeleted;
231 return undef unless $copy->ischanged or $copy->isnew;
234 my $incoming_notes = $copy->notes;
236 for my $incoming_note (@$incoming_notes) {
237 next unless $incoming_note;
239 if ($incoming_note->isnew) {
240 my $new_note = Fieldmapper::asset::copy_note->new();
241 $new_note->owning_copy( $copy->id );
242 $new_note->pub( $incoming_note->pub );
243 $new_note->title( $incoming_note->title );
244 $new_note->value( $incoming_note->value );
245 $new_note->creator( $incoming_note->creator || $editor->requestor->id );
246 $incoming_note = $editor->create_asset_copy_note($new_note)
247 or return $editor->event;
248 } elif ($incoming_note->ischanged) {
249 $incoming_note = $editor->update_asset_copy_note($incoming_note)
250 } elif ($incoming_note->isdeleted) {
251 $incoming_note = $editor->delete_asset_copy_note($incoming_note->id)
262 my($class, $editor, $override, $vol, $copy, $retarget_holds, $force_delete_empty_bib) = @_;
264 $override = { all => 1 } if($override && !ref $override);
265 $override = { all => 0 } if(!ref $override);
267 # Duplicated check from create_copy in case a copy template with a deleted location is applied later
268 my $copy_loc = $editor->search_asset_copy_location(
269 { id => $copy->location, deleted => 'f' } );
271 return OpenILS::Event->new('COPY_LOCATION_NOT_FOUND') unless @$copy_loc;
274 my $org = (ref $copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;
275 return $evt if ( $evt = $class->org_cannot_have_vols($editor, $org) );
277 $logger->info("vol-update: updating copy ".$copy->id);
278 my $orig_copy = $editor->retrieve_asset_copy($copy->id);
280 # Call-number may have changed, find the original
281 my $orig_vol_id = $editor->json_query({select => {acp => ['call_number']}, from => 'acp', where => {id => $copy->id}});
282 my $orig_vol = $editor->retrieve_asset_call_number($orig_vol_id->[0]->{call_number});
284 $copy->editor($editor->requestor->id);
285 $copy->edit_date('now');
287 $copy->age_protect( $copy->age_protect->id )
288 if ref $copy->age_protect;
290 $class->fix_copy_price($copy);
291 $class->check_hold_retarget($editor, $copy, $orig_copy, $retarget_holds);
293 return $editor->event unless $editor->update_asset_copy($copy);
294 return $class->remove_empty_objects($editor, $override, $orig_vol, $force_delete_empty_bib);
297 sub check_hold_retarget {
298 my($class, $editor, $copy, $orig_copy, $retarget_holds) = @_;
299 return unless $retarget_holds;
301 if( !($copy->isdeleted or $U->is_true($copy->deleted)) ) {
302 # see if a status change warrants a retarget
304 $orig_copy = $editor->retrieve_asset_copy($copy->id) unless $orig_copy;
306 if($orig_copy->status == $copy->status) {
307 # no status change, no retarget
311 my $stat = $editor->retrieve_config_copy_status($copy->status);
313 # new status is holdable, no retarget. Later add logic to find potential
314 # holds and retarget those to pick up the newly available copy
315 return if $U->is_true($stat->holdable);
318 my $hold_ids = $editor->search_action_hold_request(
319 { current_copy => $copy->id,
320 cancel_time => undef,
321 fulfillment_time => undef
325 push(@$retarget_holds, @$hold_ids);
329 # this does the actual work
330 sub update_fleshed_copies {
331 my($class, $editor, $override, $vol, $copies, $delete_stats, $retarget_holds, $force_delete_empty_bib, $create_parts) = @_;
333 $override = { all => 1 } if($override && !ref $override);
334 $override = { all => 0 } if(!ref $override);
337 my $fetchvol = ($vol) ? 0 : 1;
340 $cache{$vol->id} = $vol if $vol;
342 for my $copy (@$copies) {
344 my $copyid = $copy->id;
345 $logger->info("vol-update: inspecting copy $copyid");
347 if( !($vol = $cache{$copy->call_number}) ) {
348 $vol = $cache{$copy->call_number} =
349 $editor->retrieve_asset_call_number($copy->call_number);
350 return $editor->event unless $vol;
353 return $editor->event unless
354 $editor->allowed('UPDATE_COPY', $class->copy_perm_org($vol, $copy));
356 $copy->editor($editor->requestor->id);
357 $copy->edit_date('now');
359 $copy->status( $copy->status->id ) if ref($copy->status);
360 $copy->location( $copy->location->id ) if ref($copy->location);
361 $copy->circ_lib( $copy->circ_lib->id ) if ref($copy->circ_lib);
363 my $sc_entries = $copy->stat_cat_entries;
364 $copy->clear_stat_cat_entries;
366 my $parts = $copy->parts;
369 if( $copy->isdeleted ) {
370 $evt = $class->delete_copy($editor, $override, $vol, $copy, $retarget_holds, $force_delete_empty_bib);
373 } elsif( $copy->isnew ) {
374 $evt = $class->create_copy( $editor, $vol, $copy );
377 } elsif( $copy->ischanged ) {
379 $evt = $class->update_copy( $editor, $override, $vol, $copy, $retarget_holds, $force_delete_empty_bib);
383 $copy->stat_cat_entries( $sc_entries );
384 $evt = $class->update_copy_stat_entries($editor, $copy, $delete_stats);
385 $copy->parts( $parts );
386 # probably okay to use $delete_stats here for simplicity
387 $evt = $class->update_copy_parts($editor, $copy, $delete_stats, $create_parts);
388 $evt = $class->update_copy_notes($editor, $copy);
392 $logger->debug("vol-update: done updating copy batch");
399 my($class, $editor, $override, $vol, $copy, $retarget_holds, $force_delete_empty_bib, $skip_empty_cleanup) = @_;
401 return $editor->event unless
402 $editor->allowed('DELETE_COPY', $class->copy_perm_org($vol, $copy));
404 $override = { all => 1 } if($override && !ref $override);
405 $override = { all => 0 } if(!ref $override);
407 my $stat = $U->copy_status($copy->status);
408 if ($U->is_true($stat->restrict_copy_delete)) {
409 if ($override->{all} || grep { $_ eq 'COPY_DELETE_WARNING' } @{$override->{events}}) {
410 return $editor->event unless $editor->allowed('COPY_DELETE_WARNING.override', $class->copy_perm_org($vol, $copy))
412 return OpenILS::Event->new('COPY_DELETE_WARNING', payload => $copy->id )
416 $logger->info("vol-update: deleting copy ".$copy->id);
419 $copy->editor($editor->requestor->id);
420 $copy->edit_date('now');
421 $editor->update_asset_copy($copy) or return $editor->event;
423 # Delete any open transits for this copy
424 my $transits = $editor->search_action_transit_copy(
425 { target_copy=>$copy->id, dest_recv_time => undef } );
427 for my $t (@$transits) {
428 $editor->delete_action_transit_copy($t)
429 or return $editor->event;
432 my $evt = $class->cancel_copy_holds($editor, $copy);
435 $class->check_hold_retarget($editor, $copy, undef, $retarget_holds);
437 return undef if $skip_empty_cleanup;
439 return $class->remove_empty_objects($editor, $override, $vol, $force_delete_empty_bib);
443 # deletes all holds that specifically target the deleted copy
444 sub cancel_copy_holds {
445 my($class, $editor, $copy) = @_;
447 my $holds = $editor->search_action_hold_request({
449 hold_type => [qw/C R F/],
450 cancel_time => undef,
451 fulfillment_time => undef
454 return $class->cancel_hold_list($editor, $holds);
457 # deletes all holds that specifically target the deleted volume
458 sub cancel_volume_holds {
459 my($class, $editor, $volume) = @_;
461 my $holds = $editor->search_action_hold_request({
462 target => $volume->id,
464 cancel_time => undef,
465 fulfillment_time => undef
468 return $class->cancel_hold_list($editor, $holds);
471 sub cancel_hold_list {
472 my($class, $editor, $holds) = @_;
474 for my $hold (@$holds) {
476 $hold->cancel_time('now');
477 $hold->cancel_cause(1); # un-targeted expiration. Do we need an alternate "target deleted" cause?
478 $editor->update_action_hold_request($hold) or return $editor->die_event;
480 # tell A/T the hold was cancelled. Don't wait for a response..
481 my $at_ses = OpenSRF::AppSession->create('open-ils.trigger');
483 'open-ils.trigger.event.autocreate',
484 'hold_request.cancel.expire_no_target',
485 $hold, $hold->pickup_lib);
494 my($class, $override, $editor, $vol) = @_;
497 return $evt if ( $evt = $class->org_cannot_have_vols($editor, $vol->owning_lib) );
499 $override = { all => 1 } if($override && !ref $override);
500 $override = { all => 0 } if(!ref $override);
502 # see if the record this volume references is marked as deleted
503 my $rec = $editor->retrieve_biblio_record_entry($vol->record)
504 or return $editor->die_event;
505 return OpenILS::Event->new('BIB_RECORD_DELETED', rec => $rec->id)
506 if $U->is_true($rec->deleted);
508 # first lets see if there are any collisions
509 my $vols = $editor->search_asset_call_number( {
510 owning_lib => $vol->owning_lib,
511 record => $vol->record,
512 label => $vol->label,
513 prefix => $vol->prefix,
514 suffix => $vol->suffix,
521 # we've found an exising volume
522 if($override->{all} || grep { $_ eq 'VOLUME_LABEL_EXISTS' } @{$override->{events}}) {
523 $label = $vol->label;
525 return OpenILS::Event->new(
526 'VOLUME_LABEL_EXISTS', payload => $vol->id);
530 # create a temp label so we can create the new volume,
531 # then de-dup it with the existing volume
532 $vol->label( "__SYSTEM_TMP_$$".time) if $label;
534 $vol->creator($editor->requestor->id);
535 $vol->create_date('now');
536 $vol->editor($editor->requestor->id);
537 $vol->edit_date('now');
540 $editor->create_asset_call_number($vol) or return $editor->die_event;
543 # now restore the label and merge into the existing record
546 OpenILS::Application::Cat::Merge::merge_volumes($editor, [$vol], $$vols[0]);
553 # returns the volume if it exists
555 my($class, $e, $rec_id, $label, $owning_lib, $prefix, $suffix) = @_;
556 return $e->search_asset_call_number(
557 {label => $label, record => $rec_id, owning_lib => $owning_lib, deleted => 'f', prefix => $prefix, suffix => $suffix})->[0];
560 sub find_or_create_volume {
561 my($class, $e, $label, $record_id, $org_id, $prefix, $suffix, $label_class) = @_;
568 if($record_id == OILS_PRECAT_RECORD) {
569 $vol = $e->retrieve_asset_call_number(OILS_PRECAT_CALL_NUMBER)
570 or return (undef, $e->die_event);
573 $vol = $class->volume_exists($e, $record_id, $label, $org_id, $prefix, $suffix);
576 # If the volume exists, return the ID
577 return ($vol, undef, 1) if $vol;
579 # -----------------------------------------------------------------
580 # Otherwise, create a new volume with the given attributes
581 # -----------------------------------------------------------------
582 return (undef, $e->die_event) unless $e->allowed('UPDATE_VOLUME', $org_id);
584 $vol = Fieldmapper::asset::call_number->new;
585 $vol->owning_lib($org_id);
586 $vol->label_class($label_class) if ($label_class);
588 $vol->prefix($prefix);
589 $vol->suffix($suffix);
590 $vol->record($record_id);
592 my $evt = $class->create_volume(0, $e, $vol);
593 return (undef, $evt) if $evt;
599 sub create_copy_note {
600 my($class, $e, $copy, $title, $value, $pub) = @_;
601 my $note = Fieldmapper::asset::copy_note->new;
602 $note->owning_copy($copy->id);
603 $note->creator($e->requestor->id);
604 $note->pub($pub ? 't' : 'f');
605 $note->value($value);
606 $note->title($title);
607 $e->create_asset_copy_note($note) or return $e->die_event;
612 sub remove_empty_objects {
613 my($class, $editor, $override, $vol, $force_delete_empty_bib) = @_;
615 $override = { all => 1 } if($override && !ref $override);
616 $override = { all => 0 } if(!ref $override);
618 my $koe = $U->ou_ancestor_setting_value(
619 $editor->requestor->ws_ou, 'cat.bib.keep_on_empty', $editor);
620 my $aoe = $U->ou_ancestor_setting_value(
621 $editor->requestor->ws_ou, 'cat.bib.alert_on_empty', $editor);
623 if( OpenILS::Application::Cat::BibCommon->title_is_empty($editor, $vol->record, $vol->id) ) {
625 # delete this volume if it's not already marked as deleted
626 unless( $U->is_true($vol->deleted) || $vol->isdeleted ) {
627 my $evt = $class->delete_volume($editor, $vol, $override, 0, 1);
631 return OpenILS::Event->new('TITLE_LAST_COPY', payload => $vol->record )
632 if $aoe and not ($override->{all} || grep { $_ eq 'TITLE_LAST_COPY' } @{$override->{events}}) and not $force_delete_empty_bib;
634 unless($koe and not $force_delete_empty_bib) {
635 # delete the bib record if the keep-on-empty setting is not set (and we're not otherwise forcing things, say through acq settings)
636 my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($editor, $vol->record);
642 # this may be the last copy attached to the volume.
644 if($U->ou_ancestor_setting_value(
645 $editor->requestor->ws_ou, 'cat.volume.delete_on_empty', $editor)) {
647 # if this volume is "empty" and not mid-delete, delete it.
648 unless($U->is_true($vol->deleted) || $vol->isdeleted) {
650 my $copies = $editor->search_asset_copy(
651 [{call_number => $vol->id, deleted => 'f'}, {limit => 1}], {idlist => 1});
654 my $evt = $class->delete_volume($editor, $vol, $override, 0, 1);
664 # Deletes a volume. Returns undef on success, event on error
665 # force : deletes all attached copies
666 # skip_copy_check : assumes caller has verified no copies need deleting first
668 my($class, $editor, $vol, $override, $delete_copies, $skip_copy_checks) = @_;
671 unless($skip_copy_checks) {
672 my $cs = $editor->search_asset_copy(
673 [{call_number => $vol->id, deleted => 'f'}, {limit => 1}], {idlist => 1});
675 return OpenILS::Event->new('VOLUME_NOT_EMPTY', payload => $vol->id)
676 if @$cs and !$delete_copies;
678 my $copies = $editor->search_asset_copy({call_number => $vol->id, deleted => 'f'});
680 for my $copy (@$copies) {
681 $evt = $class->delete_copy($editor, $override, $vol, $copy, 0, 0, 1);
687 $vol->edit_date('now');
688 $vol->editor($editor->requestor->id);
689 $editor->update_asset_call_number($vol) or return $editor->die_event;
691 $evt = $class->cancel_volume_holds($editor, $vol);
694 # handle the case where this is the last volume on the record
695 return $class->remove_empty_objects($editor, $override, $vol);
700 my($class, $vol, $copy) = @_;
701 my $org = $vol->owning_lib;
702 if( $vol->id == OILS_PRECAT_CALL_NUMBER ) {
703 $org = ref($copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;
705 $logger->debug("using copy perm org $org");
711 my ($class, $e, $copy_id) = @_;
713 return $class->set_item_lost_or_lod(
715 perm => 'SET_CIRC_LOST',
716 status => OILS_COPY_STATUS_LOST,
717 ous_proc_fee => OILS_SETTING_LOST_PROCESSING_FEE,
718 ous_void_od => OILS_SETTING_VOID_OVERDUE_ON_LOST,
721 bill_note => 'Lost Materials',
722 bill_fee_note => 'Lost Materials Processing Fee',
723 event => 'COPY_MARKED_LOST',
724 stop_fines => OILS_STOP_FINES_LOST,
729 sub set_item_long_overdue {
730 my ($class, $e, $copy_id) = @_;
732 return $class->set_item_lost_or_lod(
734 perm => 'SET_CIRC_LONG_OVERDUE',
735 status => 16, # Long Overdue
736 ous_proc_fee => 'circ.longoverdue_materials_processing_fee',
737 ous_void_od => 'circ.void_overdue_on_longoverdue',
740 bill_note => 'Long Overdue Materials',
741 bill_fee_note => 'Long Overdue Materials Processing Fee',
742 event => 'COPY_MARKED_LONG_OVERDUE',
743 stop_fines => 'LONGOVERDUE',
744 at_hook => 'longoverdue'
748 # LOST or LONGOVERDUE
749 # basic process is the same. details change.
750 sub set_item_lost_or_lod {
751 my ($class, $e, $copy_id, %args) = @_;
753 my $copy = $e->retrieve_asset_copy([
755 {flesh => 1, flesh_fields => {'acp' => ['call_number']}}])
756 or return $e->die_event;
759 ($copy->call_number->id == OILS_PRECAT_CALL_NUMBER) ?
760 $copy->circ_lib : $copy->call_number->owning_lib;
762 my $circ = $e->search_action_circulation(
763 {checkin_time => undef, target_copy => $copy->id} )->[0]
764 or return $e->die_event;
766 $e->allowed($args{perm}, $circ->circ_lib) or return $e->die_event;
768 return $e->die_event(OpenILS::Event->new($args{event}))
769 if $copy->status == $args{status};
771 # ---------------------------------------------------------------------
772 # fetch the related org settings
773 my $proc_fee = $U->ou_ancestor_setting_value(
774 $owning_lib, $args{ous_proc_fee}, $e) || 0;
775 my $void_overdue = $U->ou_ancestor_setting_value(
776 $owning_lib, $args{ous_void_od}, $e) || 0;
778 # ---------------------------------------------------------------------
779 # move the copy into LOST status
780 $copy->status($args{status});
781 $copy->editor($e->requestor->id);
782 $copy->edit_date('now');
783 $e->update_asset_copy($copy) or return $e->die_event;
785 my $price = $U->get_copy_price($e, $copy, $copy->call_number);
788 my $evt = OpenILS::Application::Circ::CircCommon->create_bill($e,
789 $price, $args{bill_type}, $args{bill_note}, $circ->id);
793 # ---------------------------------------------------------------------
794 # if there is a processing fee, charge that too
795 if( $proc_fee > 0 ) {
796 my $evt = OpenILS::Application::Circ::CircCommon->create_bill($e,
797 $proc_fee, $args{bill_fee_type}, $args{bill_fee_note}, $circ->id);
801 # ---------------------------------------------------------------------
802 # mark the circ as lost and stop the fines
803 $circ->stop_fines($args{stop_fines});
804 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
805 $e->update_action_circulation($circ) or return $e->die_event;
807 # ---------------------------------------------------------------------
808 # zero out overdue fines on this circ if configured
809 if( $void_overdue ) {
810 my $evt = OpenILS::Application::Circ::CircCommon->void_or_zero_overdues($e, $circ, {force_zero => 1});
814 my $evt = OpenILS::Application::Circ::CircCommon->reopen_xact($e, $circ->id);
817 my $ses = OpenSRF::AppSession->create('open-ils.trigger');
819 'open-ils.trigger.event.autocreate',
820 $args{at_hook}, $circ, $circ->circ_lib
823 my $evt2 = OpenILS::Utils::Penalty->calculate_penalties(
824 $e, $circ->usr, $U->xact_org($circ->id, $e));
825 return $evt2 if $evt2;