View | Details | Raw Unified | Return to bug 7046
Collapse All | Expand All

(-)a/C4/Serials.pm (-1 / +24 lines)
Lines 36-41 use Koha::Serial; Link Here
36
use Koha::Subscriptions;
36
use Koha::Subscriptions;
37
use Koha::Subscription::Histories;
37
use Koha::Subscription::Histories;
38
use Koha::SharedContent;
38
use Koha::SharedContent;
39
use Scalar::Util qw( looks_like_number );
39
40
40
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
41
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
41
42
Lines 74-80 BEGIN { Link Here
74
75
75
      &GetNextSeq &GetSeq &NewIssue           &GetSerials
76
      &GetNextSeq &GetSeq &NewIssue           &GetSerials
76
      &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
77
      &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
77
      &ReNewSubscription  &GetLateOrMissingIssues
78
      &GetSubscriptionLength &ReNewSubscription  &GetLateOrMissingIssues
78
      &GetSerialInformation                   &AddItem2Serial
79
      &GetSerialInformation                   &AddItem2Serial
79
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
80
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
80
      &GetPreviousSerialid
81
      &GetPreviousSerialid
Lines 1483-1488 sub NewSubscription { Link Here
1483
    return $subscriptionid;
1484
    return $subscriptionid;
1484
}
1485
}
1485
1486
1487
=head2 GetSubscriptionLength
1488
1489
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
1490
1491
This function calculates the subscription length.
1492
1493
=cut
1494
1495
sub GetSubscriptionLength {
1496
    my ($subtype, $length) = @_;
1497
1498
    return unless looks_like_number($length);
1499
1500
    return
1501
    (
1502
          $subtype eq 'issues' ? $length : 0,
1503
          $subtype eq 'weeks'  ? $length : 0,
1504
          $subtype eq 'months' ? $length : 0,
1505
    );
1506
}
1507
1508
1486
=head2 ReNewSubscription
1509
=head2 ReNewSubscription
1487
1510
1488
ReNewSubscription($params);
1511
ReNewSubscription($params);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (-17 / +46 lines)
Lines 35-60 Link Here
35
                <input type="text" size="10" id="startdate" name="startdate" value="[% startdate | html %]" class="datepicker"/>
35
                <input type="text" size="10" id="startdate" name="startdate" value="[% startdate | html %]" class="datepicker"/>
36
                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
36
                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
37
            </li>
37
            </li>
38
		<li><fieldset>
38
    <li>
39
		<legend>Subscription length:</legend>
39
    <label>Subscription length:</label>
40
		<ol><li><label for="numberlength">Number of num:</label><input type="text" id="numberlength" name="numberlength" value="[% subscription.numberlength | html %]" /></li>
40
    <select name="subtype" id="subtype">
41
		<li><label for="weeklength">Number of weeks: </label><input type="text" id="weeklength" name="weeklength" value="[% subscription.weeklength | html %]" /></li>
41
        [% FOREACH st IN subtypes %]
42
		<li><label for="monthlength">Number of months: </label><input type="text" id="monthlength" name="monthlength" value="[% subscription.monthlength | html %]" /></li></ol></fieldset></li>
42
            [% SWITCH st %]
43
                [% CASE 'numberlength'%]
44
                    [% IF st == subtype %]
45
                        <option value="issues" selected="selected">
46
                    [% ELSE %]
47
                        <option value="issues">
48
                    [% END %]
49
                    issues
50
                [% CASE 'weeklength' %]
51
                    [% IF st == subtype %]
52
                        <option value="weeks" selected="selected">
53
                    [% ELSE %]
54
                        <option value="weeks">
55
                    [% END %]
56
                    weeks
57
                [% CASE 'monthlength' %]
58
                    [% IF st == subtype %]
59
                        <option value="months" selected="selected">
60
                    [% ELSE %]
61
                        <option value="months">
62
                    [% END %]
63
                    months
64
                [% CASE %][% st | html %]
65
            [% END %]
66
            </option>
67
        [% END %]
68
    </select>
69
    <input type="text" name="sublength" id="sublength" size="3" />(enter amount in numerals)
70
    <input type="hidden" name="issuelengthcount">
71
    </li>
43
72
44
<li><label for="branchcode">Library:</label>
73
    <li><label for="branchcode">Library:</label>
45
 <select name="branchcode" id="branchcode" style="width: 20em;">
74
    <select name="branchcode" id="branchcode" style="width: 20em;">
46
     [% UNLESS ( Independentbranches ) %]
75
        [% UNLESS ( Independentbranches ) %]
47
        <option value="">None</option>
76
            <option value="">None</option>
48
     [% END %]
77
        [% END %]
49
     [% IF CAN_user_serials_superserials %]
78
        [% IF CAN_user_serials_superserials %]
50
        [% FOREACH library IN libraries %]
79
            [% FOREACH library IN libraries %]
51
             <option value="[% library.branchcode | html %]"> [% library.branchname | html %] </option>
80
                <option value="[% library.branchcode | html %]"> [% library.branchname | html %] </option>
81
            [% END %]
52
        [% END %]
82
        [% END %]
53
     [% END %]
83
    </select> (select a library)
54
</select> (select a library)
84
    </li>
55
</li>
56
85
57
		<li><label for="note">Note for the librarian that will manage your renewal request: </label>
86
    <li><label for="note">Note for the librarian that will manage your renewal request: </label>
58
		<textarea name="note" id="note" rows="5" cols="50"></textarea></li></ol></fieldset>
87
		<textarea name="note" id="note" rows="5" cols="50"></textarea></li></ol></fieldset>
59
		<fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
88
		<fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
60
</form>
89
</form>
(-)a/serials/subscription-add.pl (-13 / +3 lines)
Lines 265-280 sub get_letter_loop { Link Here
265
    ];
265
    ];
266
}
266
}
267
267
268
sub _get_sub_length {
269
    my ($type, $length) = @_;
270
    return
271
        (
272
            $type eq 'issues' ? $length : 0,
273
            $type eq 'weeks'   ? $length : 0,
274
            $type eq 'months'  ? $length : 0,
275
        );
276
}
277
278
sub _guess_enddate {
268
sub _guess_enddate {
279
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
269
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
280
    my ($year, $month, $day);
270
    my ($year, $month, $day);
Lines 330-336 sub redirect_add_subscription { Link Here
330
    my $subtype = $query->param('subtype');
320
    my $subtype = $query->param('subtype');
331
    my $sublength = $query->param('sublength');
321
    my $sublength = $query->param('sublength');
332
    my ( $numberlength, $weeklength, $monthlength )
322
    my ( $numberlength, $weeklength, $monthlength )
333
        = _get_sub_length( $subtype, $sublength );
323
        = GetSubscriptionLength( $subtype, $sublength );
334
    my $add1              = $query->param('add1');
324
    my $add1              = $query->param('add1');
335
    my $lastvalue1        = $query->param('lastvalue1');
325
    my $lastvalue1        = $query->param('lastvalue1');
336
    my $innerloop1        = $query->param('innerloop1');
326
    my $innerloop1        = $query->param('innerloop1');
Lines 443-450 sub redirect_mod_subscription { Link Here
443
433
444
    my $subtype = $query->param('subtype');
434
    my $subtype = $query->param('subtype');
445
    my $sublength = $query->param('sublength');
435
    my $sublength = $query->param('sublength');
446
    my ($numberlength, $weeklength, $monthlength)
436
    my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
447
        = _get_sub_length( $subtype, $sublength );
437
    my $numberpattern = $query->param('numbering_pattern');
448
    my $locale = $query->param('locale');
438
    my $locale = $query->param('locale');
449
    my $lastvalue1 = $query->param('lastvalue1');
439
    my $lastvalue1 = $query->param('lastvalue1');
450
    my $innerloop1 = $query->param('innerloop1');
440
    my $innerloop1 = $query->param('innerloop1');
(-)a/serials/subscription-renew.pl (-3 / +9 lines)
Lines 62-67 my $mode = $query->param('mode') || q{}; Link Here
62
my $op             = $query->param('op') || 'display';
62
my $op             = $query->param('op') || 'display';
63
my @subscriptionids = $query->multi_param('subscriptionid');
63
my @subscriptionids = $query->multi_param('subscriptionid');
64
my $branchcode     = $query->param('branchcode');
64
my $branchcode     = $query->param('branchcode');
65
my $sublength = $query->param('sublength');
66
my $subtype = $query->param('subtype');
67
my ($numberlength, $weeklength, $monthlength);
68
65
my $done = 0;    # for after form has been submitted
69
my $done = 0;    # for after form has been submitted
66
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
70
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
67
    {
71
    {
Lines 80-93 if ( $op eq "renew" ) { Link Here
80
    my $subscription = GetSubscription( $subscriptionid );
84
    my $subscription = GetSubscription( $subscriptionid );
81
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
85
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
82
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
86
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
87
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
83
    ReNewSubscription(
88
    ReNewSubscription(
84
        {
89
        {
85
            subscriptionid => $subscriptionid,
90
            subscriptionid => $subscriptionid,
86
            user           => $loggedinuser,
91
            user           => $loggedinuser,
87
            startdate      => $startdate,
92
            startdate      => $startdate,
88
            numberlength   => scalar $query->param('numberlength'),
93
            numberlength   => $numberlength,
89
            weeklength     => scalar $query->param('weeklength'),
94
            weeklength     => $weeklength,
90
            monthlength    => scalar $query->param('monthlength'),
95
            monthlength    => $monthlength,
91
            note           => scalar $query->param('note'),
96
            note           => scalar $query->param('note'),
92
            branchcode     => $branchcode
97
            branchcode     => $branchcode
93
        }
98
        }
Lines 130-135 my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); Link Here
130
$template->param(
135
$template->param(
131
    op => $op,
136
    op => $op,
132
    libraries      => $libraries,
137
    libraries      => $libraries,
138
    subtypes => [ qw( numberlength weeklength monthlength ) ],
133
);
139
);
134
140
135
output_html_with_http_headers $query, $cookie, $template->output;
141
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Serials/ReNewSubscription.t (-2 / +27 lines)
Lines 3-8 Link Here
3
# This script includes tests for ReNewSubscription
3
# This script includes tests for ReNewSubscription
4
4
5
# Copyright 2015 BibLibre, Paul Poulain
5
# Copyright 2015 BibLibre, Paul Poulain
6
# Copyright 2018 Catalyst IT, Alex Buckley
6
#
7
#
7
# This file is part of Koha.
8
# This file is part of Koha.
8
#
9
#
Lines 21-27 Link Here
21
22
22
use Modern::Perl;
23
use Modern::Perl;
23
24
24
use Test::More tests => 1;
25
use Test::More tests => 7;
25
use Test::MockModule;
26
use Test::MockModule;
26
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 93-98 ReNewSubscription( Link Here
93
        monthlength    => 12
94
        monthlength    => 12
94
    }
95
    }
95
);
96
);
97
98
# Calculate the subscription length for the renewal for issues, days and months
99
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('issues', 7);
100
is ( $numberlength, 7, "Subscription length is 7 issues");
101
102
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('weeks', 7);
103
is ( $weeklength, 7, "Subscription length is 7 weeks");
104
105
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('months', 7);
106
is ( $monthlength, 7, "Subscription length is 7 months");
107
108
# Check subscription length when no value is inputted into the numeric sublength field
109
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('months', '');
110
is ($monthlength, undef, "Subscription length is undef months, invalid month data was not stored");
111
112
# Check subscription length when a letter is inputted into the numeric sublength field
113
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('issues', 'w');
114
is ($monthlength, undef, "Subscription length is undef issues, invalid issue data was not stored");
115
116
# Check subscription length when a special character is inputted into numberic sublength field
117
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('weeks', '!');
118
is ($weeklength, undef, "Subscription length is undef weeks, invalid weeks data was not stored");
119
120
# Renew the subscription and check that enddate has not been set
121
96
my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
122
my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
97
123
98
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
124
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
99
- 

Return to bug 7046