From 6cb8c9e4e97b0800d46ba2f5a32a3b898cf2d73a Mon Sep 17 00:00:00 2001 From: Pierre-Marc Thibault Date: Wed, 10 Oct 2018 11:25:59 -0400 Subject: [PATCH] Bug 17674: Allow UI to delete serials in batch 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 Signed-off-by: Sonia Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- .../en/modules/serials/serials-collection.tt | 52 ++++++++++++++++++- serials/serials-collection.pl | 29 +++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt index 7d4310d406..b7e02f4638 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt @@ -30,6 +30,31 @@ [% IF ( callnumber ) %]callnumber: [% callnumber | html %][% END %] [% END %] +[% IF ( delete ) %] +
+

You are about to delete [% serialnumber | html %] serial(s). Do you want to continue?

+
+ [% IF countitems > 0 %] +
Number of items available: [% countitems | html %]
+

+ +

+ [% END %] + + + + [% FOREACH serialid IN serialsid %] + + [% END %] + +
+
+ + +
+
+[% END %] + [% IF ( subscriptions ) %] [% IF ( subscriptions.size == 1 ) %] @@ -119,6 +144,7 @@
[% END %] [% END %] +

[% END %] @@ -162,8 +188,12 @@ [% IF ( serial.subscriptionexpired ) %] [% ELSE %] - [% IF ( serial.checked ) %] - + [% IF ( delete ) %] + [% IF serialsid.grep("${serial.serialid}").size %] + + [% ELSE %] + + [% END %] [% ELSE %] [% END %] @@ -280,6 +310,19 @@ diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index d9ab11a61e..0977e979a0 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -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; -- 2.39.5