From a9d034a90517f36f0b62e9c0e9425973ef319419 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 27 Nov 2017 15:31:35 +1300 Subject: [PATCH] Bug 7046: Implemented subscription renewal dropdown sub length element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make this work I moved the _get_sub_length function from subscription-add.pl to C4/Serials.pm so that the subscription-renew.pl script could also call it to store the sublength for the appropriate field of the subscriptions database table. Test plan: 1. Create a subscription and notice that there is a dropdown box for sub length containing the values: issues, weeks, months 2. Renew the subscription and notice that there are 3 input text boxes: 'number of num', 'number of weeks' and 'number of months' 3. Input a 'Number of weeks' value of 2 4. Query the subscription database table and notice that the value of 2 has been stored in the weeklength field for the subscription record you just renewed 5. Apply the patch 6. Renew the subscription and notice that there is now a sublength dropdown box containing issues, weeks and months 7. Set the month value to 3 8. Query the database and notice that 3 was stored in the monthlength field for the subscription record 9. Create a new subscription and select the sub length values of issues and 3 10. Query the database and notice that the numberlength field for the subscription you just created is set to 3 showing that the sublength dropbox is still working for creating a new subscription Sponsored-By: Catalyst IT Patch applies and functions as expected in line with test plan. Signed-off-by: Dilan Johnpullé --- C4/Serials.pm | 18 +++++++++++ .../prog/en/modules/serials/subscription-renew.tt | 35 ++++++++++++++++++++-- serials/subscription-add.pl | 14 ++------- serials/subscription-renew.pl | 10 +++++-- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 91498ee..07423b2 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1453,6 +1453,24 @@ sub NewSubscription { return $subscriptionid; } +=head2 _get_sub_length +my ($numberlength, $weeklength, $monthlength) = _get_sub_length( $subtype, $sublength ); + +this function calculates the subscription length. + +=cut + +sub _get_sub_length { + my ($type, $subtype, $length) = @_; + return + ( + $subtype eq 'issues' ? $length : 0, + $subtype eq 'weeks' ? $length : 0, + $subtype eq 'months' ? $length : 0, + ); +} + + =head2 ReNewSubscription ReNewSubscription($subscriptionid,$user,$startdate,$numberlength,$weeklength,$monthlength,$note) 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 fcfbd26..2de316a 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 @@ -37,9 +37,38 @@
  • Subscription length: -
    1. -
    2. -
  • + + (enter amount in numerals) + +
  • diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index fb7e797..9a6e608 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -250,16 +250,6 @@ sub get_letter_loop { ]; } -sub _get_sub_length { - my ($type, $length) = @_; - return - ( - $type eq 'issues' ? $length : 0, - $type eq 'weeks' ? $length : 0, - $type eq 'months' ? $length : 0, - ); -} - sub _guess_enddate { my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_; my ($year, $month, $day); @@ -303,7 +293,7 @@ sub redirect_add_subscription { my $subtype = $query->param('subtype'); my $sublength = $query->param('sublength'); my ( $numberlength, $weeklength, $monthlength ) - = _get_sub_length( $subtype, $sublength ); + = C4::Serials->_get_sub_length( $subtype, $sublength ); my $add1 = $query->param('add1'); my $lastvalue1 = $query->param('lastvalue1'); my $innerloop1 = $query->param('innerloop1'); @@ -381,7 +371,7 @@ sub redirect_mod_subscription { my $subtype = $query->param('subtype'); my $sublength = $query->param('sublength'); my ($numberlength, $weeklength, $monthlength) - = _get_sub_length( $subtype, $sublength ); + = C4::Serials->_get_sub_length( $subtype, $sublength ); my $numberpattern = $query->param('numbering_pattern'); my $locale = $query->param('locale'); my $lastvalue1 = $query->param('lastvalue1'); diff --git a/serials/subscription-renew.pl b/serials/subscription-renew.pl index ccfbad2..a6b4d56 100755 --- a/serials/subscription-renew.pl +++ b/serials/subscription-renew.pl @@ -61,6 +61,10 @@ my $dbh = C4::Context->dbh; my $mode = $query->param('mode') || q{}; my $op = $query->param('op') || 'display'; my @subscriptionids = $query->multi_param('subscriptionid'); +my $sublength = $query->param('sublength'); +my $subtype = $query->param('subtype'); +my ($numberlength, $weeklength, $monthlength) = C4::Serials->_get_sub_length( $subtype, $sublength ); + my $done = 0; # for after form has been submitted my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -81,9 +85,9 @@ if ( $op eq "renew" ) { my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } ); ReNewSubscription( $subscriptionid, $loggedinuser, - $startdate, scalar $query->param('numberlength'), - scalar $query->param('weeklength'), scalar $query->param('monthlength'), - scalar $query->param('note') + $startdate, $numberlength, + $weeklength, $monthlength, + $query->param('note') ); } elsif ( $op eq 'multi_renew' ) { for my $subscriptionid ( @subscriptionids ) { -- 2.1.4