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

(-)a/C4/Serials.pm (-4 / +8 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
      &getsublength &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-1498 sub NewSubscription { Link Here
1483
    return $subscriptionid;
1484
    return $subscriptionid;
1484
}
1485
}
1485
1486
1486
=head2 getsublength
1487
=head2 GetSubscriptionLength
1487
1488
1488
my ($numberlength, $weeklength, $monthlength) = getsublength( $subtype, $sublength );
1489
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
1489
1490
1490
This function calculates the subscription length.
1491
This function calculates the subscription length.
1491
1492
1492
=cut
1493
=cut
1493
1494
1494
sub getsublength {
1495
sub GetSubscriptionLength {
1495
    my ($subtype, $length) = @_;
1496
    my ($subtype, $length) = @_;
1497
1498
    return unless looks_like_number($length);
1499
1496
    return
1500
    return
1497
    (
1501
    (
1498
          $subtype eq 'issues' ? $length : 0,
1502
          $subtype eq 'issues' ? $length : 0,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (-1 / +2 lines)
Lines 66-73 Link Here
66
            </option>
66
            </option>
67
        [% END %]
67
        [% END %]
68
    </select>
68
    </select>
69
    <input type="text" name="sublength" id="sublength" value="[% sublength | html %]" size="3" />(enter amount in numerals)
69
    <input type="text" name="sublength" id="sublength" size="3" />(enter amount in numerals)
70
    <input type="hidden" name="issuelengthcount">
70
    <input type="hidden" name="issuelengthcount">
71
    </fieldset>
71
    </li>
72
    </li>
72
73
73
    <li><label for="branchcode">Library:</label>
74
    <li><label for="branchcode">Library:</label>
(-)a/serials/subscription-add.pl (-1 / +1 lines)
Lines 433-439 sub redirect_mod_subscription { Link Here
433
433
434
    my $subtype = $query->param('subtype');
434
    my $subtype = $query->param('subtype');
435
    my $sublength = $query->param('sublength');
435
    my $sublength = $query->param('sublength');
436
    my ($numberlength, $weeklength, $monthlength) = C4::Serials->getsublength( $subtype, $sublength );
436
    my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
437
    my $numberpattern = $query->param('numbering_pattern');
437
    my $numberpattern = $query->param('numbering_pattern');
438
    my $locale = $query->param('locale');
438
    my $locale = $query->param('locale');
439
    my $lastvalue1 = $query->param('lastvalue1');
439
    my $lastvalue1 = $query->param('lastvalue1');
(-)a/serials/subscription-renew.pl (-4 / +5 lines)
Lines 64-70 my @subscriptionids = $query->multi_param('subscriptionid'); Link Here
64
my $branchcode     = $query->param('branchcode');
64
my $branchcode     = $query->param('branchcode');
65
my $sublength = $query->param('sublength');
65
my $sublength = $query->param('sublength');
66
my $subtype = $query->param('subtype');
66
my $subtype = $query->param('subtype');
67
my ($numberlength, $weeklength, $monthlength) = C4::Serials->getsublength( $subtype, $sublength );
67
my ($numberlength, $weeklength, $monthlength);
68
68
69
my $done = 0;    # for after form has been submitted
69
my $done = 0;    # for after form has been submitted
70
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
70
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 84-97 if ( $op eq "renew" ) { Link Here
84
    my $subscription = GetSubscription( $subscriptionid );
84
    my $subscription = GetSubscription( $subscriptionid );
85
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
85
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
86
    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 );
87
    ReNewSubscription(
88
    ReNewSubscription(
88
        {
89
        {
89
            subscriptionid => $subscriptionid,
90
            subscriptionid => $subscriptionid,
90
            user           => $loggedinuser,
91
            user           => $loggedinuser,
91
            startdate      => $startdate,
92
            startdate      => $startdate,
92
            numberlength   => scalar $query->param('numberlength'),
93
            numberlength   => $numberlength,
93
            weeklength     => scalar $query->param('weeklength'),
94
            weeklength     => $weeklength,
94
            monthlength    => scalar $query->param('monthlength'),
95
            monthlength    => $monthlength,
95
            note           => scalar $query->param('note'),
96
            note           => scalar $query->param('note'),
96
            branchcode     => $branchcode
97
            branchcode     => $branchcode
97
        }
98
        }
(-)a/t/db_dependent/Serials/ReNewSubscription.t (-9 / +19 lines)
Lines 22-28 Link Here
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
24
25
use Test::More tests => 4;
25
use Test::More tests => 7;
26
use Test::MockModule;
26
use Test::MockModule;
27
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
28
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 96-113 ReNewSubscription( Link Here
96
);
96
);
97
97
98
# Calculate the subscription length for the renewal for issues, days and months
98
# Calculate the subscription length for the renewal for issues, days and months
99
my ($numberlength, $weeklength, $monthlength) = getsublength('issues', 7);
99
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('issues', 7);
100
is ( $numberlength, 7, "Sub length is 7 issues");
100
is ( $numberlength, 7, "Subscription length is 7 issues");
101
101
102
($numberlength, $weeklength, $monthlength) = getsublength('weeks', 7);
102
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('weeks', 7);
103
is ( $weeklength, 7, "Sub length is 7 weeks");
103
is ( $weeklength, 7, "Subscription length is 7 weeks");
104
104
105
($numberlength, $weeklength, $monthlength) = getsublength('months', 7);
105
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('months', 7);
106
is ( $monthlength, 7, "Sub length is 7 months");
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");
107
119
108
# Renew the subscription and check that enddate has not been set
120
# Renew the subscription and check that enddate has not been set
109
121
110
ReNewSubscription($subscription->{subscriptionid},'',"2016-01-01",'','',12,'');
111
my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
122
my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
112
123
113
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
124
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
114
- 

Return to bug 7046