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

(-)a/Koha/Subscription.pm (+41 lines)
Lines 28-34 use Koha::Biblioitems; Link Here
28
use Koha::Subscriptions;
28
use Koha::Subscriptions;
29
use Koha::Subscription::Frequencies;
29
use Koha::Subscription::Frequencies;
30
use Koha::Subscription::Numberpatterns;
30
use Koha::Subscription::Numberpatterns;
31
use Koha::DateUtils;
31
use JSON;
32
use JSON;
33
use Date::Calc qw( Delta_Days );
32
34
33
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
35
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
34
36
Lines 243-248 sub lengthtype { Link Here
243
    }
245
    }
244
}
246
}
245
247
248
=head3 update_irregularities
249
250
$subscription->update_irregularities
251
252
=cut
253
254
sub guess_irregularities {
255
    my ($self) = @_;
256
257
    my @irregularities;
258
    my %permanent_irregularities = map { $_ => 1 } $self->permanent_irregularities;
259
260
    my $schema = Koha::Database->new->schema;
261
    my $frequency = $schema->resultset('SubscriptionFrequency')->find($self->periodicity);
262
263
    my $enddate = $self->enddate;
264
    my $nextexpected = C4::Serials::GetNextExpected($self->id);
265
    my $date = $nextexpected->{planneddate};
266
267
    my ($issuenumber) = C4::Serials::GetFictiveIssueNumber($self->unblessed, $date);
268
    my $dow = issue_number( dt_from_string($date), $frequency->unit );
269
270
    if ( defined( $permanent_irregularities{$dow} ) ) {
271
        push @irregularities, $issuenumber;
272
    }
273
274
    while ( Delta_Days( split(/-/, $date), split(/-/, $enddate) ) >= 0 ) {
275
        $issuenumber++;
276
        $date = C4::Serials::GetNextDate($self->unblessed, $date);
277
        $dow = issue_number( dt_from_string($date), $frequency->unit );
278
279
        if ( defined( $permanent_irregularities{$dow} ) ) {
280
            push @irregularities, $issuenumber;
281
        }
282
    }
283
284
    return @irregularities;
285
}
286
246
=head3 type
287
=head3 type
247
288
248
=cut
289
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (-1 / +3 lines)
Lines 117-123 Link Here
117
        var irregularity = "[% subscription.irregularity %]";
117
        var irregularity = "[% subscription.irregularity %]";
118
        var more_than_one_serial = "[% more_than_one_serial %]";
118
        var more_than_one_serial = "[% more_than_one_serial %]";
119
        $(document).ready(function(){
119
        $(document).ready(function(){
120
            testPredictionPattern();
120
            if (subscriptionid) {
121
                testPredictionPattern();
122
            }
121
            $(".close").on("click", function(e){
123
            $(".close").on("click", function(e){
122
                e.preventDefault();
124
                e.preventDefault();
123
                window.opener.location.reload(false);
125
                window.opener.location.reload(false);
(-)a/serials/subscription-renew.pl (+4 lines)
Lines 122-127 if ( $op eq "renew" ) { Link Here
122
                monthlength    => $subscription->{monthlength},
122
                monthlength    => $subscription->{monthlength},
123
            }
123
            }
124
        );
124
        );
125
126
        $subscription = Koha::Subscriptions->find( $subscriptionid );
127
        my @irregularities = $subscription->guess_irregularities;
128
        $subscription->irregularity( join(';', @irregularities) )->store;
125
    }
129
    }
126
} else {
130
} else {
127
    my $subscriptionid = $subscriptionids[0];
131
    my $subscriptionid = $subscriptionids[0];
(-)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