From 12e6e7fe3861f2464fa6ef003edef9771fcca096 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Apr 2018 14:01:18 -0300 Subject: [PATCH] Bug 7910: Add the ability to renew several subscriptions at once This patch adds a "Renew all selected subscriptions" action link on top of the table of the "Check expiration" page. It will allow to auto-renew several subscriptions. Test plan: Make sure this new link renew the selected subscriptions as expected. --- .../prog/en/modules/serials/checkexpiration.tt | 52 ++++++++++++++++++++++ .../prog/en/modules/serials/subscription-renew.tt | 21 +++++---- serials/subscription-renew.pl | 52 +++++++++++++--------- 3 files changed, 96 insertions(+), 29 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tt index 24a977c24b..d2bf124cc9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tt @@ -61,8 +61,20 @@ [% END %] will expire before [% date | $KohaDates %]

+ +
+ Select all | + Clear all + + | Actions: + Renew selected subscriptions + +
+ + + [% IF can_change_library %][% END %] @@ -73,6 +85,9 @@ [% FOREACH subscriptions_loo IN subscriptions_loop %] + @@ -123,6 +138,43 @@ var subscriptionid = $(this).data("subscriptionid"); popup( subscriptionid ); }); + function itemSelectionBuildRenewLink() { + var subscription_ids= new Array(); + $("input[name='subscriptionid'][type='checkbox']:checked").each(function() { + subscription_ids.push($(this).val()); + }); + if (subscription_ids.length > 0) { + var url = '/cgi-bin/koha/serials/subscription-renew.pl?op=multi_renew'; + url += '&subscriptionid=' + subscription_ids.join('&subscriptionid='); + $('a.itemselection_action_renew').attr('href', url); + } else { + return false; + } + return true; + } + + function itemSelectionBuildActionLinks() { + var export_link_ok = itemSelectionBuildRenewLink(); + if (export_link_ok) { + $('.itemselection_actions').show(); + } else { + $('.itemselection_actions').hide(); + } + } + + itemSelectionBuildActionLinks(); + + $("input[name='subscriptionid'][type='checkbox']").change(function() { + itemSelectionBuildActionLinks(); + }); + + $(".SelectAll, .ClearAll").on("click",function(e){ + e.preventDefault(); + var checkboxes = $(this).parent().siblings('table').first().find('input[type="checkbox"]'); + checkboxes.prop('checked', $(this).hasClass('SelectAll')); + itemSelectionBuildActionLinks(); + }); + }); function popup(subscriptionid) { newin=window.open("subscription-renew.pl?mode=popup&subscriptionid="+subscriptionid,'popup','width=590,height=440,toolbar=false,scrollbars=yes,resize=yes'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt index 6f854e7f0b..3639e57961 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt @@ -1,18 +1,23 @@ [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] -Koha › Serials subscription renew #[% subscriptionid %] +[% IF subscription %] +Koha › Serials subscription renew #[% subscription.subscriptionid %] +[% ELSE %] +Koha › Serials subscription renew +[% END %] [% INCLUDE 'doc-head-close.inc' %]
-[% IF ( renew ) %] +[% IF op == 'renew' %] Subscription renewed. @@ -20,8 +25,8 @@
- -
Subscription renewal for [% bibliotitle %] + +
Subscription renewal for [% subscription.bibliotitle %]
  1. @@ -30,9 +35,9 @@
  2. Subscription length: -
    1. -
    2. -
  3. +
    1. +
    2. +
  • diff --git a/serials/subscription-renew.pl b/serials/subscription-renew.pl index 06b03e2d35..836e612344 100755 --- a/serials/subscription-renew.pl +++ b/serials/subscription-renew.pl @@ -60,7 +60,7 @@ my $dbh = C4::Context->dbh; my $mode = $query->param('mode') || q{}; my $op = $query->param('op') || 'display'; -my $subscriptionid = $query->param('subscriptionid'); +my @subscriptionids = $query->multi_param('subscriptionid'); my $done = 0; # for after form has been submitted my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -73,34 +73,44 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); if ( $op eq "renew" ) { + # Do not use this script with op=renew and @subscriptionids > 1! + my $subscriptionid = $subscriptionids[0]; my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } ); ReNewSubscription( $subscriptionid, $loggedinuser, - $startdate, $query->param('numberlength'), - $query->param('weeklength'), $query->param('monthlength'), - $query->param('note') + $startdate, scalar $query->param('numberlength'), + scalar $query->param('weeklength'), scalar $query->param('monthlength'), + scalar $query->param('note') ); -} +} elsif ( $op eq 'multi_renew' ) { + for my $subscriptionid ( @subscriptionids ) { + my $subscription = GetSubscription( $subscriptionid ); + next unless $subscription; + ReNewSubscription( + $subscriptionid, $loggedinuser, + $subscription->{enddate}, $subscription->{numberlength}, + $subscription->{weeklength}, $subscription->{monthlength}, + ); + } +} else { + my $subscriptionid = $subscriptionids[0]; + my $subscription = GetSubscription($subscriptionid); + if ($subscription->{'cannotedit'}){ + carp "Attempt to renew subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; + print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); + } -my $subscription = GetSubscription($subscriptionid); -if ($subscription->{'cannotedit'}){ - carp "Attempt to renew subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; - print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); -} + my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } ) + or output_pref( { dt => dt_from_string, dateonly => 1 } ); -my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } ) - or output_pref( { dt => dt_from_string, dateonly => 1 } ); + $template->param( + startdate => $newstartdate, + subscription => $subscription, + ); +} $template->param( - startdate => $newstartdate, - numberlength => $subscription->{numberlength}, - weeklength => $subscription->{weeklength}, - monthlength => $subscription->{monthlength}, - subscriptionid => $subscriptionid, - bibliotitle => $subscription->{bibliotitle}, - $op => 1, - popup => ($mode eq 'popup'), + op => $op, ); -# Print the page output_html_with_http_headers $query, $cookie, $template->output; -- 2.11.0
    ISSN TitleLibrary
    + + [% subscriptions_loo.issn %]