webstaff: Transfer Copies to Marked Volume
authorJason Etheridge <jason@esilibrary.com>
Wed, 9 Sep 2015 22:02:06 +0000 (18:02 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:21 +0000 (15:44 -0400)
in Copy Bucket

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>

Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm
Open-ILS/src/templates/staff/cat/bucket/copy/index.tt2
Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2
Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js

index 4a5d1b3..91566c2 100644 (file)
@@ -756,6 +756,76 @@ sub reset_hold_list {
     $ses->request('open-ils.circ.hold.reset.batch', $auth, $hold_ids);
 }
 
+__PACKAGE__->register_method(
+    method    => "transfer_copies_to_volume",
+    api_name  => "open-ils.cat.transfer_copies_to_volume",
+    argc      => 3,
+    signature => {
+        desc   => 'Transfers specified copies to the specified call number, and changes Circ Lib to match the new Owning Lib.',
+        params => [
+            {desc => 'Authtoken', type => 'string'},
+            {desc => 'Call Number ID', type => 'number'},
+            {desc => 'Array of Copy IDs', type => 'array'},
+        ]
+    },
+    return => {desc => '1 on success, Event on error'}
+);
+
+__PACKAGE__->register_method(
+    method   => "transfer_copies_to_volume",
+    api_name => "open-ils.cat.transfer_copies_to_volume.override",);
+
+sub transfer_copies_to_volume {
+    my( $self, $conn, $auth, $volume, $copies, $oargs ) = @_;
+    my $delete_stats = 1;
+    my $force_delete_empty_bib = undef;
+    my $create_parts = undef;
+
+    # initial tests
+
+    return 1 unless ref $copies;
+    my( $reqr, $evt ) = $U->checkses($auth);
+    return $evt if $evt;
+    my $editor = new_editor(requestor => $reqr, xact => 1);
+    if ($self->api_name =~ /override/) {
+        $oargs = { all => 1 } unless defined $oargs;
+    } else {
+        $oargs = {};
+    }
+
+    # does the volume exist?  good, we also need its owning_lib later
+    my( $cn, $cn_evt ) = $U->fetch_callnumber( $volume, 0, $editor );
+    return $cn_evt if $cn_evt;
+
+    # flesh and munge the copies
+    my $fleshed_copies = [];
+    my ($copy, $copy_evt);
+    foreach my $copy_id ( @{ $copies } ) {
+        ($copy, $copy_evt) = $U->fetch_copy($copy_id);
+        return $copy_evt if $copy_evt;
+        $copy->call_number( $volume );
+        $copy->circ_lib( $cn->owning_lib() );
+        $copy->ischanged( 't' );
+        push @$fleshed_copies, $copy;
+    }
+
+    # actual work
+    my $retarget_holds = [];
+    $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies(
+        $editor, $oargs, undef, $fleshed_copies, $delete_stats, $retarget_holds, $force_delete_empty_bib, $create_parts);
+
+    if( $evt ) { 
+        $logger->info("copy to volume transfer failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt));
+        $editor->rollback; 
+        return $evt; 
+    }
+
+    $editor->commit;
+    $logger->info("copy to volume transfer successfully updated ".scalar(@$copies)." copies");
+    reset_hold_list($auth, $retarget_holds);
+
+    return 1;
+}
 
 __PACKAGE__->register_method(
     method    => 'in_db_merge',
index db0e6dc..aa80153 100644 (file)
       "[% l('One or more items could not be deleted. Override?') %]";
     s.OVERRIDE_DELETE_COPY_BUCKET_ITEMS_FROM_CATALOG_BODY =
       "[% l('Reason(s) include: [_1]', '{{evt_desc}}') %]";
+    s.CONFIRM_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME =
+      "[% l('Are you sure you want to transfer selected items to the marked volume?') %]";
+    s.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_TITLE =
+      "[% l('One or more items could not be transferred. Override?') %]";
+    s.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_BODY =
+      "[% l('Reason(s) include: [_1]', '{{evt_desc}}') %]";
   }])
 </script>
 [% END %]
index 420dd80..6a66ed6 100644 (file)
@@ -16,6 +16,8 @@
     handler="spawnHoldingsEdit"></eg-grid-action>
   <eg-grid-action label="[% l('Remove Selected Copies') %]" 
     handler="detachCopies"></eg-grid-action>
+  <eg-grid-action label="[% l('Transfer Selected Copies to Marked Volume') %]" 
+    handler="transferCopies"></eg-grid-action>
   <eg-grid-action label="[% l('Delete Selected Copies from Catalog') %]" 
     handler="deleteCopiesFromCatalog"></eg-grid-action>
 
index c866a65..ebc4bb9 100644 (file)
@@ -602,6 +602,52 @@ function($scope,  $q , $routeParams , $timeout , $window , $modal , bucketSvc ,
         });
     }
 
+    $scope.transferCopies = function(copies) {
+        var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
+        var copy_ids = copies.map(
+            function(curr,idx,arr) {
+                return curr.id;
+            }
+        );
+        if (xfer_target) {
+            egCore.net.request(
+                'open-ils.cat',
+                'open-ils.cat.transfer_copies_to_volume',
+                egCore.auth.token(),
+                xfer_target,
+                copy_ids
+            ).then(
+                function(resp) { // oncomplete
+                    var evt = egCore.evt.parse(resp);
+                    if (evt) {
+                        egConfirmDialog.open(
+                            egCore.strings.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_TITLE,
+                            egCore.strings.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_BODY,
+                            {'evt_desc': evt.desc}
+                        ).result.then(function() {
+                            egCore.net.request(
+                                'open-ils.cat',
+                                'open-ils.cat.transfer_copies_to_volume.override',
+                                egCore.auth.token(),
+                                xfer_target,
+                                copy_ids,
+                                { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
+                            ).then(function(resp) {
+                                bucketSvc.bucketNeedsRefresh = true;
+                                drawBucket();
+                            });
+                        });
+                    } else {
+                        bucketSvc.bucketNeedsRefresh = true;
+                        drawBucket();
+                    }
+                },
+                null, // onerror
+                null // onprogress
+            )
+        }
+    }
+
     // fetch the bucket;  on error show the not-allowed message
     if ($scope.bucketId) 
         drawBucket()['catch'](function() { $scope.forbidden = true });