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

(-)a/C4/Serials.pm (-44 / +45 lines)
Lines 51-56 BEGIN { Link Here
51
        HasItems
51
        HasItems
52
52
53
        findSerialsByStatus
53
        findSerialsByStatus
54
        &subscriptionCurrentlyOnOrder
55
        &issue_number
54
56
55
    );
57
    );
56
}
58
}
Lines 1307-1343 sub ModNextExpected { Link Here
1307
1309
1308
}
1310
}
1309
1311
1310
=head2 GetSubscriptionIrregularities
1311
1312
=over 4
1313
1314
=item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1315
get the list of irregularities for a subscription
1316
1317
=back
1318
1319
=cut
1320
1321
sub GetSubscriptionIrregularities {
1322
    my $subscriptionid = shift;
1323
1324
    return unless $subscriptionid;
1325
1326
    my $dbh   = C4::Context->dbh;
1327
    my $query = qq{
1328
        SELECT irregularity
1329
        FROM subscription
1330
        WHERE subscriptionid = ?
1331
    };
1332
    my $sth = $dbh->prepare($query);
1333
    $sth->execute($subscriptionid);
1334
1335
    my ($result) = $sth->fetchrow_array;
1336
    my @irreg    = split /;/, $result;
1337
1338
    return @irreg;
1339
}
1340
1341
=head2 ModSubscription
1312
=head2 ModSubscription
1342
1313
1343
this function modifies a subscription. Put all new values on input args.
1314
this function modifies a subscription. Put all new values on input args.
Lines 1347-1357 returns the number of rows affected Link Here
1347
1318
1348
sub ModSubscription {
1319
sub ModSubscription {
1349
    my (
1320
    my (
1350
        $auser,         $branchcode,      $aqbooksellerid,    $cost,          $aqbudgetid, $startdate,
1321
        $auser,         $branchcode,      $aqbooksellerid,    $cost,                   $aqbudgetid,    $startdate,
1351
        $periodicity,   $firstacquidate,  $irregularity,      $numberpattern, $locale,
1322
        $periodicity,   $firstacquidate,  $irregularity,      $permanent_irregularity, $numberpattern, $locale,
1352
        $numberlength,  $weeklength,      $monthlength,       $lastvalue1,    $innerloop1,
1323
        $numberlength,  $weeklength,      $monthlength,       $lastvalue1,             $innerloop1,
1353
        $lastvalue2,    $innerloop2,      $lastvalue3,        $innerloop3,    $status,
1324
        $lastvalue2,    $innerloop2,      $lastvalue3,        $innerloop3,             $status,
1354
        $biblionumber,  $callnumber,      $notes,             $letter,        $manualhistory,
1325
        $biblionumber,  $callnumber,      $notes,             $letter,                 $manualhistory,
1355
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1326
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1356
        $graceperiod,   $location,        $enddate,           $subscriptionid, $skip_serialseq,
1327
        $graceperiod,   $location,        $enddate,           $subscriptionid, $skip_serialseq,
1357
        $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, $preselect_issues_in_collections_table
1328
        $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, $preselect_issues_in_collections_table
Lines 1382-1387 sub ModSubscription { Link Here
1382
            letter                                => $letter,
1353
            letter                                => $letter,
1383
            firstacquidate                        => $firstacquidate,
1354
            firstacquidate                        => $firstacquidate,
1384
            irregularity                          => $irregularity,
1355
            irregularity                          => $irregularity,
1356
            permanent_irregularity                => $permanent_irregularity,
1385
            numberpattern                         => $numberpattern,
1357
            numberpattern                         => $numberpattern,
1386
            locale                                => $locale,
1358
            locale                                => $locale,
1387
            callnumber                            => $callnumber,
1359
            callnumber                            => $callnumber,
Lines 1432-1445 the id of this new subscription Link Here
1432
1404
1433
sub NewSubscription {
1405
sub NewSubscription {
1434
    my (
1406
    my (
1435
        $auser,                 $branchcode,        $aqbooksellerid,   $cost,          $aqbudgetid, $biblionumber,
1407
        $auser,                  $branchcode,        $aqbooksellerid,   $cost,       $aqbudgetid, $biblionumber,
1436
        $startdate,             $periodicity,       $numberlength,     $weeklength,    $monthlength,
1408
        $startdate,              $periodicity,       $numberlength,     $weeklength, $monthlength,
1437
        $lastvalue1,            $innerloop1,        $lastvalue2,       $innerloop2,    $lastvalue3,
1409
        $lastvalue1,             $innerloop1,        $lastvalue2,       $innerloop2, $lastvalue3,
1438
        $innerloop3,            $status,            $notes,            $letter,        $firstacquidate, $irregularity,
1410
        $innerloop3,             $status,            $notes,            $letter,     $firstacquidate, $irregularity,
1439
        $numberpattern,         $locale,            $callnumber,       $manualhistory, $internalnotes,
1411
        $permanent_irregularity, $numberpattern,     $locale,           $callnumber, $manualhistory,  $internalnotes,
1440
        $serialsadditems,       $staffdisplaycount, $opacdisplaycount, $graceperiod,
1412
        $serialsadditems,        $staffdisplaycount, $opacdisplaycount, $graceperiod,
1441
        $location,              $enddate,           $skip_serialseq,   $itemtype, $previousitemtype, $mana_id, $ccode,
1413
        $location,               $enddate,           $skip_serialseq,   $itemtype, $previousitemtype, $mana_id, $ccode,
1442
        $published_on_template, $preselect_issues_in_collections_table
1414
        $published_on_template,  $preselect_issues_in_collections_table
1443
    ) = @_;
1415
    ) = @_;
1444
    my $dbh = C4::Context->dbh;
1416
    my $dbh = C4::Context->dbh;
1445
1417
Lines 1467-1472 sub NewSubscription { Link Here
1467
            letter                                => $letter,
1439
            letter                                => $letter,
1468
            firstacquidate                        => $firstacquidate,
1440
            firstacquidate                        => $firstacquidate,
1469
            irregularity                          => $irregularity,
1441
            irregularity                          => $irregularity,
1442
            permanent_irregularity                => $permanent_irregularity,
1470
            numberpattern                         => $numberpattern,
1443
            numberpattern                         => $numberpattern,
1471
            locale                                => $locale,
1444
            locale                                => $locale,
1472
            callnumber                            => $callnumber,
1445
            callnumber                            => $callnumber,
Lines 2830-2835 sub findSerialsByStatus { Link Here
2830
    return @$serials;
2803
    return @$serials;
2831
}
2804
}
2832
2805
2806
=head2 issue_number
2807
2808
    my $week_number = issue_number($dt, 'week');
2809
2810
=cut
2811
2812
sub issue_number {
2813
    my ( $date, $issue_type ) = @_;
2814
2815
    unless ( ref($date) eq 'DateTime' ) {
2816
        Koha::Exceptions::WrongParameter->throw("Date passed to issue_number is not a valid DateTime object");
2817
    }
2818
2819
    if ( $issue_type eq 'day' ) {
2820
        return $date->dow;
2821
    }
2822
2823
    if ( $issue_type eq 'week' ) {
2824
        return $date->week_number;
2825
    }
2826
2827
    if ( $issue_type eq 'month' ) {
2828
        return $date->month;
2829
    }
2830
2831
    return 0;
2832
}
2833
2833
1;
2834
1;
2834
__END__
2835
__END__
2835
2836
(-)a/Koha/Subscription.pm (-4 / +141 lines)
Lines 19-24 package Koha::Subscription; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use C4::Serials::Frequency;
23
22
use Koha::Database;
24
use Koha::Database;
23
use Koha::Biblios;
25
use Koha::Biblios;
24
use Koha::Acquisition::Booksellers;
26
use Koha::Acquisition::Booksellers;
Lines 26-31 use Koha::Biblioitems; Link Here
26
use Koha::Subscriptions;
28
use Koha::Subscriptions;
27
use Koha::Subscription::Frequencies;
29
use Koha::Subscription::Frequencies;
28
use Koha::Subscription::Numberpatterns;
30
use Koha::Subscription::Numberpatterns;
31
use Koha::DateUtils qw( dt_from_string );
32
use JSON;
33
use Date::Calc qw( Delta_Days Add_Delta_Days Add_Delta_YM );
29
34
30
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
35
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
31
36
Lines 74-82 sub subscribers { Link Here
74
    my ($self) = @_;
79
    my ($self) = @_;
75
    my $schema = Koha::Database->new->schema;
80
    my $schema = Koha::Database->new->schema;
76
    my @borrowernumbers =
81
    my @borrowernumbers =
77
        $schema->resultset('Alert')
82
        $schema->resultset('Alert')->search( { externalid => $self->subscriptionid } )->get_column('borrowernumber')
78
        ->search( { externalid => $self->subscriptionid } )
79
        ->get_column('borrowernumber')
80
        ->all;
83
        ->all;
81
    return Koha::Patrons->search( { borrowernumber => { -in => \@borrowernumbers } } );
84
    return Koha::Patrons->search( { borrowernumber => { -in => \@borrowernumbers } } );
82
}
85
}
Lines 193-199 sub get_sharable_info { Link Here
193
    return $sub_mana_info;
196
    return $sub_mana_info;
194
}
197
}
195
198
196
=head3 _type
199
=head2 irregularities
200
201
Returns an array containing irregularities
202
203
=cut
204
205
sub irregularities {
206
    my ($self) = @_;
207
208
    return split( ';', $self->irregularity );
209
}
210
211
=head2 permanent_irregularities
212
213
Returns an array containing permanent irregularities
214
215
=cut
216
217
sub permanent_irregularities {
218
    my ($self) = @_;
219
220
    return split( ';', $self->permanent_irregularity );
221
}
222
223
=head3 lengthtype
224
225
Return the length type (issues, weeks, months)
226
227
=cut
228
229
sub lengthtype {
230
    my ($self) = @_;
231
232
    if ( $self->numberlength ) {
233
        return 'issues';
234
    }
235
236
    if ( $self->weeklength ) {
237
        return 'weeks';
238
    }
239
240
    if ( $self->monthlength ) {
241
        return 'months';
242
    }
243
}
244
245
=head3 guess_irregularities
246
247
my @irregularities = $subscription->guess_irregularities
248
249
=cut
250
251
sub guess_irregularities {
252
    my ($self) = @_;
253
254
    my @irregularities;
255
    my %permanent_irregularities = map { $_ => 1 } $self->permanent_irregularities;
256
257
    my $frequency    = $self->frequency;
258
    my $enddate      = $self->enddate;
259
    my $nextexpected = C4::Serials::GetNextExpected( $self->id );
260
    my $date         = $nextexpected->{planneddate};
261
262
    my ($issuenumber) = C4::Serials::GetFictiveIssueNumber( $self->unblessed, $date, $frequency->unblessed );
263
    my $dow = C4::Serials::issue_number( dt_from_string($date), $frequency->unit );
264
265
    if ( defined( $permanent_irregularities{$dow} ) ) {
266
        push @irregularities, $issuenumber;
267
    }
268
269
    while ( $date && Delta_Days( split( /-/, $date ), split( /-/, $enddate ) ) >= 0 ) {
270
        $issuenumber++;
271
        $date = C4::Serials::GetNextDate( $self->unblessed, $date, $frequency->unblessed );
272
        $dow  = C4::Serials::issue_number( dt_from_string($date), $frequency->unit );
273
274
        if ( defined( $permanent_irregularities{$dow} ) ) {
275
            push @irregularities, $issuenumber;
276
        }
277
    }
278
279
    return @irregularities;
280
}
281
282
=head2 guess_enddate
283
284
my $enddate = $subscription->guess_enddate;
285
286
=cut
287
288
sub guess_enddate {
289
    my ($self) = @_;
290
291
    my ( $year, $month, $day, $enddate );
292
    my $startdate    = $self->startdate;
293
    my $numberlength = $self->numberlength;
294
    my $weeklength   = $self->weeklength;
295
    my $monthlength  = $self->monthlength;
296
297
    if ( $numberlength != 0 ) {
298
        my $frequency = GetSubscriptionFrequency( $self->periodicity );
299
        if ( $frequency->{'unit'} eq 'day' ) {
300
            ( $year, $month, $day ) = Add_Delta_Days(
301
                split( /-/, $startdate ),
302
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
303
            );
304
        } elsif ( $frequency->{'unit'} eq 'week' ) {
305
            ( $year, $month, $day ) = Add_Delta_Days(
306
                split( /-/, $startdate ),
307
                $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
308
            );
309
        } elsif ( $frequency->{'unit'} eq 'month' ) {
310
            ( $year, $month, $day ) = Add_Delta_YM(
311
                split( /-/, $startdate ), 0,
312
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
313
            );
314
        } elsif ( $frequency->{'unit'} eq 'year' ) {
315
            ( $year, $month, $day ) = Add_Delta_YM(
316
                split( /-/, $startdate ),
317
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0
318
            );
319
        }
320
    } elsif ( $weeklength != 0 ) {
321
        ( $year, $month, $day ) = Add_Delta_Days( split( /-/, $startdate ), $weeklength * 7 );
322
    } elsif ( $monthlength != 0 ) {
323
        ( $year, $month, $day ) = Add_Delta_YM( split( /-/, $startdate ), 0, $monthlength );
324
    }
325
    if ( defined $year ) {
326
        $enddate = sprintf( "%04d-%02d-%02d", $year, $month, $day );
327
    } else {
328
        undef $enddate;
329
    }
330
    return $enddate;
331
}
332
333
=head3 type
197
334
198
=cut
335
=cut
199
336
(-)a/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.perl (+25 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "17656",
6
    description => "Store permanent_irregularity for serials in the subscription table",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        if ( !column_exists( 'subscription', 'permanent_irregularity' ) ) {
12
13
            $dbh->do(q{
14
                ALTER TABLE `subscription`
15
                ADD permanent_irregularity MEDIUMTEXT
16
                AFTER irregularity
17
            });
18
19
            say_success( $out, "Added column 'subscription.permanent_irregularity'" );
20
21
        } else {
22
            say_info( $out, "Column 'subscription.permanent_irregularity' already exists!" );
23
        }
24
    },
25
};
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 6491-6496 CREATE TABLE `subscription` ( Link Here
6491
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
6491
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
6492
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
6492
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
6493
  `irregularity` mediumtext DEFAULT NULL COMMENT 'any irregularities in the subscription',
6493
  `irregularity` mediumtext DEFAULT NULL COMMENT 'any irregularities in the subscription',
6494
  `permanent_irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permanent irregularities for renewal',
6494
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
6495
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
6495
  `letter` varchar(20) DEFAULT NULL,
6496
  `letter` varchar(20) DEFAULT NULL,
6496
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
6497
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc (+1 lines)
Lines 213-218 Link Here
213
            let refresh_max_date = 0;
213
            let refresh_max_date = 0;
214
            let disable_buttons = [];
214
            let disable_buttons = [];
215
215
216
            options['defaultDate'] = $(input).val();
216
            if( $(input).data("flatpickr-futureinclusive") === true
217
            if( $(input).data("flatpickr-futureinclusive") === true
217
             || $(input).data("flatpickr-futuredate") === true ) {
218
             || $(input).data("flatpickr-futuredate") === true ) {
218
                let original_date = $(input).val();
219
                let original_date = $(input).val();
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc (+35 lines)
Line 0 Link Here
1
[% daily_choice = [ {name => 'monday', value => 1}, {name => 'tuesday', value => 2}, {name => 'wednesday', value => 3}, {name => 'thursday', value => 4}, {name => 'friday', value => 5}, {name => 'saturday', value => 6}, {name => 'sunday', value => 7} ] %]
2
3
[% BLOCK days %]
4
    [% SWITCH d %]
5
    [% CASE 'monday' %]
6
        Monday
7
    [% CASE 'tuesday' %]
8
        Tuesday
9
    [% CASE 'wednesday' %]
10
        Wednesday
11
    [% CASE 'thursday' %]
12
        Thursday
13
    [% CASE 'friday' %]
14
        Friday
15
    [% CASE 'saturday' %]
16
        Saturday
17
    [% CASE 'sunday' %]
18
        Sunday
19
    [% END %]
20
[% END %]
21
22
[% FOREACH day IN daily_choice %]
23
    [% IF permanent_irreg.grep( day.value ).0 == day.value %]
24
        <input type="checkbox" name="permanent_irregularity" id="[% day.name | html %]" data-dow="[% day.value | html %]" value="[% day.value | html %]" class="skip" checked="checked" />
25
    [% ELSE %]
26
        <input type="checkbox" name="permanent_irregularity" id="[% day.name | html %]" data-dow="[% day.value | html %]" value="[% day.value | html %]" class="skip" />
27
    [% END %]
28
    <label for="[% day.name | html %]" class="inline">[% PROCESS days d=day.name %]</label>
29
[% END %]
30
<p>
31
    <em>Check days in the above list in order to keep them unpublished throughout upcoming renewals (permanent irregularities).</em>
32
</p>
33
<p>
34
    <em>Or check days in the "Not published" column below to set unpublished days for this subscription only.</em>
35
</p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc (+45 lines)
Line 0 Link Here
1
[% monthly_choice = [ {name => 'january', value => 1}, {name => 'february', value => 2}, {name => 'march', value => 3}, {name => 'april', value => 4}, {name => 'may', value => 5}, {name => 'june', value => 6}, {name => 'july', value => 7}, {name => 'august', value => 8}, {name => 'september', value => 9}, {name => 'october', value => 10}, {name => 'november', value => 11}, {name => 'december', value =>12} ] %]
2
3
[% BLOCK months %]
4
    [% SWITCH m %]
5
    [% CASE 'january' %]
6
        January
7
    [% CASE 'february' %]
8
        February
9
    [% CASE 'march' %]
10
        March
11
    [% CASE 'april' %]
12
        April
13
    [% CASE 'may' %]
14
        May
15
    [% CASE 'june' %]
16
        June
17
    [% CASE 'july' %]
18
        July
19
    [% CASE 'august' %]
20
        August
21
    [% CASE 'september' %]
22
        September
23
    [% CASE 'october' %]
24
        October
25
    [% CASE 'november' %]
26
        November
27
    [% CASE 'december' %]
28
        December
29
    [% END %]
30
[% END %]
31
32
[% FOREACH month IN monthly_choice %]
33
    [% IF permanent_irreg.grep( month.value ).0 == month.value %]
34
        <input type="checkbox" name="permanent_irregularity" id="[% month.name | html %]" data-dow="[% month.value | html %]" value="[% month.value | html %]" class="skip" checked="checked" />
35
    [% ELSE %]
36
        <input type="checkbox" name="permanent_irregularity" id="[% month.name | html %]" data-dow="[% month.value | html %]" value="[% month.value | html %]" class="skip" />
37
    [% END %]
38
    <label for="[% month.name | html %]" class="inline">[% PROCESS months m=month.name %]</label>
39
[% END %]
40
<p>
41
    <em>Check months in the above list in order to keep them unpublished throughout upcoming renewals (permanent irregularities).</em>
42
</p>
43
<p>
44
    <em>Or check months in the "Not published" column below to set unpublished months for this subscription only.</em>
45
</p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc (+30 lines)
Line 0 Link Here
1
<div class="row select-weeks">
2
    <div class="col-lg-12">
3
        <div class="button-group">
4
            <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
5
                Week(s) not published
6
                <span class="caret"></span>
7
            </button>
8
            <ul class="dropdown-menu week-columns">
9
                [% FOREACH p IN predictions_loop %]
10
                    <li>
11
                        <a class="small" href="JavaScript:Void(0);">
12
                            [% IF permanent_irreg.grep( p.dow ).0 == p.dow %]
13
                                <input type="checkbox" name="permanent_irregularity" value="[% p.dow | html %]" data-dow="[% p.dow | html %]" class="skip" checked="checked" />
14
                            [% ELSE %]
15
                                <input type="checkbox" name="permanent_irregularity" value="[% p.dow | html %]" data-dow="[% p.dow | html %]" class="skip" />
16
                            [% END %]
17
                            &nbsp;Week <b>#[% p.dow | html %]</b> ([% p.publicationdate | $KohaDates %])
18
                        </a>
19
                    </li>
20
                [% END %]
21
            </ul>
22
        </div>
23
    </div>
24
</div>
25
<p>
26
    <em>Check weeks in the above list in order to keep them unpublished throughout upcoming renewals (permanent irregularities).</em>
27
</p>
28
<p>
29
    <em>Or check weeks in the "Not published" column below to set unpublished weeks for this subscription only.</em>
30
</p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt (-17 / +15 lines)
Lines 4-26 Link Here
4
    <p><em>End date is not consistent with subscription length.</em></p>
4
    <p><em>End date is not consistent with subscription length.</em></p>
5
[% END %]
5
[% END %]
6
[% IF (ask_for_irregularities) %]
6
[% IF (ask_for_irregularities) %]
7
    <p><em>Please check issues that are NOT published (irregularities)</em></p>
7
    [% IF (show_irregularity_options) %]
8
    [% IF (daily_options) %]
8
        <script>
9
        <p><em> If there is a day (or more) in the week where issues are never published, you can check corresponding boxes below. </em></p>
9
            //<![CDATA[
10
        <input type="checkbox" id="monday" data-dow="1" class="skipday" />
10
            $(document).ready(function () {
11
        <label for="monday">Monday</label>
11
                Check_permanent_irregularities();
12
        <input type="checkbox" id="tuesday" data-dow="2" class="skipday" />
12
            });
13
        <label for="tuesday">Tuesday</label>
13
            //]]>
14
        <input type="checkbox" id="wednesday" data-dow="3" class="skipday" />
14
        </script>
15
        <label for="wednesday">Wednesday</label>
15
        [% IF (show_irregularity_options == 'day') %]
16
        <input type="checkbox" id="thursday" data-dow="4" class="skipday" />
16
            [% INCLUDE 'serials/subscription_daily_choice.inc' %]
17
        <label for="thursday">Thursday</label>
17
        [% ELSIF (show_irregularity_options == 'month') %]
18
        <input type="checkbox" id="friday" data-dow="5" class="skipday" />
18
            [% INCLUDE 'serials/subscription_monthly_choice.inc' %]
19
        <label for="friday">Friday</label>
19
        [% ELSIF (show_irregularity_options == 'week') %]
20
        <input type="checkbox" id="saturday" data-dow="6" class="skipday" />
20
            [% INCLUDE 'serials/subscription_weekly_choice.inc' %]
21
        <label for="saturday">Saturday</label>
21
        [% END %]
22
        <input type="checkbox" id="sunday" data-dow="7" class="skipday" />
23
        <label for="sunday">Sunday</label>
24
    [% END %]
22
    [% END %]
25
[% END %]
23
[% END %]
26
[% IF (predictions_loop) %]
24
[% IF (predictions_loop) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-1 / +2 lines)
Lines 390-396 Link Here
390
                                <select name="numbering_pattern" id="numberpattern" class="required" required="required">
390
                                <select name="numbering_pattern" id="numberpattern" class="required" required="required">
391
                                    <option value="">-- please choose --</option>
391
                                    <option value="">-- please choose --</option>
392
                                    [% FOREACH numberpattern IN numberpatterns %]
392
                                    [% FOREACH numberpattern IN numberpatterns %]
393
                                        <option value="[% numberpattern.id | html %]" [% IF numberpattern.selected %]selected="selected"[% END %]> [% numberpattern.label | html %] </option>
393
                                        <option value="[% numberpattern.id | html %]" [% IF numberpattern.selected %]selected="selected"[% END %]>[% numberpattern.label | html %]</option>
394
                                    [% END %]
394
                                    [% END %]
395
                                </select>
395
                                </select>
396
                                <span class="required">Required</span>
396
                                <span class="required">Required</span>
Lines 613-618 Link Here
613
        [%- END -%]
613
        [%- END -%]
614
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %];
614
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %];
615
    </script>
615
    </script>
616
    [% Asset.js("js/subscription.js") | $raw %]
616
    [% Asset.js("js/subscription-add.js") | $raw %]
617
    [% Asset.js("js/subscription-add.js") | $raw %]
617
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
618
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
618
    [% Asset.js("js/additional-fields-entry.js") | $raw %]
619
    [% Asset.js("js/additional-fields-entry.js") | $raw %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (-4 / +51 lines)
Lines 2-7 Link Here
2
[% USE Koha %]
2
[% USE Koha %]
3
[% USE Branches %]
3
[% USE Branches %]
4
[% PROCESS 'i18n.inc' %]
4
[% PROCESS 'i18n.inc' %]
5
[% USE raw %]
6
[% USE Asset %]
5
[% SET footerjs = 1 %]
7
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
8
[% INCLUDE 'doc-head-open.inc' %]
7
<title
9
<title
Lines 60-71 Link Here
60
            [% INCLUDE 'csrf-token.inc' %]
62
            [% INCLUDE 'csrf-token.inc' %]
61
            <input type="hidden" name="op" value="cud-renew" />
63
            <input type="hidden" name="op" value="cud-renew" />
62
            <input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
64
            <input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
65
            <input type="hidden" id="frequency" value="[% subscription.periodicity | html %]" />
66
            <input type="hidden" id="acqui_date" value="[% subscription.firstacquidate | html %]" />
67
            <input type="hidden" id="nextacquidate" value="[% nextacquidate | html %]" />
68
69
            <input type="hidden" id="to" value="[% enddate | html %]" />
70
            <input type="hidden" id="subtype" value="[% lengthtype | html %]" />
71
            <input type="hidden" id="sublength" value="[% sublength | html %]" />
72
            <input type="hidden" id="numberingmethod" value="[% numberpattern.numberingmethod | html %]" />
73
            <input type="hidden" id="lastvalue1" value="[% subscription.lastvalue1 | html %]" />
74
            <input type="hidden" id="lastvalue2" value="[% subscription.lastvalue2 | html %]" />
75
            <input type="hidden" id="lastvalue3" value="[% subscription.lastvalue3 | html %]" />
76
            <input type="hidden" id="add1" value="[% numberpattern.add1 | html %]" />
77
            <input type="hidden" id="add2" value="[% numberpattern.add2 | html %]" />
78
            <input type="hidden" id="add3" value="[% numberpattern.add3 | html %]" />
79
            <input type="hidden" id="every1" value="[% numberpattern.every1 | html %]" />
80
            <input type="hidden" id="every2" value="[% numberpattern.every2 | html %]" />
81
            <input type="hidden" id="every3" value="[% numberpattern.every3 | html %]" />
82
            <input type="hidden" id="innerloop1" value="[% subscription.innerloop1 | html %]" />
83
            <input type="hidden" id="innerloop2" value="[% subscription.innerloop2 | html %]" />
84
            <input type="hidden" id="innerloop3" value="[% subscription.innerloop3 | html %]" />
85
            <input type="hidden" id="setto1" value="[% numberpattern.setto1 | html %]" />
86
            <input type="hidden" id="setto2" value="[% numberpattern.setto2 | html %]" />
87
            <input type="hidden" id="setto3" value="[% numberpattern.setto3 | html %]" />
88
            <input type="hidden" id="numbering1" value="[% numberpattern.numbering1 | html %]" />
89
            <input type="hidden" id="numbering2" value="[% numberpattern.numbering2 | html %]" />
90
            <input type="hidden" id="numbering3" value="[% numberpattern.numbering3 | html %]" />
91
            <input type="hidden" id="whenmorethan1" value="[% numberpattern.whenmorethan1 | html %]" />
92
            <input type="hidden" id="whenmorethan2" value="[% numberpattern.whenmorethan2 | html %]" />
93
            <input type="hidden" id="whenmorethan3" value="[% numberpattern.whenmorethan3 | html %]" />
94
            <input type="hidden" id="locale" value="[% subscription.locale | html %]" />
63
            <fieldset class="rows"
95
            <fieldset class="rows"
64
                ><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
96
                ><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
65
                <ol>
97
                <ol>
66
                    <li>
98
                    <li>
67
                        <label for="startdate">Start date: </label>
99
                        <label for="startdate">Start date: </label>
68
                        <input type="text" size="10" id="startdate" name="startdate" value="[% startdate | html %]" class="flatpickr" />
100
                        <input type="text" size="10" id="startdate" name="startdate" class="flatpickr" value="[% startdate | html %]" />
69
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
101
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
70
                    </li>
102
                    </li>
71
                    <li>
103
                    <li>
Lines 74-80 Link Here
74
                            [% FOREACH st IN [['numberlength', 'issues'], ['weeklength', 'weeks'], ['monthlength', 'months']] %]
106
                            [% FOREACH st IN [['numberlength', 'issues'], ['weeklength', 'weeks'], ['monthlength', 'months']] %]
75
                                [% SET subtype = st.0 %]
107
                                [% SET subtype = st.0 %]
76
                                [% SET value = st.1 %]
108
                                [% SET value = st.1 %]
77
                                <option value="[% value | html %]" [% IF subscription.$subtype %]selected="selected"[% END %]>
109
                                <option
110
                                    value="[% value | html %]"
111
                                    [% IF subscription.$subtype %]
112
                                        selected="selected"
113
                                    [% END %]
114
                                >
78
                                    [% SWITCH subtype %]
115
                                    [% SWITCH subtype %]
79
                                    [% CASE 'numberlength' %]
116
                                    [% CASE 'numberlength' %]
80
                                        <span>issues</span>
117
                                        <span>issues</span>
Lines 109-114 Link Here
109
                            <textarea name="note" id="note" rows="5" cols="50"></textarea>
146
                            <textarea name="note" id="note" rows="5" cols="50"></textarea>
110
                        </li>
147
                        </li>
111
                    [% END %]
148
                    [% END %]
149
150
                    <li id="displayexample"></li>
112
                </ol>
151
                </ol>
113
            </fieldset>
152
            </fieldset>
114
            <nav class="navbar navbar-default fixed-bottom">
153
            <nav class="navbar navbar-default fixed-bottom">
Lines 125-138 Link Here
125
    [% MACRO jsinclude BLOCK %]
164
    [% MACRO jsinclude BLOCK %]
126
        [% INCLUDE 'calendar.inc' %]
165
        [% INCLUDE 'calendar.inc' %]
127
        <script>
166
        <script>
128
            $(document).ready(function () {
167
            var subscriptionid = "[% subscription.subscriptionid | html %]";
129
                $(".close").on("click", function (e) {
168
            var irregularity = "[% subscription.irregularity | html %]";
169
            var more_than_one_serial = "[% more_than_one_serial | html %]";
170
            $(document).ready(function(){
171
                if (subscriptionid) {
172
                    testPredictionPattern();
173
                }
174
                $(".close").on("click", function(e){
130
                    e.preventDefault();
175
                    e.preventDefault();
131
                    window.opener.location.reload(false);
176
                    window.opener.location.reload(false);
132
                    self.close();
177
                    self.close();
133
                });
178
                });
134
            });
179
            });
135
        </script>
180
        </script>
181
        [% Asset.js("js/subscription.js") | $raw %]
182
        [% Asset.js("js/showpredictionpattern.js") | $raw %]
136
    [% END %]
183
    [% END %]
137
</div>
184
</div>
138
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
185
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js (-1 / +20 lines)
Lines 8-16 function Check_boxes(dow) { Link Here
8
            $(this).prop("checked", false);
8
            $(this).prop("checked", false);
9
        });
9
        });
10
    }
10
    }
11
    return false;
12
}
13
function Check_permanent_irregularities() {
14
    nothing_checked = 1;
15
    $("input[name='irregularity']").each(function () {
16
        if ($(this).is(":checked")) {
17
            nothing_checked = 0;
18
        }
19
    });
20
21
    // No day/month/week are checked, could be after a renewal.
22
    // So check them according to permanent irregularity
23
    if (nothing_checked) {
24
        $(".skip").each(function () {
25
            if ($(this).is(":checked")) {
26
                Check_boxes($(this).data("dow"));
27
            }
28
        });
29
    }
11
}
30
}
12
$(document).ready(function () {
31
$(document).ready(function () {
13
    $("#displayexample").on("change", ".skipday", function () {
32
    $("#displayexample").on("change", ".skip", function (e) {
14
        Check_boxes($(this).data("dow"));
33
        Check_boxes($(this).data("dow"));
15
    });
34
    });
16
});
35
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js (-2 / +2 lines)
Lines 689-695 function showPredictionPatternTest(data) { Link Here
689
    $("#page_2 > div").attr("class", "col-sm-6");
689
    $("#page_2 > div").attr("class", "col-sm-6");
690
}
690
}
691
691
692
function hidePredcitionPatternTest() {
692
function hidePredictionPatternTest() {
693
    $("#displayexample").hide();
693
    $("#displayexample").hide();
694
    $("#page_2 > div").attr(
694
    $("#page_2 > div").attr(
695
        "class",
695
        "class",
Lines 858-864 $(document).ready(function () { Link Here
858
858
859
    $("#displayexample").on("click", "#hidepredictionpattern", function (e) {
859
    $("#displayexample").on("click", "#hidepredictionpattern", function (e) {
860
        e.preventDefault();
860
        e.preventDefault();
861
        hidePredcitionPatternTest();
861
        hidePredictionPatternTest();
862
    });
862
    });
863
863
864
    $("#biblionumber").on("change", function () {
864
    $("#biblionumber").on("change", function () {
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription.js (+99 lines)
Line 0 Link Here
1
var advancedpatternlocked;
2
3
function testPredictionPattern() {
4
    var frequencyid = $("#frequency").val();
5
    var acquidate;
6
    var error = 0;
7
    var error_msg = "";
8
    if (frequencyid == undefined || frequencyid == "") {
9
        error_msg += "- " + MSG_FREQUENCY_UNDEFINED + "\n";
10
        error++;
11
    }
12
    acquidate = $("#acqui_date").val();
13
    if (acquidate == undefined || acquidate == "") {
14
        error_msg += "-" + MSG_PUB_DATE_UNDEFINED + "\n";
15
        error++;
16
    }
17
    if (more_than_one_serial !== "") {
18
        var nextacquidate = $("#nextacquidate").val();
19
        if (nextacquidate == undefined || nextacquidate == "") {
20
            error_msg += "-" + MSG_NEXT_ISSUE_UNDEFINED + "\n";
21
            error++;
22
        }
23
    }
24
25
    if (error) {
26
        alert(MSG_PATTERN_TEST_FAILED.format(error_msg));
27
        return false;
28
    }
29
30
    var custompattern = 0;
31
    if (advancedpatternlocked == 0) {
32
        custompattern = 1;
33
    }
34
35
    var ajaxData = {
36
        custompattern: custompattern,
37
        firstacquidate: acquidate,
38
    };
39
40
    if (subscriptionid !== "") {
41
        ajaxData.subscriptionid = subscriptionid;
42
    }
43
    if (more_than_one_serial !== "") {
44
        ajaxData.nextacquidate = nextacquidate;
45
    }
46
47
    var ajaxParams = [
48
        "to",
49
        "subtype",
50
        "sublength",
51
        "frequency",
52
        "numberingmethod",
53
        "lastvalue1",
54
        "lastvalue2",
55
        "lastvalue3",
56
        "add1",
57
        "add2",
58
        "add3",
59
        "every1",
60
        "every2",
61
        "every3",
62
        "innerloop1",
63
        "innerloop2",
64
        "innerloop3",
65
        "setto1",
66
        "setto2",
67
        "setto3",
68
        "numbering1",
69
        "numbering2",
70
        "numbering3",
71
        "whenmorethan1",
72
        "whenmorethan2",
73
        "whenmorethan3",
74
        "locale",
75
        "sfdescription",
76
        "unitsperissue",
77
        "issuesperunit",
78
        "unit",
79
    ];
80
    for (i in ajaxParams) {
81
        var param = ajaxParams[i];
82
        var value = $("#" + param).val();
83
        if (value && value.length > 0) ajaxData[param] = value;
84
    }
85
86
    $.ajax({
87
        url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
88
        data: ajaxData,
89
        success: function (data) {
90
            showPredictionPatternTest(data);
91
            patternneedtobetested = 0;
92
        },
93
    });
94
}
95
96
function showPredictionPatternTest(data) {
97
    $("#displayexample").html(data).show();
98
    $("#page_2 > div").attr("class", "col-xs-6");
99
}
(-)a/serials/showpredictionpattern.pl (-11 / +17 lines)
Lines 30-40 publication date, based on frequency and first publication date. Link Here
30
30
31
use Modern::Perl;
31
use Modern::Perl;
32
32
33
use CGI         qw ( -utf8 );
33
use CGI        qw ( -utf8 );
34
use Date::Calc  qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days );
34
use Date::Calc qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days );
35
use C4::Auth    qw( get_template_and_user );
35
use C4::Auth   qw( get_template_and_user );
36
use C4::Output  qw( output_html_with_http_headers );
36
use C4::Output qw( output_html_with_http_headers );
37
use C4::Serials qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq );
37
use C4::Serials
38
    qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq );
38
use C4::Serials::Frequency;
39
use C4::Serials::Frequency;
39
use Koha::DateUtils qw( dt_from_string );
40
use Koha::DateUtils qw( dt_from_string );
40
41
Lines 119-133 if ( defined $subscriptionid ) { Link Here
119
120
120
my @predictions_loop;
121
my @predictions_loop;
121
my ($calculated) = GetSeq( \%subscription, \%pattern );
122
my ($calculated) = GetSeq( \%subscription, \%pattern );
123
my $dow = C4::Serials::issue_number( dt_from_string($date), $frequency->{unit} );
122
push @predictions_loop, {
124
push @predictions_loop, {
123
    number          => $calculated,
125
    number          => $calculated,
124
    publicationdate => $date,
126
    publicationdate => $date,
125
    issuenumber     => $issuenumber,
127
    issuenumber     => $issuenumber,
126
    dow             => Day_of_Week( split /-/, $date ),
128
    dow             => $dow,
127
};
129
};
128
my @irreg = ();
130
my @irreg           = ();
131
my @permanent_irreg = ();
129
if ( defined $subscriptionid ) {
132
if ( defined $subscriptionid ) {
130
    @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
133
    my $subscription_o = Koha::Subscriptions->find($subscriptionid);
134
    @irreg           = $subscription_o->irregularities;
135
    @permanent_irreg = $subscription_o->permanent_irregularities;
131
    while ( @irreg && $issuenumber > $irreg[0] ) {
136
    while ( @irreg && $issuenumber > $irreg[0] ) {
132
        shift @irreg;
137
        shift @irreg;
133
    }
138
    }
Lines 146-152 while ( $i < 1000 ) { Link Here
146
    }
151
    }
147
    if ( defined $date ) {
152
    if ( defined $date ) {
148
        $line{'publicationdate'} = $date;
153
        $line{'publicationdate'} = $date;
149
        $line{'dow'}             = Day_of_Week( split /-/, $date );
154
        $line{dow}               = C4::Serials::issue_number( dt_from_string($date), $frequency->{unit} );
150
    }
155
    }
151
156
152
    # Check if we don't have exceed end date
157
    # Check if we don't have exceed end date
Lines 193-200 $template->param( Link Here
193
198
194
if ( $frequency->{unit} and not $custompattern ) {
199
if ( $frequency->{unit} and not $custompattern ) {
195
    $template->param( ask_for_irregularities => 1 );
200
    $template->param( ask_for_irregularities => 1 );
196
    if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {
201
    if ( $frequency->{unit} =~ /^(day|month|week)$/ and $frequency->{unitsperissue} == 1 ) {
197
        $template->param( daily_options => 1 );
202
        $template->param( show_irregularity_options => $frequency->{unit} );
203
        $template->param( permanent_irreg           => \@permanent_irreg );
198
    }
204
    }
199
}
205
}
200
206
(-)a/serials/subscription-add.pl (-67 / +47 lines)
Lines 259-304 sub get_letter_loop { Link Here
259
    ];
259
    ];
260
}
260
}
261
261
262
sub _guess_enddate {
263
    my ( $startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength ) = @_;
264
    my ( $year, $month, $day );
265
    my $enddate;
266
    if ( $numberlength != 0 ) {
267
        my $frequency = GetSubscriptionFrequency($frequencyid);
268
        if ( $frequency->{'unit'} eq 'day' ) {
269
            ( $year, $month, $day ) = Add_Delta_Days(
270
                split( /-/, $startdate_iso ),
271
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
272
            );
273
        } elsif ( $frequency->{'unit'} eq 'week' ) {
274
            ( $year, $month, $day ) = Add_Delta_Days(
275
                split( /-/, $startdate_iso ),
276
                $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
277
            );
278
        } elsif ( $frequency->{'unit'} eq 'month' ) {
279
            ( $year, $month, $day ) = Add_Delta_YM(
280
                split( /-/, $startdate_iso ), 0,
281
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
282
            );
283
        } elsif ( $frequency->{'unit'} eq 'year' ) {
284
            ( $year, $month, $day ) = Add_Delta_YM(
285
                split( /-/, $startdate_iso ),
286
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0
287
            );
288
        }
289
    } elsif ( $weeklength != 0 ) {
290
        ( $year, $month, $day ) = Add_Delta_Days( split( /-/, $startdate_iso ), $weeklength * 7 );
291
    } elsif ( $monthlength != 0 ) {
292
        ( $year, $month, $day ) = Add_Delta_YM( split( /-/, $startdate_iso ), 0, $monthlength );
293
    }
294
    if ( defined $year ) {
295
        $enddate = sprintf( "%04d-%02d-%02d", $year, $month, $day );
296
    } else {
297
        undef $enddate;
298
    }
299
    return $enddate;
300
}
301
302
sub redirect_add_subscription {
262
sub redirect_add_subscription {
303
    my $periodicity = $query->param('frequency');
263
    my $periodicity = $query->param('frequency');
304
    if ( $periodicity eq 'mana' ) {
264
    if ( $periodicity eq 'mana' ) {
Lines 314-327 sub redirect_add_subscription { Link Here
314
    }
274
    }
315
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing( { $query->Vars } );
275
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing( { $query->Vars } );
316
276
317
    my $auser          = $query->param('user');
277
    my $auser                  = $query->param('user');
318
    my $branchcode     = $query->param('branchcode');
278
    my $branchcode             = $query->param('branchcode');
319
    my $aqbooksellerid = $query->param('aqbooksellerid');
279
    my $aqbooksellerid         = $query->param('aqbooksellerid');
320
    my $cost           = $query->param('cost');
280
    my $cost                   = $query->param('cost');
321
    my $aqbudgetid     = $query->param('aqbudgetid');
281
    my $aqbudgetid             = $query->param('aqbudgetid');
322
    my @irregularity   = $query->multi_param('irregularity');
282
    my @irregularity           = $query->multi_param('irregularity');
323
    my $locale         = $query->param('locale');
283
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
324
    my $graceperiod    = $query->param('graceperiod') || 0;
284
    my $locale                 = $query->param('locale');
285
    my $graceperiod            = $query->param('graceperiod') || 0;
325
286
326
    my $subtype   = $query->param('subtype');
287
    my $subtype   = $query->param('subtype');
327
    my $sublength = $query->param('sublength');
288
    my $sublength = $query->param('sublength');
Lines 363-383 sub redirect_add_subscription { Link Here
363
        output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
324
        output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
364
325
365
    if ( !defined $enddate || $enddate eq '' ) {
326
    if ( !defined $enddate || $enddate eq '' ) {
327
        my $subscription = Koha::Subscription->new(
328
            {
329
                startdate    => $startdate,
330
                periodicity  => $periodicity,
331
                weeklength   => $weeklength,
332
                monthlength  => $monthlength,
333
                numberlength => $numberlength
334
            }
335
        );
336
366
        if ( $subtype eq "issues" ) {
337
        if ( $subtype eq "issues" ) {
367
            $enddate = _guess_enddate( $firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength );
338
            $subscription->startdate($firstacquidate);
368
        } else {
369
            $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength );
370
        }
339
        }
340
        $enddate = $subscription->guess_enddate;
371
    }
341
    }
372
    my $subscriptionid = NewSubscription(
342
    my $subscriptionid = NewSubscription(
373
        $auser,                     $branchcode,       $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
343
        $auser,                     $branchcode,  $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
374
        $startdate,                 $periodicity,      $numberlength,   $weeklength,
344
        $startdate,                 $periodicity, $numberlength,   $weeklength,
375
        $monthlength,               $lastvalue1,       $innerloop1,     $lastvalue2, $innerloop2,
345
        $monthlength,               $lastvalue1,  $innerloop1,     $lastvalue2, $innerloop2,
376
        $lastvalue3,                $innerloop3,       $status,         $notes, $letter, $firstacquidate,
346
        $lastvalue3,                $innerloop3,  $status,         $notes,      $letter, $firstacquidate,
377
        join( ";", @irregularity ), $numberpattern,    $locale,         $callnumber,
347
        join( ";", @irregularity ), join( ';', @permanent_irregularity ), $numberpattern, $locale, $callnumber,
378
        $manualhistory,             $internalnotes,    $serialsadditems,
348
        $manualhistory,             $internalnotes,                       $serialsadditems,
379
        $staffdisplaycount,         $opacdisplaycount, $graceperiod, $location, $enddate,
349
        $staffdisplaycount,         $opacdisplaycount,                    $graceperiod, $location, $enddate,
380
        $skip_serialseq,            $itemtype,         $previousitemtype, $mana_id, $ccode, $published_on_template,
350
        $skip_serialseq,            $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template,
381
        $preselect_issues_in_collections_table
351
        $preselect_issues_in_collections_table
382
    );
352
    );
383
    if (    ( C4::Context->preference('Mana') == 1 )
353
    if (    ( C4::Context->preference('Mana') == 1 )
Lines 399-407 sub redirect_add_subscription { Link Here
399
}
369
}
400
370
401
sub redirect_mod_subscription {
371
sub redirect_mod_subscription {
402
    my $subscriptionid = $query->param('subscriptionid');
372
    my $subscriptionid         = $query->param('subscriptionid');
403
    my @irregularity   = $query->multi_param('irregularity');
373
    my @irregularity           = $query->multi_param('irregularity');
404
    my $auser          = $query->param('user');
374
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
375
    my $auser                  = $query->param('user');
405
    my $librarian => scalar $query->param('librarian'),
376
    my $librarian => scalar $query->param('librarian'),
406
        my $branchcode = $query->param('branchcode');
377
        my $branchcode = $query->param('branchcode');
407
    my $cost           = $query->param('cost');
378
    my $cost           = $query->param('cost');
Lines 472-482 sub redirect_mod_subscription { Link Here
472
443
473
    # Guess end date
444
    # Guess end date
474
    if ( !defined $enddate || $enddate eq '' ) {
445
    if ( !defined $enddate || $enddate eq '' ) {
446
        my $subscription = Koha::Subscription->new(
447
            {
448
                startdate    => $startdate,
449
                periodicity  => $periodicity,
450
                weeklength   => $weeklength,
451
                monthlength  => $monthlength,
452
                numberlength => $numberlength
453
            }
454
        );
455
475
        if ( $subtype eq "issues" ) {
456
        if ( $subtype eq "issues" ) {
476
            $enddate = _guess_enddate( $nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength );
457
            $subscription->startdate($nextacquidate);
477
        } else {
478
            $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength );
479
        }
458
        }
459
        $enddate = $subscription->guess_enddate;
480
    }
460
    }
481
461
482
    my $nextexpected = GetNextExpected($subscriptionid);
462
    my $nextexpected = GetNextExpected($subscriptionid);
Lines 490-497 sub redirect_mod_subscription { Link Here
490
    }
470
    }
491
471
492
    ModSubscription(
472
    ModSubscription(
493
        $auser,            $branchcode,     $aqbooksellerid, $cost, $aqbudgetid, $startdate,
473
        $auser,            $branchcode,     $aqbooksellerid,            $cost, $aqbudgetid, $startdate,
494
        $periodicity,      $firstacquidate, join( ";", @irregularity ),
474
        $periodicity,      $firstacquidate, join( ";", @irregularity ), join( ';', @permanent_irregularity ),
495
        $numberpattern,    $locale,         $numberlength,     $weeklength, $monthlength, $lastvalue1,
475
        $numberpattern,    $locale,         $numberlength,     $weeklength, $monthlength, $lastvalue1,
496
        $innerloop1,       $lastvalue2,     $innerloop2,       $lastvalue3, $innerloop3,
476
        $innerloop1,       $lastvalue2,     $innerloop2,       $lastvalue3, $innerloop3,
497
        $status,           $biblionumber,   $callnumber,       $notes,      $letter,
477
        $status,           $biblionumber,   $callnumber,       $notes,      $letter,
(-)a/serials/subscription-renew.pl (-7 / +51 lines)
Lines 49-58 use Carp qw( carp ); Link Here
49
use C4::Koha;
49
use C4::Koha;
50
use C4::Auth qw( get_template_and_user );
50
use C4::Auth qw( get_template_and_user );
51
use C4::Context;
51
use C4::Context;
52
use C4::Auth        qw( get_template_and_user );
52
use C4::Auth    qw( get_template_and_user );
53
use C4::Output      qw( output_and_exit output_html_with_http_headers );
53
use C4::Output  qw( output_and_exit output_html_with_http_headers );
54
use C4::Serials     qw( GetSubscription GetSubscriptionLength NewSubscription ReNewSubscription );
54
use C4::Serials qw( GetSubscription GetSubscriptionLength NewSubscription ReNewSubscription GetSerials GetNextExpected);
55
use C4::Serials::Frequency;
56
use C4::Serials::Numberpattern;
55
use Koha::DateUtils qw( dt_from_string output_pref );
57
use Koha::DateUtils qw( dt_from_string output_pref );
58
use Date::Calc      qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM);
56
59
57
my $query = CGI->new;
60
my $query = CGI->new;
58
my $dbh   = C4::Context->dbh;
61
my $dbh   = C4::Context->dbh;
Lines 86-91 if ( $op eq "cud-renew" ) { Link Here
86
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
89
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
87
    }
90
    }
88
91
92
    my @irregularities = $query->param('irregularity');
89
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
93
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
90
    ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength );
94
    ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength );
91
    ReNewSubscription(
95
    ReNewSubscription(
Lines 115-120 if ( $op eq "cud-renew" ) { Link Here
115
                monthlength    => $subscription->{monthlength},
119
                monthlength    => $subscription->{monthlength},
116
            }
120
            }
117
        );
121
        );
122
123
        $subscription = Koha::Subscriptions->find($subscriptionid);
124
        my @irregularities           = $subscription->guess_irregularities;
125
        my @permanent_irregularities = $query->param('permanent_irregularity');
126
        $subscription->permanent_irregularity( join( ';', @permanent_irregularities ) );
127
        $subscription->irregularity( join( ';', @irregularities ) );
128
        $subscription->store;
118
    }
129
    }
119
} elsif ( $op eq 'multi_renew' ) {
130
} elsif ( $op eq 'multi_renew' ) {
120
    my @subscriptions;
131
    my @subscriptions;
Lines 137-148 if ( $op eq "cud-renew" ) { Link Here
137
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
148
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
138
    }
149
    }
139
150
140
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
151
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1, dateformat => 'iso' } )
141
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
152
        or output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } );
153
    my ($serials_number) = GetSerials($subscriptionid);
154
    if ( $serials_number > 1 ) {
155
        $template->param( more_than_one_serial => 1 );
156
    }
157
158
    my $subscription_o = Koha::Subscriptions->find( $subscription->{subscriptionid} );
159
    my $lengthtype     = $subscription_o->lengthtype;
160
    my $nextexpected   = GetNextExpected($subscriptionid);
161
    $subscription_o->update(
162
        {
163
            startdate    => $subscription->{enddate},
164
            periodicity  => $subscription->{periodicity},
165
            weeklength   => $subscription->{weeklength},
166
            monthlength  => $subscription->{monthlength},
167
            numberlength => $subscription->{numberlength}
168
        }
169
    );
170
    my $enddate = $subscription_o->guess_enddate;
171
172
    my $sub_length;
173
    foreach my $length_unit (qw(numberlength weeklength monthlength)) {
174
        if ( $subscription->{$length_unit} ) {
175
            $sub_length = $subscription->{$length_unit};
176
            last;
177
        }
178
    }
179
180
    my $numberpattern = GetSubscriptionNumberpattern( $subscription->{numberpattern} );
142
181
143
    $template->param(
182
    $template->param(
144
        startdate    => $newstartdate,
183
        subscription  => $subscription,
145
        subscription => $subscription,
184
        numberpattern => $numberpattern,
185
        startdate     => $newstartdate,
186
        nextacquidate => $nextexpected->{planneddate},
187
        enddate       => $enddate,
188
        lengthtype    => $lengthtype,
189
        sublength     => $sub_length,
146
    );
190
    );
147
}
191
}
148
192
(-)a/t/Serials/IssueNumber.t (+49 lines)
Line 0 Link Here
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
# WITHOUT 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 <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 10;
21
use Test::Warn;
22
use Test::NoWarnings;
23
use Test::Exception;
24
25
BEGIN {
26
    use_ok('C4::Serials');
27
}
28
29
my $dt = DateTime->new( year => 2017, month => 1, day => 1 );
30
31
throws_ok { C4::Serials::issue_number( '2017', 'day' ) }
32
'Koha::Exceptions::WrongParameter',
33
    'Date passed to issue_number is not a valid DateTime object';
34
35
is( C4::Serials::issue_number( $dt, 'day' ), 7, '2017-01-01 is the seventh day of week' );
36
37
is( C4::Serials::issue_number( $dt, 'week' ), 52, '2017-01-01 is the week #52 of the year' );
38
39
is( C4::Serials::issue_number( $dt, 'month' ), 1, '2017-01-01 is the first month of the year' );
40
41
$dt = DateTime->new( year => 2022, month => 9, day => 17 );
42
43
is( C4::Serials::issue_number( $dt, 'day' ), 6, '2022-09-17 is the sixth day of week' );
44
45
is( C4::Serials::issue_number( $dt, 'week' ), 37, '2022-09-17 is the week #37 of the year' );
46
47
is( C4::Serials::issue_number( $dt, 'month' ), 9, '2022-09-17 is the ninth month of the year' );
48
49
is( C4::Serials::issue_number( $dt, 'foo' ), 0, 'issue_number return 0 for others issue type' );
(-)a/t/db_dependent/Koha/Subscription.t (-1 / +44 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 11;
23
use Test::More tests => 12;
24
24
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::Subscription;
26
use Koha::Subscription;
Lines 126-131 subtest 'Koha::Subscription->frequency' => sub { Link Here
126
    );
126
    );
127
};
127
};
128
128
129
subtest 'Koha::Subscription::lengthtype' => sub {
130
    plan tests => 3;
131
132
    my $subs = $builder->build(
133
        {
134
            source => 'Subscription',
135
            value  => {
136
                numberlength => 7,
137
                weeklength   => 0,
138
                monthlength  => 0,
139
            }
140
        }
141
    );
142
    my $subscription = Koha::Subscriptions->find( $subs->{subscriptionid} );
143
    is( $subscription->lengthtype, 'issues', 'Subscription with numberlength has issues type' );
144
145
    my $subs2 = $builder->build(
146
        {
147
            source => 'Subscription',
148
            value  => {
149
                numberlength => 0,
150
                weeklength   => 52,
151
                monthlength  => 0,
152
            }
153
        }
154
    );
155
    my $subscription2 = Koha::Subscriptions->find( $subs2->{subscriptionid} );
156
    is( $subscription2->lengthtype, 'weeks', 'Subscription with weeklength has weeks type' );
157
158
    my $subs3 = $builder->build(
159
        {
160
            source => 'Subscription',
161
            value  => {
162
                numberlength => 0,
163
                weeklength   => 0,
164
                monthlength  => 12,
165
            }
166
        }
167
    );
168
    my $subscription3 = Koha::Subscriptions->find( $subs3->{subscriptionid} );
169
    is( $subscription3->lengthtype, 'months', 'Subscription with monthlength has months type' );
170
};
171
129
my $nb_of_subs = Koha::Subscriptions->search->count;
172
my $nb_of_subs = Koha::Subscriptions->search->count;
130
my $biblio_1   = $builder->build_sample_biblio;
173
my $biblio_1   = $builder->build_sample_biblio;
131
my $bi_1       = $biblio_1->biblioitem;
174
my $bi_1       = $biblio_1->biblioitem;
(-)a/t/db_dependent/Koha/Subscription/GuessEnddate.t (+173 lines)
Line 0 Link Here
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
# WITHOUT 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 <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 16;
21
use Test::NoWarnings;
22
use t::lib::TestBuilder;
23
24
use Koha::Database;
25
use Koha::Subscriptions;
26
27
BEGIN {
28
    use_ok('Koha::Subscriptions');
29
}
30
31
my $schema  = Koha::Database->new->schema;
32
my $builder = t::lib::TestBuilder->new;
33
34
$schema->storage->txn_begin;
35
36
my $frequency = $builder->build(
37
    {
38
        source => 'SubscriptionFrequency',
39
        value  => {
40
            unit          => 'day',
41
            unitsperissue => 1,
42
            issuesperunit => 1
43
        }
44
    }
45
);
46
47
my $subscription = $builder->build(
48
    {
49
        source => 'Subscription',
50
        value  => {
51
            startdate    => '2018-01-01',
52
            weeklength   => 0,
53
            monthlength  => 0,
54
            numberlength => 7,
55
            periodicity  => $frequency->{id},
56
        }
57
    }
58
);
59
60
$subscription = Koha::Subscriptions->find( $subscription->{subscriptionid} );
61
$frequency    = $schema->resultset('SubscriptionFrequency')->find( $frequency->{id} );
62
is( $subscription->guess_enddate, '2018-01-08' );
63
64
$frequency->update(
65
    {
66
        unit          => 'day',
67
        unitsperissue => 2,
68
        issuesperunit => 1
69
    }
70
);
71
is( $subscription->guess_enddate, '2018-01-15' );
72
73
$frequency->update(
74
    {
75
        unit          => 'day',
76
        unitsperissue => 1,
77
        issuesperunit => 2
78
    }
79
);
80
is( $subscription->guess_enddate, '2018-01-04' );
81
82
$frequency->update(
83
    {
84
        unit          => 'week',
85
        unitsperissue => 1,
86
        issuesperunit => 1
87
    }
88
);
89
is( $subscription->guess_enddate, '2018-02-19' );
90
91
$frequency->update(
92
    {
93
        unit          => 'week',
94
        unitsperissue => 2,
95
        issuesperunit => 1
96
    }
97
);
98
is( $subscription->guess_enddate, '2018-04-09' );
99
100
$frequency->update(
101
    {
102
        unit          => 'week',
103
        unitsperissue => 1,
104
        issuesperunit => 2
105
    }
106
);
107
is( $subscription->guess_enddate, '2018-01-25' );
108
109
$frequency->update(
110
    {
111
        unit          => 'month',
112
        unitsperissue => 1,
113
        issuesperunit => 1
114
    }
115
);
116
is( $subscription->guess_enddate, '2018-08-01' );
117
118
$frequency->update(
119
    {
120
        unit          => 'month',
121
        unitsperissue => 2,
122
        issuesperunit => 1
123
    }
124
);
125
is( $subscription->guess_enddate, '2019-03-01' );
126
127
$frequency->update(
128
    {
129
        unit          => 'month',
130
        unitsperissue => 1,
131
        issuesperunit => 2
132
    }
133
);
134
is( $subscription->guess_enddate, '2018-04-01' );
135
136
$frequency->update(
137
    {
138
        unit          => 'year',
139
        unitsperissue => 1,
140
        issuesperunit => 1
141
    }
142
);
143
is( $subscription->guess_enddate, '2025-01-01' );
144
145
$frequency->update(
146
    {
147
        unit          => 'year',
148
        unitsperissue => 2,
149
        issuesperunit => 1
150
    }
151
);
152
is( $subscription->guess_enddate, '2032-01-01' );
153
154
$frequency->update(
155
    {
156
        unit          => 'year',
157
        unitsperissue => 1,
158
        issuesperunit => 2
159
    }
160
);
161
is( $subscription->guess_enddate, '2021-01-01' );
162
163
$subscription->numberlength(0);
164
$subscription->weeklength(2);
165
$subscription->store;
166
is( $subscription->guess_enddate, '2018-01-15' );
167
168
$subscription->weeklength(0);
169
$subscription->monthlength(1);
170
$subscription->store;
171
is( $subscription->guess_enddate, '2018-02-01' );
172
173
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Subscription/Irregularities.t (+201 lines)
Line 0 Link Here
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
# WITHOUT 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 <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
use Test::NoWarnings;
22
use t::lib::TestBuilder;
23
24
use C4::Serials;
25
26
use Koha::Database;
27
use Koha::Subscriptions;
28
29
BEGIN {
30
    use_ok('Koha::Subscriptions');
31
}
32
33
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
35
36
$schema->storage->txn_begin;
37
38
my $biblio = $builder->build(
39
    {
40
        source => 'Biblio',
41
    }
42
);
43
44
my $frequency = $builder->build(
45
    {
46
        source => 'SubscriptionFrequency',
47
        value  => {
48
            unit          => 'day',
49
            unitsperissue => 1,
50
            issuesperunit => 1
51
        }
52
    }
53
);
54
55
my $number_pattern = $builder->build(
56
    {
57
        source => 'SubscriptionNumberpattern',
58
        value  => {
59
            numberingmethod => 'No.{X}',
60
            add1            => 1,
61
            every1          => 1,
62
            whenmorethan1   => 99999,
63
            setto1          => 1
64
        }
65
    }
66
);
67
68
my $subscription = $builder->build(
69
    {
70
        source => 'Subscription',
71
        value  => {
72
            biblionumber           => $biblio->{biblionumber},
73
            startdate              => '2018-05-07',
74
            weeklength             => 0,
75
            monthlength            => 0,
76
            numberlength           => 7,
77
            periodicity            => $frequency->{id},
78
            countissuesperunit     => 1,
79
            status                 => 1,
80
            lastvalue1             => 5,
81
            lastvalue2             => 0,
82
            innerloop1             => 0,
83
            innerloop2             => 0,
84
            innerloop3             => 0,
85
            lastvalue3             => 0,
86
            firstacquidate         => '2018-05-07',
87
            irregularity           => '3;4',
88
            permanent_irregularity => '3;4',
89
            numberpattern          => $number_pattern->{id},
90
            enddate                => '2018-05-13',
91
            closed                 => 0
92
        }
93
    }
94
);
95
96
$builder->build(
97
    {
98
        source => 'Serial',
99
        value  => {
100
            biblionumber   => $biblio->{biblionumber},
101
            subscriptionid => $subscription->{subscriptionid},
102
            serialseq      => 'No.1',
103
            serialseq_x    => 1,
104
            status         => 2,
105
            planneddate    => '2018-05-07',
106
            publisheddate  => '2018-05-07',
107
        }
108
    }
109
);
110
111
$builder->build(
112
    {
113
        source => 'Serial',
114
        value  => {
115
            biblionumber   => $biblio->{biblionumber},
116
            subscriptionid => $subscription->{subscriptionid},
117
            serialseq      => 'No.2',
118
            serialseq_x    => 2,
119
            status         => 2,
120
            planneddate    => '2018-05-08',
121
            publisheddate  => '2018-05-08',
122
        }
123
    }
124
);
125
126
$builder->build(
127
    {
128
        source => 'Serial',
129
        value  => {
130
            biblionumber   => $biblio->{biblionumber},
131
            subscriptionid => $subscription->{subscriptionid},
132
            serialseq      => 'No.3',
133
            serialseq_x    => 3,
134
            status         => 2,
135
            planneddate    => '2018-05-11',
136
            publisheddate  => '2018-05-11',
137
        }
138
    }
139
);
140
141
$builder->build(
142
    {
143
        source => 'Serial',
144
        value  => {
145
            biblionumber   => $biblio->{biblionumber},
146
            subscriptionid => $subscription->{subscriptionid},
147
            serialseq      => 'No.4',
148
            serialseq_x    => 4,
149
            status         => 2,
150
            planneddate    => '2018-05-12',
151
            publisheddate  => '2018-05-12',
152
        }
153
    }
154
);
155
156
$builder->build(
157
    {
158
        source => 'Serial',
159
        value  => {
160
            biblionumber   => $biblio->{biblionumber},
161
            subscriptionid => $subscription->{subscriptionid},
162
            serialseq      => 'No.5',
163
            serialseq_x    => 5,
164
            status         => 2,
165
            planneddate    => '2018-05-13',
166
            publisheddate  => '2018-05-13',
167
        }
168
    }
169
);
170
171
$builder->build(
172
    {
173
        source => 'Serial',
174
        value  => {
175
            biblionumber   => $biblio->{biblionumber},
176
            subscriptionid => $subscription->{subscriptionid},
177
            serialseq      => 'No.6',
178
            serialseq_x    => 6,
179
            status         => 1,
180
            planneddate    => '2018-05-14',
181
            publisheddate  => '2018-05-14',
182
        }
183
    }
184
);
185
186
C4::Serials::ReNewSubscription(
187
    {
188
        subscriptionid => $subscription->{subscriptionid},
189
        user           => undef,
190
        startdate      => $subscription->{enddate},
191
        numberlength   => $subscription->{numberlength},
192
        weeklength     => $subscription->{weeklength},
193
        monthlength    => $subscription->{monthlength},
194
    }
195
);
196
197
my $s              = Koha::Subscriptions->find( $subscription->{subscriptionid} );
198
my $irregularities = join( ';', $s->guess_irregularities );
199
is( $irregularities, '10;11', 'Irregularities have been updated' );
200
201
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials/SubscriptionIrregularity.t (-1 / +37 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use t::lib::TestBuilder;
6
use Test::More tests => 7;
7
use Test::NoWarnings;
8
use Koha::Database;
9
10
use_ok('Koha::Subscription');
11
12
my $schema = Koha::Database->new->schema;
13
$schema->storage->txn_begin;
14
15
my $builder = t::lib::TestBuilder->new();
16
17
my $subscription = $builder->build(
18
    {
19
        source => 'Subscription',
20
        value  => {
21
            irregularity           => '2;4;7',
22
            permanent_irregularity => '1;2'
23
        },
24
    }
25
);
26
27
my $subscription_o = Koha::Subscriptions->find( $subscription->{subscriptionid} );
28
my @irreg          = $subscription_o->irregularities;
29
is( $irreg[0], 2, 'First element of irregularities is 2' );
30
is( $irreg[1], 4, 'Second element of irregularities is 4' );
31
is( $irreg[2], 7, 'Third element of irregularities is 7' );
32
33
my @permanent_irreg = $subscription_o->permanent_irregularities;
34
is( $permanent_irreg[0], 1, 'First element of permanent_irregularities is 1' );
35
is( $permanent_irreg[1], 2, 'Second element of permanent_irregularities is 2' );
36
37
$schema->storage->txn_rollback;

Return to bug 17656