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

(-)a/C4/Serials.pm (-33 / +34 lines)
Lines 106-111 BEGIN { Link Here
106
      HasItems
106
      HasItems
107
107
108
      findSerialsByStatus
108
      findSerialsByStatus
109
      &subscriptionCurrentlyOnOrder
110
      &issue_number
109
111
110
    );
112
    );
111
}
113
}
Lines 1277-1313 sub ModNextExpected { Link Here
1277
1279
1278
}
1280
}
1279
1281
1280
=head2 GetSubscriptionIrregularities
1281
1282
=over 4
1283
1284
=item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1285
get the list of irregularities for a subscription
1286
1287
=back
1288
1289
=cut
1290
1291
sub GetSubscriptionIrregularities {
1292
    my $subscriptionid = shift;
1293
1294
    return unless $subscriptionid;
1295
1296
    my $dbh = C4::Context->dbh;
1297
    my $query = qq{
1298
        SELECT irregularity
1299
        FROM subscription
1300
        WHERE subscriptionid = ?
1301
    };
1302
    my $sth = $dbh->prepare($query);
1303
    $sth->execute($subscriptionid);
1304
1305
    my ($result) = $sth->fetchrow_array;
1306
    my @irreg = split /;/, $result;
1307
1308
    return @irreg;
1309
}
1310
1311
=head2 ModSubscription
1282
=head2 ModSubscription
1312
1283
1313
this function modifies a subscription. Put all new values on input args.
1284
this function modifies a subscription. Put all new values on input args.
Lines 1318-1324 returns the number of rows affected Link Here
1318
sub ModSubscription {
1289
sub ModSubscription {
1319
    my (
1290
    my (
1320
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1291
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1321
    $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale,
1292
    $periodicity, $firstacquidate, $irregularity, $permanent_irregularity, $numberpattern, $locale,
1322
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1293
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1323
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1294
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1324
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1295
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
Lines 1352-1357 sub ModSubscription { Link Here
1352
            letter            => $letter,
1323
            letter            => $letter,
1353
            firstacquidate    => $firstacquidate,
1324
            firstacquidate    => $firstacquidate,
1354
            irregularity      => $irregularity,
1325
            irregularity      => $irregularity,
1326
            permanent_irregularity  => $permanent_irregularity,
1355
            numberpattern     => $numberpattern,
1327
            numberpattern     => $numberpattern,
1356
            locale            => $locale,
1328
            locale            => $locale,
1357
            callnumber        => $callnumber,
1329
            callnumber        => $callnumber,
Lines 1404-1410 sub NewSubscription { Link Here
1404
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1376
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1405
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1377
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1406
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1378
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1407
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1379
    $permanent_irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1408
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1380
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1409
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode,
1381
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode,
1410
    $published_on_template,
1382
    $published_on_template,
Lines 1435-1440 sub NewSubscription { Link Here
1435
            letter            => $letter,
1407
            letter            => $letter,
1436
            firstacquidate    => $firstacquidate,
1408
            firstacquidate    => $firstacquidate,
1437
            irregularity      => $irregularity,
1409
            irregularity      => $irregularity,
1410
            permanent_irregularity  => $permanent_irregularity,
1438
            numberpattern     => $numberpattern,
1411
            numberpattern     => $numberpattern,
1439
            locale            => $locale,
1412
            locale            => $locale,
1440
            callnumber        => $callnumber,
1413
            callnumber        => $callnumber,
Lines 2729-2734 sub findSerialsByStatus { Link Here
2729
    return @$serials;
2702
    return @$serials;
2730
}
2703
}
2731
2704
2705
=head2 issue_number
2706
2707
    my $week_number = issue_number($dt, 'week');
2708
2709
=cut
2710
2711
sub issue_number {
2712
    my ($date, $issue_type) = @_;
2713
2714
    unless ( ref($date) eq 'DateTime' ) {
2715
        Koha::Exceptions::WrongParameter->throw("Date passed to issue_number is not a valid DateTime object" );
2716
    }
2717
2718
    if ($issue_type eq 'day') {
2719
        return $date->dow;
2720
    }
2721
2722
    if ($issue_type eq 'week') {
2723
        return $date->week_number;
2724
    }
2725
2726
    if ($issue_type eq 'month') {
2727
        return $date->month;
2728
    }
2729
2730
    return 0;
2731
}
2732
2732
1;
2733
1;
2733
__END__
2734
__END__
2734
2735
(-)a/Koha/Subscription.pm (-1 / +131 lines)
Lines 20-25 package Koha::Subscription; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
22
23
use C4::Serials::Frequency;
24
use C4::Serials qw(issue_number);
25
23
use Koha::Database;
26
use Koha::Database;
24
use Koha::Biblios;
27
use Koha::Biblios;
25
use Koha::Acquisition::Booksellers;
28
use Koha::Acquisition::Booksellers;
Lines 27-32 use Koha::Biblioitems; Link Here
27
use Koha::Subscriptions;
30
use Koha::Subscriptions;
28
use Koha::Subscription::Frequencies;
31
use Koha::Subscription::Frequencies;
29
use Koha::Subscription::Numberpatterns;
32
use Koha::Subscription::Numberpatterns;
33
use Koha::DateUtils;
34
use JSON;
35
use Date::Calc qw( Delta_Days Add_Delta_Days Add_Delta_YM );
30
36
31
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
37
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
32
38
Lines 195-201 sub get_sharable_info { Link Here
195
}
201
}
196
202
197
203
198
=head3 _type
204
=head2 irregularities
205
206
Returns an array containing irregularities
207
208
=cut
209
210
sub irregularities {
211
    my ($self) = @_;
212
213
    return split(';', $self->irregularity);
214
}
215
216
=head2 permanent_irregularities
217
218
Returns an array containing permanent irregularities
219
220
=cut
221
222
sub permanent_irregularities {
223
    my ($self) = @_;
224
225
    return split(';', $self->permanent_irregularity);
226
}
227
228
=head3 lengthtype
229
230
Return the length type (issues, weeks, months)
231
232
=cut
233
234
sub lengthtype {
235
    my ($self) = @_;
236
237
    if ($self->numberlength) {
238
        return 'issues';
239
    }
240
241
    if ($self->weeklength) {
242
        return 'weeks';
243
    }
244
245
    if ($self->monthlength) {
246
        return 'months';
247
    }
248
}
249
250
=head3 guess_irregularities
251
252
my @irregularities = $subscription->guess_irregularities
253
254
=cut
255
256
sub guess_irregularities {
257
    my ($self) = @_;
258
259
    my @irregularities;
260
    my %permanent_irregularities = map { $_ => 1 } $self->permanent_irregularities;
261
262
    my $schema = Koha::Database->new->schema;
263
    my $frequency = $schema->resultset('SubscriptionFrequency')->find($self->periodicity);
264
265
    my $enddate = $self->enddate;
266
    my $nextexpected = C4::Serials::GetNextExpected($self->id);
267
    my $date = $nextexpected->{planneddate};
268
269
    my ($issuenumber) = C4::Serials::GetFictiveIssueNumber($self->unblessed, $date);
270
    my $dow = issue_number( dt_from_string($date), $frequency->unit );
271
272
    if ( defined( $permanent_irregularities{$dow} ) ) {
273
        push @irregularities, $issuenumber;
274
    }
275
276
    while ( Delta_Days( split(/-/, $date), split(/-/, $enddate) ) >= 0 ) {
277
        $issuenumber++;
278
        $date = C4::Serials::GetNextDate($self->unblessed, $date);
279
        $dow = issue_number( dt_from_string($date), $frequency->unit );
280
281
        if ( defined( $permanent_irregularities{$dow} ) ) {
282
            push @irregularities, $issuenumber;
283
        }
284
    }
285
286
    return @irregularities;
287
}
288
289
=head2 guess_enddate
290
291
my $enddate = $subscription->guess_enddate;
292
293
=cut
294
295
sub guess_enddate {
296
    my ($self) = @_;
297
298
    my ($year, $month, $day, $enddate);
299
    my $startdate = $self->startdate;
300
    my $numberlength = $self->numberlength;
301
    my $weeklength = $self->weeklength;
302
    my $monthlength = $self->monthlength;
303
304
    if($numberlength != 0) {
305
        my $frequency = GetSubscriptionFrequency($self->periodicity);
306
        if($frequency->{'unit'} eq 'day') {
307
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
308
        } elsif($frequency->{'unit'} eq 'week') {
309
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
310
        } elsif($frequency->{'unit'} eq 'month') {
311
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
312
        } elsif($frequency->{'unit'} eq 'year') {
313
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
314
        }
315
    } elsif($weeklength != 0) {
316
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $weeklength * 7);
317
    } elsif($monthlength != 0) {
318
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), 0, $monthlength);
319
    }
320
    if(defined $year) {
321
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
322
    } else {
323
        undef $enddate;
324
    }
325
    return $enddate;
326
}
327
328
=head3 type
199
329
200
=cut
330
=cut
201
331
(-)a/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.perl (+9 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    if( !column_exists( 'subscription', 'permanent_irregularity' ) ) {
4
        $dbh->do( "ALTER TABLE `subscription` ADD permanent_irregularity MEDIUMTEXT AFTER irregularity" );
5
    }
6
7
    SetVersion( $DBversion );
8
    print "Upgrade to $DBversion done (Bug 17656 - Irregularities in serial prediction pattern are planned only for current subscription)\n";
9
}
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 6122-6127 CREATE TABLE `subscription` ( Link Here
6122
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
6122
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
6123
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
6123
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
6124
  `irregularity` mediumtext DEFAULT NULL COMMENT 'any irregularities in the subscription',
6124
  `irregularity` mediumtext DEFAULT NULL COMMENT 'any irregularities in the subscription',
6125
  `permanent_irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permanent irregularities for renewal',
6125
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
6126
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
6126
  `letter` varchar(20) DEFAULT NULL,
6127
  `letter` varchar(20) DEFAULT NULL,
6127
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
6128
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc (+33 lines)
Line 0 Link Here
1
<p><em>
2
    If there is a day (or more) in the week where issues are never
3
    published, you can check corresponding boxes below.
4
</em></p>
5
[% 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} ] %]
6
7
[% BLOCK days %]
8
    [% SWITCH d %]
9
        [% CASE 'monday' %]Monday
10
        [% CASE 'tuesday' %]Tuesday
11
        [% CASE 'wednesday' %]Wednesday
12
        [% CASE 'thursday' %]Thursday
13
        [% CASE 'friday' %]Friday
14
        [% CASE 'saturday' %]Saturday
15
        [% CASE 'sunday' %]Sunday
16
    [% END %]
17
[% END %]
18
19
[% FOREACH day IN daily_choice %]
20
    [% IF permanent_irreg.grep( day.value ).0 == day.value %]
21
        <input type="checkbox" name="permanent_irregularity"
22
               id="[% day.name %]" data-dow="[% day.value %]"
23
               value="[% day.value %]" class="skip"
24
               checked="checked"
25
        />
26
    [% ELSE %]
27
        <input type="checkbox" name="permanent_irregularity"
28
               id="[% day.name %]" data-dow="[% day.value %]"
29
               value="[% day.value %]" class="skip"
30
        />
31
    [% END %]
32
    <label for="[% day.name | html %]" class="inline">[% PROCESS days d=day.name %]</label>
33
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc (+38 lines)
Line 0 Link Here
1
<p><em>
2
    If there is a month (or more) in the year where issues are never
3
    published, you can check corresponding boxes below.
4
</em></p>
5
[% 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} ] %]
6
7
[% BLOCK months %]
8
    [% SWITCH m %]
9
        [% CASE 'january' %]January
10
        [% CASE 'february' %]February
11
        [% CASE 'march' %]March
12
        [% CASE 'april' %]April
13
        [% CASE 'may' %]May
14
        [% CASE 'june' %]June
15
        [% CASE 'july' %]July
16
        [% CASE 'august' %]August
17
        [% CASE 'september' %]September
18
        [% CASE 'october' %]October
19
        [% CASE 'november' %]November
20
        [% CASE 'december' %]December
21
    [% END %]
22
[% END %]
23
24
[% FOREACH month IN monthly_choice %]
25
    [% IF permanent_irreg.grep( month.value ).0 == month.value %]
26
        <input type="checkbox" name="permanent_irregularity"
27
               id="[% month.name %]" data-dow="[% month.value %]"
28
               value="[% month.value %]" class="skip"
29
               checked="checked"
30
        />
31
    [% ELSE %]
32
        <input type="checkbox" name="permanent_irregularity"
33
               id="[% month.name %]" data-dow="[% month.value %]"
34
               value="[% month.value %]" class="skip"
35
        />
36
    [% END %]
37
    <label for="[% month.name | html %]" class="inline">[% PROCESS months m=month.name %]</label>
38
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc (+28 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 href="#" class="small">
12
                            [% IF permanent_irreg.grep( p.dow ).0 == p.dow %]
13
                                <input type="checkbox" name="permanent_irregularity" value="[% p.dow %]" data-dow="[% p.dow %]" class="skip" checked="checked"/>
14
                            [% ELSE %]
15
                                <input type="checkbox" name="permanent_irregularity" value="[% p.dow %]" data-dow="[% p.dow %]" class="skip"/>
16
                            [% END %]
17
                            &nbsp;Week <b>#[% p.dow %]</b> ([% p.publicationdate | $KohaDates %])
18
                        </a>
19
                    </li>
20
                [% END %]
21
            </ul>
22
        </div>
23
    </div>
24
</div>
25
<p>
26
    <em>Choice the week(s) in the year where issues are never
27
    published.</em>
28
</p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt (-19 / +15 lines)
Lines 5-29 Link Here
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
    <p><em>Please check issues that are NOT published (irregularities)</em></p>
8
    [% IF (daily_options) %]
8
    [% IF (show_irregularity_options) %]
9
        <p><em>
9
        <script>
10
            If there is a day (or more) in the week where issues are never
10
        //<![CDATA[
11
            published, you can check corresponding boxes below.
11
        $(document).ready(function(){
12
        </em></p>
12
            Check_permanent_irregularities();
13
        <input type="checkbox" id="monday" data-dow="1" class="skipday" />
13
        });
14
        <label for="monday">Monday</label>
14
        //]]>
15
        <input type="checkbox" id="tuesday" data-dow="2" class="skipday" />
15
        </script>
16
        <label for="tuesday">Tuesday</label>
16
        [% IF (show_irregularity_options == 'day') %]
17
        <input type="checkbox" id="wednesday" data-dow="3" class="skipday" />
17
            [% INCLUDE 'serials/subscription_daily_choice.inc' %]
18
        <label for="wednesday">Wednesday</label>
18
        [% ELSIF (show_irregularity_options == 'month') %]
19
        <input type="checkbox" id="thursday" data-dow="4" class="skipday" />
19
            [% INCLUDE 'serials/subscription_monthly_choice.inc' %]
20
        <label for="thursday">Thursday</label>
20
        [% ELSIF (show_irregularity_options == 'week') %]
21
        <input type="checkbox" id="friday" data-dow="5" class="skipday" />
21
            [% INCLUDE 'serials/subscription_weekly_choice.inc' %]
22
        <label for="friday">Friday</label>
22
        [% END %]
23
        <input type="checkbox" id="saturday" data-dow="6" class="skipday" />
24
        <label for="saturday">Saturday</label>
25
        <input type="checkbox" id="sunday" data-dow="7" class="skipday" />
26
        <label for="sunday">Sunday</label>
27
    [% END %]
23
    [% END %]
28
[% END %]
24
[% END %]
29
[% IF (predictions_loop) %]
25
[% IF (predictions_loop) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (+1 lines)
Lines 602-607 fieldset.rows table { clear: none; margin: 0; } Link Here
602
        [%- END -%]
602
        [%- END -%]
603
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %];
603
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %];
604
    </script>
604
    </script>
605
    [% Asset.js("js/subscription.js") | $raw %]
605
    [% Asset.js("js/subscription-add.js") | $raw %]
606
    [% Asset.js("js/subscription-add.js") | $raw %]
606
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
607
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
607
    [% Asset.js("js/additional-fields-entry.js") | $raw %]
608
    [% Asset.js("js/additional-fields-entry.js") | $raw %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (+41 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 Asset %]
5
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
7
<title>[% FILTER collapse %]
8
<title>[% FILTER collapse %]
Lines 61-66 Link Here
61
    [% INCLUDE 'csrf-token.inc' %]
62
    [% INCLUDE 'csrf-token.inc' %]
62
		<input type="hidden" name="op" value="cud-renew" />
63
		<input type="hidden" name="op" value="cud-renew" />
63
		<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 %]" />
64
		<fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
95
		<fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
65
        <ol>
96
        <ol>
66
            <li>
97
            <li>
Lines 109-114 Link Here
109
            <textarea name="note" id="note" rows="5" cols="50"></textarea>
140
            <textarea name="note" id="note" rows="5" cols="50"></textarea>
110
        </li>
141
        </li>
111
    [% END %]
142
    [% END %]
143
144
    <li id="displayexample"></li>
112
</ol>
145
</ol>
113
</fieldset>
146
</fieldset>
114
    <nav class="navbar navbar-default fixed-bottom">
147
    <nav class="navbar navbar-default fixed-bottom">
Lines 125-131 Link Here
125
[% MACRO jsinclude BLOCK %]
158
[% MACRO jsinclude BLOCK %]
126
    [% INCLUDE 'calendar.inc' %]
159
    [% INCLUDE 'calendar.inc' %]
127
    <script>
160
    <script>
161
        var subscriptionid = "[% subscription.subscriptionid %]";
162
        var irregularity = "[% subscription.irregularity %]";
163
        var more_than_one_serial = "[% more_than_one_serial %]";
128
        $(document).ready(function(){
164
        $(document).ready(function(){
165
            if (subscriptionid) {
166
                testPredictionPattern();
167
            }
129
            $(".close").on("click", function(e){
168
            $(".close").on("click", function(e){
130
                e.preventDefault();
169
                e.preventDefault();
131
                window.opener.location.reload(false);
170
                window.opener.location.reload(false);
Lines 133-138 Link Here
133
            });
172
            });
134
        });
173
        });
135
    </script>
174
    </script>
175
    [% Asset.js("js/subscription.js") | $raw %]
176
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
136
[% END %]
177
[% END %]
137
178
138
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
179
[% 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(){
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 (-1 / +1 lines)
Lines 548-554 function showPredictionPatternTest( data ){ Link Here
548
    $("#page_2 > div").attr("class","col-sm-6");
548
    $("#page_2 > div").attr("class","col-sm-6");
549
}
549
}
550
550
551
function hidePredcitionPatternTest(){
551
function hidePredictionPatternTest(){
552
    $("#displayexample").hide();
552
    $("#displayexample").hide();
553
    $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2");
553
    $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2");
554
}
554
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription.js (+77 lines)
Line 0 Link Here
1
2
var advancedpatternlocked;
3
4
function testPredictionPattern() {
5
    var frequencyid = $("#frequency").val();
6
    var acquidate;
7
    var error = 0;
8
    var error_msg = "";
9
    if(frequencyid == undefined || frequencyid == ""){
10
        error_msg += "- " + MSG_FREQUENCY_UNDEFINED + "\n";
11
        error ++;
12
    }
13
    acquidate = $("#acqui_date").val();
14
    if(acquidate == undefined || acquidate == ""){
15
        error_msg += "-" + MSG_PUB_DATE_UNDEFINED + "\n";
16
        error ++;
17
    }
18
    if( more_than_one_serial !== "" ){
19
        var nextacquidate = $("#nextacquidate").val();
20
        if(nextacquidate == undefined || nextacquidate == ""){
21
            error_msg += "-" + MSG_NEXT_ISSUE_UNDEFINED + "\n";
22
            error ++;
23
        }
24
    }
25
26
    if(error){
27
        alert( MSG_PATTERN_TEST_FAILED.format(error_msg) );
28
        return false;
29
    }
30
31
    var custompattern = 0;
32
    if(advancedpatternlocked == 0) {
33
        custompattern = 1;
34
    }
35
36
    var ajaxData = {
37
        'custompattern': custompattern,
38
        'firstacquidate': acquidate
39
    };
40
41
    if( subscriptionid !== "" ){
42
        ajaxData.subscriptionid = subscriptionid;
43
    }
44
    if( more_than_one_serial !== "" ){
45
        ajaxData.nextacquidate = nextacquidate;
46
    }
47
48
49
    var ajaxParams = [
50
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
51
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
52
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
53
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
54
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale',
55
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
56
    ];
57
    for(i in ajaxParams) {
58
        var param = ajaxParams[i];
59
        var value = $("#"+param).val();
60
        if(value && value.length > 0)
61
            ajaxData[param] = value;
62
    }
63
64
    $.ajax({
65
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
66
        data: ajaxData,
67
        success: function(data) {
68
            showPredictionPatternTest( data );
69
            patternneedtobetested = 0;
70
        }
71
    });
72
}
73
74
function showPredictionPatternTest( data ){
75
    $("#displayexample").html(data).show();
76
    $("#page_2 > div").attr("class","col-xs-6");
77
}
(-)a/serials/showpredictionpattern.pl (-5 / +10 lines)
Lines 119-133 if(defined $subscriptionid) { Link Here
119
119
120
my @predictions_loop;
120
my @predictions_loop;
121
my ($calculated) = GetSeq(\%subscription, \%pattern);
121
my ($calculated) = GetSeq(\%subscription, \%pattern);
122
my $dow = issue_number( dt_from_string($date), $frequency->{unit} );
122
push @predictions_loop, {
123
push @predictions_loop, {
123
    number => $calculated,
124
    number => $calculated,
124
    publicationdate => $date,
125
    publicationdate => $date,
125
    issuenumber => $issuenumber,
126
    issuenumber => $issuenumber,
126
    dow => Day_of_Week(split /-/, $date),
127
    dow => $dow,
127
};
128
};
128
my @irreg = ();
129
my @irreg = ();
130
my @permanent_irreg = ();
129
if(defined $subscriptionid) {
131
if(defined $subscriptionid) {
130
    @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
132
    my $subscription_o = Koha::Subscriptions->find($subscriptionid);
133
    @irreg = $subscription_o->irregularities;
134
    @permanent_irreg = $subscription_o->permanent_irregularities;
131
    while(@irreg && $issuenumber > $irreg[0]) {
135
    while(@irreg && $issuenumber > $irreg[0]) {
132
        shift @irreg;
136
        shift @irreg;
133
    }
137
    }
Lines 146-152 while( $i < 1000 ) { Link Here
146
    }
150
    }
147
    if(defined $date){
151
    if(defined $date){
148
        $line{'publicationdate'} = $date;
152
        $line{'publicationdate'} = $date;
149
        $line{'dow'} = Day_of_Week(split /-/, $date);
153
        $line{dow} = issue_number( dt_from_string($date), $frequency->{unit} );
150
    }
154
    }
151
155
152
    # Check if we don't have exceed end date
156
    # Check if we don't have exceed end date
Lines 182-189 $template->param( Link Here
182
186
183
if ( $frequency->{unit} and not $custompattern ) {
187
if ( $frequency->{unit} and not $custompattern ) {
184
    $template->param( ask_for_irregularities => 1 );
188
    $template->param( ask_for_irregularities => 1 );
185
    if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {
189
    if ( $frequency->{unit} =~ /^(day|month|week)$/ and $frequency->{unitsperissue} == 1 ) {
186
        $template->param( daily_options => 1 );
190
        $template->param( show_irregularity_options => $frequency->{unit} );
191
        $template->param( permanent_irreg => \@permanent_irreg );
187
    }
192
    }
188
}
193
}
189
194
(-)a/serials/subscription-add.pl (-37 / +26 lines)
Lines 247-280 sub get_letter_loop { Link Here
247
    ];
247
    ];
248
}
248
}
249
249
250
sub _guess_enddate {
251
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
252
    my ($year, $month, $day);
253
    my $enddate;
254
    if($numberlength != 0) {
255
        my $frequency = GetSubscriptionFrequency($frequencyid);
256
        if($frequency->{'unit'} eq 'day') {
257
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
258
        } elsif($frequency->{'unit'} eq 'week') {
259
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
260
        } elsif($frequency->{'unit'} eq 'month') {
261
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
262
        } elsif($frequency->{'unit'} eq 'year') {
263
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
264
        }
265
    } elsif($weeklength != 0) {
266
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
267
    } elsif($monthlength != 0) {
268
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
269
    }
270
    if(defined $year) {
271
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
272
    } else {
273
        undef $enddate;
274
    }
275
    return $enddate;
276
}
277
278
sub redirect_add_subscription {
250
sub redirect_add_subscription {
279
    my $periodicity = $query->param('frequency');
251
    my $periodicity = $query->param('frequency');
280
    if ($periodicity eq 'mana') {
252
    if ($periodicity eq 'mana') {
Lines 296-301 sub redirect_add_subscription { Link Here
296
    my $cost           = $query->param('cost');
268
    my $cost           = $query->param('cost');
297
    my $aqbudgetid     = $query->param('aqbudgetid');
269
    my $aqbudgetid     = $query->param('aqbudgetid');
298
    my @irregularity   = $query->multi_param('irregularity');
270
    my @irregularity   = $query->multi_param('irregularity');
271
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
299
    my $locale         = $query->param('locale');
272
    my $locale         = $query->param('locale');
300
    my $graceperiod    = $query->param('graceperiod') || 0;
273
    my $graceperiod    = $query->param('graceperiod') || 0;
301
274
Lines 338-356 sub redirect_add_subscription { Link Here
338
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
311
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
339
312
340
    if(!defined $enddate || $enddate eq '') {
313
    if(!defined $enddate || $enddate eq '') {
314
        my $subscription = Koha::Subscriptions->new({
315
            startdate       => $startdate,
316
            periodicity     => $periodicity,
317
            weeklength      => $weeklength,
318
            monthlength     =>$monthlength,
319
            numberlength    => $numberlength
320
        });
321
341
        if($subtype eq "issues") {
322
        if($subtype eq "issues") {
342
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength)
323
            $subscription->startdate($firstacquidate);
343
        } else {
344
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
345
        }
324
        }
325
        $enddate = $subscription->guess_enddate;
346
    }
326
    }
347
    my $subscriptionid = NewSubscription(
327
    my $subscriptionid = NewSubscription(
348
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
328
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
349
        $startdate, $periodicity, $numberlength, $weeklength,
329
        $startdate, $periodicity, $numberlength, $weeklength,
350
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
330
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
351
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
331
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
352
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
332
        join(";",@irregularity), join(';', @permanent_irregularity), $numberpattern, $locale,
353
        $manualhistory, $internalnotes, $serialsadditems,
333
        $callnumber, $manualhistory, $internalnotes, $serialsadditems,
354
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
334
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
355
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
335
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
356
    );
336
    );
Lines 370-375 sub redirect_add_subscription { Link Here
370
sub redirect_mod_subscription {
350
sub redirect_mod_subscription {
371
    my $subscriptionid = $query->param('subscriptionid');
351
    my $subscriptionid = $query->param('subscriptionid');
372
    my @irregularity = $query->multi_param('irregularity');
352
    my @irregularity = $query->multi_param('irregularity');
353
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
373
    my $auser = $query->param('user');
354
    my $auser = $query->param('user');
374
    my $librarian => scalar $query->param('librarian'),
355
    my $librarian => scalar $query->param('librarian'),
375
    my $branchcode = $query->param('branchcode');
356
    my $branchcode = $query->param('branchcode');
Lines 439-449 sub redirect_mod_subscription { Link Here
439
420
440
    # Guess end date
421
    # Guess end date
441
    if(!defined $enddate || $enddate eq '') {
422
    if(!defined $enddate || $enddate eq '') {
423
        my $subscription = Koha::Subscriptions->new({
424
            startdate       => $startdate,
425
            periodicity     => $periodicity,
426
            weeklength      => $weeklength,
427
            monthlength     =>$monthlength,
428
            numberlength    => $numberlength
429
        });
430
442
        if($subtype eq "issues") {
431
        if($subtype eq "issues") {
443
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
432
            $subscription->startdate($nextacquidate);
444
        } else {
445
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
446
        }
433
        }
434
        $enddate = $subscription->guess_enddate;
447
    }
435
    }
448
436
449
    my $nextexpected = GetNextExpected($subscriptionid);
437
    my $nextexpected = GetNextExpected($subscriptionid);
Lines 457-463 sub redirect_mod_subscription { Link Here
457
    ModSubscription(
445
    ModSubscription(
458
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
446
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
459
        $periodicity, $firstacquidate, join(";",@irregularity),
447
        $periodicity, $firstacquidate, join(";",@irregularity),
460
        $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1,
448
        join(';', @permanent_irregularity), $numberpattern, $locale,
449
        $numberlength, $weeklength, $monthlength, $lastvalue1,
461
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
450
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
462
        $status, $biblionumber, $callnumber, $notes, $letter,
451
        $status, $biblionumber, $callnumber, $notes, $letter,
463
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
452
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
(-)a/serials/subscription-renew.pl (-2 / +47 lines)
Lines 53-59 use C4::Context; Link Here
53
use C4::Auth qw( get_template_and_user );
53
use C4::Auth qw( get_template_and_user );
54
use C4::Output qw( output_and_exit output_html_with_http_headers );
54
use C4::Output qw( output_and_exit output_html_with_http_headers );
55
use C4::Serials qw( GetSubscription GetSubscriptionLength NewSubscription ReNewSubscription );
55
use C4::Serials qw( GetSubscription GetSubscriptionLength NewSubscription ReNewSubscription );
56
use C4::Serials::Frequency;
57
use C4::Serials::Numberpattern;
56
use Koha::DateUtils qw( dt_from_string output_pref );
58
use Koha::DateUtils qw( dt_from_string output_pref );
59
use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM);
57
60
58
my $query = CGI->new;
61
my $query = CGI->new;
59
my $dbh   = C4::Context->dbh;
62
my $dbh   = C4::Context->dbh;
Lines 85-90 if ( $op eq "cud-renew" ) { Link Here
85
      print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
88
      print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
86
    }
89
    }
87
90
91
    my @permanent_irregularities = $query->param('permanent_irregularity');
92
    my @irregularities = $query->param('irregularity');
88
    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' } );
89
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
94
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
90
    ReNewSubscription(
95
    ReNewSubscription(
Lines 114-119 if ( $op eq "cud-renew" ) { Link Here
114
                monthlength    => $subscription->{monthlength},
119
                monthlength    => $subscription->{monthlength},
115
            }
120
            }
116
        );
121
        );
122
123
        $subscription = Koha::Subscriptions->find( $subscriptionid );
124
        my @irregularities = $subscription->guess_irregularities;
125
        $subscription->permanent_irregularity(join(';', @permanent_irregularities));
126
        $subscription->irregularity( join(';', @irregularities) )
127
        $subscription->store;
117
    }
128
    }
118
}
129
}
119
elsif ( $op eq 'multi_renew' ) {
130
elsif ( $op eq 'multi_renew' ) {
Lines 141-154 else { Link Here
141
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
152
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
142
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
153
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
143
154
155
    my ($serials_number) = GetSerials($subscriptionid);
156
    if ($serials_number > 1) {
157
        $template->param(more_than_one_serial => 1);
158
    }
159
160
    my $subscription_o = Koha::Subscriptions->find($subscription->{subscriptionid});
161
    my $lengthtype = $subscription_o->lengthtype;
162
    my $nextexpected = GetNextExpected($subscriptionid);
163
    $subscription_o->update({
164
        startdate       => $subscription->{enddate},
165
        periodicity     => $subscription->{periodicity},
166
        weeklength      => $subscription->{weeklength},
167
        monthlength     => $subscription->{monthlength},
168
        numberlength    => $subscription->{numberlength}
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});
181
144
    $template->param(
182
    $template->param(
145
        startdate      => $newstartdate,
183
        startdate       => $newstartdate,
146
        subscription   => $subscription,
184
        subscription    => $subscription,
185
        numberpattern   => $numberpattern,
186
        startdate       => $newstartdate,
187
        nextacquidate   => $nextexpected->{planneddate},
188
        enddate         => $enddate,
189
        lengthtype      => $lengthtype,
190
        sublength       => $sub_length,
147
    );
191
    );
148
}
192
}
149
193
150
$template->param(
194
$template->param(
151
    op => $op,
195
    op => $op,
196
    popup => ($mode eq 'popup'),
152
);
197
);
153
198
154
output_html_with_http_headers $query, $cookie, $template->output;
199
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/Serials/IssueNumber.t (+47 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 <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 10;
21
use Test::Warn;
22
23
BEGIN {
24
    use_ok('C4::Serials');
25
}
26
27
my $dt = DateTime->new(year => 2017, month => 1, day => 1);
28
29
eval { issue_number('2017', 'day'); };
30
is(ref($@), 'Koha::Exceptions::WrongParameter');
31
is($@, 'Date passed to issue_number is not a valid DateTime object');
32
33
is(issue_number($dt, 'day'), 7, '2017-01-01 is the seventh day of week');
34
35
is(issue_number($dt, 'week'), 52, '2017-01-01 is the week #52 of the year');
36
37
is(issue_number($dt, 'month'), 1, '2017-01-01 is the first month of the year');
38
39
$dt = DateTime->new(year => 2022, month => 9, day => 17);
40
41
is(issue_number($dt, 'day'), 6, '2022-09-17 is the sixth day of week');
42
43
is(issue_number($dt, 'week'), 37, '2022-09-17 is the week #37 of the year');
44
45
is(issue_number($dt, 'month'), 9, '2022-09-17 is the ninth month of the year');
46
47
is(issue_number($dt, 'foo'), 0, 'issue_number return 0 for others issue type');
(-)a/t/db_dependent/Koha/Subscription.t (-1 / +38 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Subscription;
25
use Koha::Subscription;
Lines 115-120 subtest 'Koha::Subscription->frequency' => sub { Link Here
115
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
115
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
116
};
116
};
117
117
118
subtest 'Koha::Subscription::lengthtype' => sub {
119
    plan tests => 3;
120
121
    my $subs = $builder->build({
122
        source => 'Subscription',
123
        value => {
124
            numberlength => 7,
125
            weeklength => 0,
126
            monthlength => 0,
127
        }
128
    });
129
    my $subscription = Koha::Subscriptions->find($subs->{subscriptionid});
130
    is($subscription->lengthtype, 'issues', 'Subscription with numberlength has issues type');
131
132
    my $subs2 = $builder->build({
133
        source => 'Subscription',
134
        value => {
135
            numberlength => 0,
136
            weeklength => 52,
137
            monthlength => 0,
138
        }
139
    });
140
    my $subscription2 = Koha::Subscriptions->find($subs2->{subscriptionid});
141
    is($subscription2->lengthtype, 'weeks', 'Subscription with weeklength has weeks type');
142
143
    my $subs3 = $builder->build({
144
        source => 'Subscription',
145
        value => {
146
            numberlength => 0,
147
            weeklength => 0,
148
            monthlength => 12,
149
        }
150
    });
151
    my $subscription3 = Koha::Subscriptions->find($subs3->{subscriptionid});
152
    is($subscription3->lengthtype, 'months', 'Subscription with monthlength has months type');
153
};
154
118
my $nb_of_subs = Koha::Subscriptions->search->count;
155
my $nb_of_subs = Koha::Subscriptions->search->count;
119
my $biblio_1   = $builder->build_sample_biblio;
156
my $biblio_1   = $builder->build_sample_biblio;
120
my $bi_1       = $biblio_1->biblioitem;
157
my $bi_1       = $biblio_1->biblioitem;
(-)a/t/db_dependent/Koha/Subscription/GuessEnddate.t (+148 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
# 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 => 15;
21
use t::lib::TestBuilder;
22
23
use Koha::Database;
24
use Koha::Subscriptions;
25
26
BEGIN {
27
    use_ok('Koha::Subscriptions');
28
}
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
$schema->storage->txn_begin;
34
35
36
my $frequency = $builder->build({
37
    source => 'SubscriptionFrequency',
38
    value => {
39
        unit => 'day',
40
        unitsperissue => 1,
41
        issuesperunit => 1
42
    }
43
});
44
45
my $subscription = $builder->build({
46
        source => 'Subscription',
47
        value => {
48
            startdate => '2018-01-01',
49
            weeklength => 0,
50
            monthlength => 0,
51
            numberlength => 7,
52
            periodicity => $frequency->{id},
53
        }
54
});
55
56
$subscription = Koha::Subscriptions->find($subscription->{subscriptionid});
57
$frequency = $schema->resultset('SubscriptionFrequency')->find($frequency->{id});
58
is($subscription->guess_enddate, '2018-01-08');
59
60
$frequency->update({
61
    unit => 'day',
62
    unitsperissue => 2,
63
    issuesperunit => 1
64
});
65
is($subscription->guess_enddate, '2018-01-15');
66
67
$frequency->update({
68
    unit => 'day',
69
    unitsperissue => 1,
70
    issuesperunit => 2
71
});
72
is($subscription->guess_enddate, '2018-01-04');
73
74
$frequency->update({
75
    unit => 'week',
76
    unitsperissue => 1,
77
    issuesperunit => 1
78
});
79
is($subscription->guess_enddate, '2018-02-19');
80
81
$frequency->update({
82
    unit => 'week',
83
    unitsperissue => 2,
84
    issuesperunit => 1
85
});
86
is($subscription->guess_enddate, '2018-04-09');
87
88
$frequency->update({
89
    unit => 'week',
90
    unitsperissue => 1,
91
    issuesperunit => 2
92
});
93
is($subscription->guess_enddate, '2018-01-25');
94
95
$frequency->update({
96
    unit => 'month',
97
    unitsperissue => 1,
98
    issuesperunit => 1
99
});
100
is($subscription->guess_enddate, '2018-08-01');
101
102
$frequency->update({
103
    unit => 'month',
104
    unitsperissue => 2,
105
    issuesperunit => 1
106
});
107
is($subscription->guess_enddate, '2019-03-01');
108
109
$frequency->update({
110
    unit => 'month',
111
    unitsperissue => 1,
112
    issuesperunit => 2
113
});
114
is($subscription->guess_enddate, '2018-04-01');
115
116
$frequency->update({
117
    unit => 'year',
118
    unitsperissue => 1,
119
    issuesperunit => 1
120
});
121
is($subscription->guess_enddate, '2025-01-01');
122
123
$frequency->update({
124
    unit => 'year',
125
    unitsperissue => 2,
126
    issuesperunit => 1
127
});
128
is($subscription->guess_enddate, '2032-01-01');
129
130
$frequency->update({
131
    unit => 'year',
132
    unitsperissue => 1,
133
    issuesperunit => 2
134
});
135
is($subscription->guess_enddate, '2021-01-01');
136
137
138
$subscription->numberlength(0);
139
$subscription->weeklength(2);
140
$subscription->store;
141
is($subscription->guess_enddate, '2018-01-15');
142
143
$subscription->weeklength(0);
144
$subscription->monthlength(1);
145
$subscription->store;
146
is($subscription->guess_enddate, '2018-02-01');
147
148
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Subscription/Irregularities.t (+175 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
# 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;
(-)a/t/db_dependent/Serials/SubscriptionIrregularity.t (-1 / +35 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 => 6;
7
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
    source => 'Subscription',
19
    value  => {
20
        irregularity => '2;4;7',
21
        permanent_irregularity => '1;2'
22
    },
23
});
24
25
my $subscription_o = Koha::Subscriptions->find($subscription->{subscriptionid});
26
my @irreg = $subscription_o->irregularities;
27
is($irreg[0], 2, 'First element of irregularities is 2');
28
is($irreg[1], 4, 'Second element of irregularities is 4');
29
is($irreg[2], 7, 'Third element of irregularities is 7');
30
31
my @permanent_irreg = $subscription_o->permanent_irregularities;
32
is($permanent_irreg[0], 1, 'First element of permanent_irregularities is 1');
33
is($permanent_irreg[1], 2, 'Second element of permanent_irregularities is 2');
34
35
$schema->storage->txn_rollback;

Return to bug 17656