From ce5898201096f602df3cb895e8277fc0dccdf4f8 Mon Sep 17 00:00:00 2001 From: phasefx Date: Tue, 27 Jul 2010 22:33:34 +0000 Subject: [PATCH] middle layer support and client-side utility function. missing messagecat for missing pieces dialog git-svn-id: svn://svn.open-ils.org/ILS/trunk@17047 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Circ.pm | 137 +++++++++++++++++++++ .../staff_client/chrome/content/main/constants.js | 1 + Open-ILS/xul/staff_client/server/cat/util.js | 39 +++++- .../staff_client/server/circ/missing_pieces.xul | 1 + .../server/locale/en-US/cat.properties | 9 ++ 5 files changed, 186 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 2a414d3cd..e8db5b008 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -35,6 +35,7 @@ use OpenILS::Application::Cat::AssetCommon; my $apputils = "OpenILS::Application::AppUtils"; my $U = $apputils; +my $holdcode = "OpenILS::Application::Circ::Holds"; # ------------------------------------------------------------------------ # Top level Circ package; @@ -1202,6 +1203,142 @@ sub handle_mark_damaged { +# ---------------------------------------------------------------------- +__PACKAGE__->register_method( + method => 'mark_item_missing_pieces', + api_name => 'open-ils.circ.mark_item_missing_pieces', + signature => q/ + Changes the status of a copy to "damaged" or to a custom status based on the + circ.missing_pieces.copy_status org unit setting. Requires MARK_ITEM_MISSING_PIECES + permission. + @param authtoken The login session key + @param copy_id The ID of the copy to mark as damaged + @return Success event with circ and copy objects in the payload, or error Event otherwise. + / +); + +sub mark_item_missing_pieces { + my( $self, $conn, $auth, $copy_id, $args ) = @_; + ### FIXME: We're starting a transaction here, but we're doing a lot of things outside of the transaction + my $e = new_editor(authtoken=>$auth, xact =>1); + return $e->die_event unless $e->checkauth; + $args ||= {}; + + my $copy = $e->retrieve_asset_copy([ + $copy_id, + {flesh => 1, flesh_fields => {'acp' => ['call_number']}}]) + or return $e->die_event; + + my $owning_lib = + ($copy->call_number->id == OILS_PRECAT_CALL_NUMBER) ? + $copy->circ_lib : $copy->call_number->owning_lib; + + return $e->die_event unless $e->allowed('MARK_ITEM_MISSING_PIECES', $owning_lib); + + #### grab the last circulation + my $circ = $e->search_action_circulation([ + { target_copy => $copy->id}, + { limit => 1, + order_by => {circ => "xact_start DESC"} + } + ])->[0]; + + if ($circ) { + if (! $circ->checkin_time) { # if circ active, attempt renew + my ($res) = $self->method_lookup('open-ils.circ.renew')->run($e->authtoken,{'copy_id'=>$circ->target_copy}); + if (ref $res ne 'ARRAY') { $res = [ $res ]; } + if ( $res->[0]->{textcode} eq 'SUCCESS' ) { + $circ = $res->[0]->{payload}{'circ'}; + $circ->target_copy( $copy->id ); + $logger->info('open-ils.circ.mark_item_missing_pieces: successful renewal'); + } else { + $logger->info('open-ils.circ.mark_item_missing_pieces: non-successful renewal'); + } + } else { + + my $co_params = { + 'copy_id'=>$circ->target_copy, + 'patron_id'=>$circ->usr, + 'skip_deposit_fee'=>1, + 'skip_rental_fee'=>1 + }; + + if ($U->ou_ancestor_setting_value($e->requestor->ws_ou, 'circ.block_renews_for_holds')) { + + my ($hold, undef, $retarget) = $holdcode->find_nearest_permitted_hold( + $e, $copy, $e->requestor, 1 ); + + if ($hold) { # needed for hold? then due now + + $logger->info('open-ils.circ.mark_item_missing_pieces: item needed for hold, shortening due date'); + my $due_date = DateTime->now(time_zone => 'local'); + $co_params->{'due_date'} = cleanse_ISO8601( $due_date->strftime('%FT%T%z') ); + } else { + $logger->info('open-ils.circ.mark_item_missing_pieces: item not needed for hold'); + } + } + + my ($res) = $self->method_lookup('open-ils.circ.checkout.full.override')->run($e->authtoken,$co_params); + if (ref $res ne 'ARRAY') { $res = [ $res ]; } + if ( $res->[0]->{textcode} eq 'SUCCESS' ) { + $logger->info('open-ils.circ.mark_item_missing_pieces: successful checkout'); + $circ = $res->[0]->{payload}{'circ'}; + } else { + $logger->info('open-ils.circ.mark_item_missing_pieces: non-successful checkout'); + $e->rollback; + return $res; + } + } + } else { + $logger->info('open-ils.circ.mark_item_missing_pieces: no previous checkout'); + $e->rollback; + return OpenILS::Event->new('ACTION_CIRCULATION_NOT_FOUND',{'copy'=>$copy}); + } + + ### Update the item status + + my $custom_stat = $U->ou_ancestor_setting_value( + $owning_lib, 'circ.missing_pieces.copy_status', $e); + my $stat = $custom_stat || OILS_COPY_STATUS_DAMAGED; + + my $ses = OpenSRF::AppSession->create('open-ils.trigger'); + $ses->request('open-ils.trigger.event.autocreate', 'missing_pieces', $copy, $owning_lib); + + $copy->status($stat); + $copy->edit_date('now'); + $copy->editor($e->requestor->id); + + $e->update_asset_copy($copy) or return $e->die_event; + + my $holds = $e->search_action_hold_request( + { + current_copy => $copy->id, + fulfillment_time => undef, + cancel_time => undef, + } + ); + + $logger->debug("resetting holds that target the marked copy"); + OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds; + + if ($e->commit) { + + my $ses = OpenSRF::AppSession->create('open-ils.trigger'); + $ses->request('open-ils.trigger.event.autocreate', 'checkout.missing_pieces', $circ, $circ->circ_lib); + + return OpenILS::Event->new('SUCCESS', + payload => { + circ => $circ, + copy => $copy + } + ); + + } else { + return $e->die_event; + } +} + + diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index cd5fab472..cf50fd0dc 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -278,6 +278,7 @@ var api = { 'FM_BLOB_RETRIEVE_VIA_Z3950_RAW_SEARCH' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.z3950.search_service' }, 'RETRIEVE_Z3950_SERVICES' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.z3950.retrieve_services', 'secure' : false }, 'MARK_ITEM_DAMAGED' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.mark_item_damaged' }, + 'MARK_ITEM_MISSING_PIECES' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.mark_item_missing_pieces' }, 'MARK_ITEM_MISSING' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.mark_item_missing' }, 'MARK_ITEM_LOST' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.circulation.set_lost' }, 'MARK_ITEM_CLAIM_RETURNED' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.circulation.set_claims_returned' }, diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js index 9622a7278..d4a01abf2 100644 --- a/Open-ILS/xul/staff_client/server/cat/util.js +++ b/Open-ILS/xul/staff_client/server/cat/util.js @@ -740,7 +740,44 @@ cat.util.render_loan_duration = function(value) { } cat.util.mark_item_as_missing_pieces = function(copy_ids) { - alert(js2JSON(copy_ids)); + var error; + try { + JSAN.use('util.error'); error = new util.error(); + JSAN.use('util.functional'); JSAN.use('util.date'); + JSAN.use('util.network'); var network = new util.network(); + var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ copy_ids ]); + if (typeof copies.ilsevent != 'undefined') throw(copies); + + var r = error.yns_alert($("catStrings").getFormattedString('staff.cat.util.mark_item_missing_pieces.ms_message', [util.functional.map_list( copies, function(o) { return o.barcode(); } ).join(", ")]), + $("catStrings").getString('staff.cat.util.mark_item_missing_pieces.ms_title'), + $("catStrings").getString('staff.cat.util.mark_item_missing_pieces.ms_ok_label'), + $("catStrings").getString('staff.cat.util.mark_item_missing_pieces.ms_cancel_label'), null, + $("catStrings").getString('staff.cat.util.mark_item_missing_pieces.ms_confirm_action')); + + if (r == 0) { + var count = 0; + for (var i = 0; i < copies.length; i++) { + try { + var robj = network.simple_request('MARK_ITEM_MISSING_PIECES',[ses(),copies[i].id()]); + if (typeof robj.ilsevent != 'undefined') { throw(robj); } + // TODO: Print missing pieces slip + // TODO: Bill patron prompt + // TODO: Item/patron notes/messages + // TODO: Invoke 3rd party app with letter to patron + count++; + } catch(E) { + error.standard_unexpected_error_alert($("catStrings").getFormattedString('staff.cat.util.mark_item_missing_pieces.marking_error', [copies[i].barcode()]),E); + } + } + alert(count == 1 ? $("catStrings").getString('staff.cat.util.mark_item_missing_pieces.one_item_missing_pieces') : + $("catStrings").getFormattedString('staff.cat.util.mark_item_missing_pieces.multiple_item_missing_pieces', [count])); + } + + return true; + } catch(E) { + alert('Error in cat.util.mark_item_as_missing_pieces: ' + E); + return false; + } } dump('exiting cat/util.js\n'); diff --git a/Open-ILS/xul/staff_client/server/circ/missing_pieces.xul b/Open-ILS/xul/staff_client/server/circ/missing_pieces.xul index 303e6ce3d..5c24a0a75 100644 --- a/Open-ILS/xul/staff_client/server/circ/missing_pieces.xul +++ b/Open-ILS/xul/staff_client/server/circ/missing_pieces.xul @@ -29,6 +29,7 @@ +