Bug 17674: Allow UI to delete serials in batch
authorPierre-Marc Thibault <pierre-marc.thibault@inLibro.com>
Wed, 10 Oct 2018 15:25:59 +0000 (11:25 -0400)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 19 Mar 2020 09:30:38 +0000 (09:30 +0000)
This new feature allows for batch deletion of serials through the UI.  The current usage is a one-by-one long game.

Test plan :
- Apply patch.
- Create at least four serials with items.
- Notice that new items have a numbering pattern and a date in the enumchron field.
- Use the button Delete selected issues for the following steps.
- Delete a serial and its associated item.
- Confirm the serial and item are gone.
- Delete a serial and not its item.
- Confirm the serial is gone.
- Confirm the item is still there and the date part in the enumchron field is gone.
- Delete the two lasts serials.
- Confirm they are gone.

Sponsored-by: CCSR
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Sonia <sonia.bouis@univ-lyon3.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt
serials/serials-collection.pl

index 7d4310d..b7e02f4 100644 (file)
                [% IF ( callnumber ) %]callnumber: [% callnumber | html %][% END %]</h1>
 [% END %]
 
+[% IF ( delete ) %]
+    <div class="dialog alert">
+        <h3>You are about to delete [% serialnumber | html %] serial(s). Do you want to continue?</h3>
+        <form action="/cgi-bin/koha/serials/serials-collection.pl/#">
+            [% IF countitems > 0 %]
+                <h5>Number of items available: [% countitems | html %]</h5>
+                <p>
+                  <label>Delete associated items? <input type="checkbox" name="delitems" value="Yes" />Yes</label>
+                </p>
+            [% END %]
+            <input type="hidden" name="op" value="delete_confirmed" />
+            <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
+            <input type="hidden" name="subscriptionid" value="[% subscriptionid | html %]" />
+            [% FOREACH serialid IN serialsid %]
+                <input type="hidden" name="serialid" value="[% serialid | html %]" />
+            [% END %]
+            <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
+        </form>
+        <form action="/cgi-bin/koha/serials/serials-collection.pl">
+            <input type="hidden" name="subscriptionid" value="[% subscriptionid | html %]" />
+            <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
+        </form>
+    </div>
+[% END %]
+
 [% IF ( subscriptions ) %]
 <table>
 [% IF ( subscriptions.size == 1 ) %]
                     <div class="btn-group"><input type="button" value="Multi receiving" href="#multi_receiving" class="btn btn-default btn-sm" data-toggle="modal"></div>
                 [% END %]
             [% END %]
+            <input type="button" value="Delete selected issues" class="delete-issues btn btn-default btn-sm" data-subscriptionids="[% subscriptionidlist | html %]" />
         </p>
     [% END %]
       <span class="checkall">
                     [% IF ( serial.subscriptionexpired ) %]
                     <input type="checkbox" name="serialid" value="[% serial.serialid | html %]" disabled="disabled" />
                     [% ELSE %]
-                      [% IF ( serial.checked ) %]
-                    <input type="checkbox" class="checkboxed" name="serialid" checked="checked" value="[% serial.serialid | html %]" />
+                      [% IF ( delete ) %]
+                        [% IF serialsid.grep("${serial.serialid}").size %]
+                          <input type="checkbox" class="checkboxed" name="serialid" value="[% serial.serialid | html %]" disabled checked />
+                        [% ELSE %]
+                          <input type="checkbox" class="checkboxed" name="serialid" value="[% serial.serialid | html %]" disabled />
+                        [% END %]
                       [% ELSE %]
                     <input type="checkbox" class="checkboxed" name="serialid" value="[% serial.serialid | html %]" />
                       [% END %]
 
     <script>
 
+        function deleteIssues(subscriptionid) {
+            var serialschecked = $("form[name='edition'] input[name='serialid']:checked");
+            if (serialschecked.length > 0) {
+                var location = 'serials-collection.pl?subscriptionid='+subscriptionid+'&op=delete_confirm';
+                for (i=0; i < serialschecked.length; i++) {
+                    location += '&serialid=' + serialschecked[i].value;
+                }
+                document.location = location;
+            } else {
+                alert(_("No serials selected"));
+            }
+        }
+
         function print_slip(subscriptionid,issue){
             var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue;
             window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
                 }
                 return 1;
             });
+
+            $(".delete-issues").on("click", function(e){
+                e.preventDefault();
+                deleteIssues("[% subscriptionidlist | html %]");
+            });
         });
 
     </script>
index d9ab11a..0977e97 100755 (executable)
@@ -27,6 +27,7 @@ use C4::Serials;
 use C4::Letters;
 use C4::Output;
 use C4::Context;
+use Koha::Serial::Items;
 
 use Koha::DateUtils qw( dt_from_string );
 
@@ -110,6 +111,29 @@ if($op eq 'gennext' && @subscriptionid){
     exit;
 }
 
+my $countitems = 0;
+my @serialsid = $query->multi_param('serialid');
+my $subscriptionid = $subscriptionid[0];
+
+if($op eq 'delete_confirm'){
+    foreach my $serialid (@serialsid){
+        $countitems += Koha::Serial::Items->search({serialid => $serialid})->count();
+    }
+}elsif($op eq 'delete_confirmed'){
+    if($query->param('delitems') eq "Yes"){
+        foreach my $serialid (@serialsid){
+            my @itemnumbers = Koha::Serial::Items->search({serialid => $serialid})->get_column('itemnumber');
+            foreach my $itemnumber (@itemnumbers){
+                C4::Items::DelItem({'biblionumber' => $biblionumber, 'itemnumber' => $itemnumber});
+            }
+        }
+    }
+    for my $serialid (@serialsid){
+        ModSerialStatus($serialid,"","","","",6);
+    }
+    print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
+}
+
 my $subscriptioncount;
 my ($location, $callnumber);
 if (@subscriptionid){
@@ -181,6 +205,11 @@ $template->param(
           callnumber          => $callnumber,
           uc(C4::Context->preference("marcflavour")) => 1,
           serialsadditems   => $subscriptiondescs->[0]{'serialsadditems'},
+          delete => ($op eq 'delete_confirm'),
+          subscriptionid => $subscriptionid,
+          countitems => $countitems,
+          serialnumber => scalar @serialsid,
+          serialsid => \@serialsid,
           );
 
 output_html_with_http_headers $query, $cookie, $template->output;