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

(-)a/Koha/Subscription.pm (+42 lines)
Lines 24-29 use Carp; Link Here
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Biblios;
25
use Koha::Biblios;
26
use Koha::Acquisition::Booksellers;
26
use Koha::Acquisition::Booksellers;
27
use Koha::DateUtils;
28
29
use Date::Calc qw( Delta_Days );
27
30
28
use base qw(Koha::Object);
31
use base qw(Koha::Object);
29
32
Lines 152-157 sub lengthtype { Link Here
152
    }
155
    }
153
}
156
}
154
157
158
=head3 update_irregularities
159
160
$subscription->update_irregularities
161
162
=cut
163
164
sub guess_irregularities {
165
    my ($self) = @_;
166
167
    my @irregularities;
168
    my %permanent_irregularities = map { $_ => 1 } $self->permanent_irregularities;
169
170
    my $schema = Koha::Database->new->schema;
171
    my $frequency = $schema->resultset('SubscriptionFrequency')->find($self->periodicity);
172
173
    my $enddate = $self->enddate;
174
    my $nextexpected = C4::Serials::GetNextExpected($self->id);
175
    my $date = $nextexpected->{planneddate};
176
177
    my ($issuenumber) = C4::Serials::GetFictiveIssueNumber($self->unblessed, $date);
178
    my $dow = issue_number( dt_from_string($date), $frequency->unit );
179
180
    if ( defined( $permanent_irregularities{$dow} ) ) {
181
        push @irregularities, $issuenumber;
182
    }
183
184
    while ( Delta_Days( split(/-/, $date), split(/-/, $enddate) ) >= 0 ) {
185
        $issuenumber++;
186
        $date = C4::Serials::GetNextDate($self->unblessed, $date);
187
        $dow = issue_number( dt_from_string($date), $frequency->unit );
188
189
        if ( defined( $permanent_irregularities{$dow} ) ) {
190
            push @irregularities, $issuenumber;
191
        }
192
    }
193
194
    return @irregularities;
195
}
196
155
=head3 type
197
=head3 type
156
198
157
=cut
199
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (-1 / +3 lines)
Lines 84-90 Link Here
84
        var irregularity = "[% subscription.irregularity %]";
84
        var irregularity = "[% subscription.irregularity %]";
85
        var more_than_one_serial = "[% more_than_one_serial %]";
85
        var more_than_one_serial = "[% more_than_one_serial %]";
86
        $(document).ready(function(){
86
        $(document).ready(function(){
87
            testPredictionPattern();
87
            if (subscriptionid) {
88
                testPredictionPattern();
89
            }
88
            $(".close").on("click", function(e){
90
            $(".close").on("click", function(e){
89
                e.preventDefault();
91
                e.preventDefault();
90
                window.opener.location.reload(false);
92
                window.opener.location.reload(false);
(-)a/serials/subscription-renew.pl (+4 lines)
Lines 101-106 if ( $op eq "renew" ) { Link Here
101
            $subscription->{enddate}, $subscription->{numberlength},
101
            $subscription->{enddate}, $subscription->{numberlength},
102
            $subscription->{weeklength}, $subscription->{monthlength},
102
            $subscription->{weeklength}, $subscription->{monthlength},
103
        );
103
        );
104
105
        $subscription = Koha::Subscriptions->find( $subscriptionid );
106
        my @irregularities = $subscription->guess_irregularities;
107
        $subscription->irregularity( join(';', @irregularities) )->store;
104
    }
108
    }
105
} else {
109
} else {
106
    my $subscriptionid = $subscriptionids[0];
110
    my $subscriptionid = $subscriptionids[0];
(-)a/t/db_dependent/Koha/Subscription.t (-1 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 4;
23
use Test::More tests => 2;
24
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
25
24
26
use Koha::Subscriptions;
25
use Koha::Subscriptions;
(-)a/t/db_dependent/Koha/Subscription/Irregularities.t (-1 / +175 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WIT HOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use t::lib::TestBuilder;
22
23
use C4::Serials;
24
25
use Koha::Database;
26
use Koha::Subscriptions;
27
28
BEGIN {
29
    use_ok('Koha::Subscriptions');
30
}
31
32
my $schema  = Koha::Database->new->schema;
33
my $builder = t::lib::TestBuilder->new;
34
35
$schema->storage->txn_begin;
36
37
my $biblio = $builder->build({
38
    source => 'Biblio',
39
});
40
41
my $frequency = $builder->build({
42
    source => 'SubscriptionFrequency',
43
    value => {
44
        unit => 'day',
45
        unitsperissue => 1,
46
        issuesperunit => 1
47
    }
48
});
49
50
my $number_pattern = $builder->build({
51
    source => 'SubscriptionNumberpattern',
52
    value => {
53
        numberingmethod => 'No.{X}',
54
        add1 => 1,
55
        every1 => 1,
56
        whenmorethan1 => 99999,
57
        setto1 => 1
58
    }
59
});
60
61
my $subscription = $builder->build({
62
        source => 'Subscription',
63
        value => {
64
            biblionumber => $biblio->{biblionumber},
65
            startdate => '2018-05-07',
66
            weeklength => 0,
67
            monthlength => 0,
68
            numberlength => 7,
69
            periodicity => $frequency->{id},
70
            countissuesperunit => 1,
71
            status => 1,
72
            lastvalue1 => 5,
73
            lastvalue2 => 0,
74
            innerloop1 => 0,
75
            innerloop2 => 0,
76
            innerloop3 => 0,
77
            lastvalue3 => 0,
78
            firstacquidate => '2018-05-07',
79
            irregularity => '3;4',
80
            permanent_irregularity => '3;4',
81
            numberpattern => 7,
82
            enddate => '2018-05-13',
83
            closed => 0
84
        }
85
});
86
87
$builder->build({
88
    source => 'Serial',
89
    value => {
90
        biblionumber => $biblio->{biblionumber},
91
        subscriptionid => $subscription->{subscriptionid},
92
        serialseq => 'No.1',
93
        serialseq_x => 1,
94
        status => 2,
95
        planneddate => '2018-05-07',
96
        publisheddate => '2018-05-07',
97
    }
98
});
99
100
$builder->build({
101
    source => 'Serial',
102
    value => {
103
        biblionumber => $biblio->{biblionumber},
104
        subscriptionid => $subscription->{subscriptionid},
105
        serialseq => 'No.2',
106
        serialseq_x => 2,
107
        status => 2,
108
        planneddate => '2018-05-08',
109
        publisheddate => '2018-05-08',
110
    }
111
});
112
113
$builder->build({
114
    source => 'Serial',
115
    value => {
116
        biblionumber => $biblio->{biblionumber},
117
        subscriptionid => $subscription->{subscriptionid},
118
        serialseq => 'No.3',
119
        serialseq_x => 3,
120
        status => 2,
121
        planneddate => '2018-05-11',
122
        publisheddate => '2018-05-11',
123
    }
124
});
125
126
$builder->build({
127
    source => 'Serial',
128
    value => {
129
        biblionumber => $biblio->{biblionumber},
130
        subscriptionid => $subscription->{subscriptionid},
131
        serialseq => 'No.4',
132
        serialseq_x => 4,
133
        status => 2,
134
        planneddate => '2018-05-12',
135
        publisheddate => '2018-05-12',
136
    }
137
});
138
139
$builder->build({
140
    source => 'Serial',
141
    value => {
142
        biblionumber => $biblio->{biblionumber},
143
        subscriptionid => $subscription->{subscriptionid},
144
        serialseq => 'No.5',
145
        serialseq_x => 5,
146
        status => 2,
147
        planneddate => '2018-05-13',
148
        publisheddate => '2018-05-13',
149
    }
150
});
151
152
$builder->build({
153
    source => 'Serial',
154
    value => {
155
        biblionumber => $biblio->{biblionumber},
156
        subscriptionid => $subscription->{subscriptionid},
157
        serialseq => 'No.6',
158
        serialseq_x => 6,
159
        status => 1,
160
        planneddate => '2018-05-14',
161
        publisheddate => '2018-05-14',
162
    }
163
});
164
165
ReNewSubscription(
166
    $subscription->{subscriptionid}, undef,
167
    $subscription->{enddate}, $subscription->{numberlength},
168
    $subscription->{weeklength}, $subscription->{monthlength},
169
);
170
171
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
172
my $irregularities = join(';', $s->guess_irregularities);
173
is($irregularities, '10;11', 'Irregularities have been updated');
174
175
$schema->storage->txn_rollback;

Return to bug 17656