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

(-)a/C4/Serials.pm (-71 / +72 lines)
Lines 99-104 BEGIN { Link Here
99
      HasItems
99
      HasItems
100
100
101
      findSerialsByStatus
101
      findSerialsByStatus
102
      &subscriptionCurrentlyOnOrder
103
      &issue_number
102
104
103
    );
105
    );
104
}
106
}
Lines 1272-1308 sub ModNextExpected { Link Here
1272
1274
1273
}
1275
}
1274
1276
1275
=head2 GetSubscriptionIrregularities
1276
1277
=over 4
1278
1279
=item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1280
get the list of irregularities for a subscription
1281
1282
=back
1283
1284
=cut
1285
1286
sub GetSubscriptionIrregularities {
1287
    my $subscriptionid = shift;
1288
1289
    return unless $subscriptionid;
1290
1291
    my $dbh = C4::Context->dbh;
1292
    my $query = qq{
1293
        SELECT irregularity
1294
        FROM subscription
1295
        WHERE subscriptionid = ?
1296
    };
1297
    my $sth = $dbh->prepare($query);
1298
    $sth->execute($subscriptionid);
1299
1300
    my ($result) = $sth->fetchrow_array;
1301
    my @irreg = split /;/, $result;
1302
1303
    return @irreg;
1304
}
1305
1306
=head2 ModSubscription
1277
=head2 ModSubscription
1307
1278
1308
this function modifies a subscription. Put all new values on input args.
1279
this function modifies a subscription. Put all new values on input args.
Lines 1313-1319 returns the number of rows affected Link Here
1313
sub ModSubscription {
1284
sub ModSubscription {
1314
    my (
1285
    my (
1315
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1286
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1316
    $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale,
1287
    $periodicity, $firstacquidate, $irregularity, $permanent_irregularity, $numberpattern, $locale,
1317
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1288
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1318
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1289
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1319
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1290
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
Lines 1347-1352 sub ModSubscription { Link Here
1347
            letter            => $letter,
1318
            letter            => $letter,
1348
            firstacquidate    => $firstacquidate,
1319
            firstacquidate    => $firstacquidate,
1349
            irregularity      => $irregularity,
1320
            irregularity      => $irregularity,
1321
            permanent_irregularity  => $permanent_irregularity,
1350
            numberpattern     => $numberpattern,
1322
            numberpattern     => $numberpattern,
1351
            locale            => $locale,
1323
            locale            => $locale,
1352
            callnumber        => $callnumber,
1324
            callnumber        => $callnumber,
Lines 1397-1447 sub NewSubscription { Link Here
1397
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1369
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1398
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1370
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1399
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1371
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1400
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1372
    $permanent_irregularity, $numberpattern, $locale, $callnumber, $manualhistory,
1401
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1373
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1402
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1374
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1403
    ) = @_;
1375
    ) = @_;
1404
    my $dbh = C4::Context->dbh;
1376
    my $dbh = C4::Context->dbh;
1405
1377
1406
    my $subscription = Koha::Subscription->new(
1378
    my $subscription = Koha::Subscription->new(
1407
        {
1379
        {
1408
            librarian         => $auser,
1380
            librarian               => $auser,
1409
            branchcode        => $branchcode,
1381
            branchcode              => $branchcode,
1410
            aqbooksellerid    => $aqbooksellerid,
1382
            aqbooksellerid          => $aqbooksellerid,
1411
            cost              => $cost,
1383
            cost                    => $cost,
1412
            aqbudgetid        => $aqbudgetid,
1384
            aqbudgetid              => $aqbudgetid,
1413
            biblionumber      => $biblionumber,
1385
            biblionumber            => $biblionumber,
1414
            startdate         => $startdate,
1386
            startdate               => $startdate,
1415
            periodicity       => $periodicity,
1387
            periodicity             => $periodicity,
1416
            numberlength      => $numberlength,
1388
            numberlength            => $numberlength,
1417
            weeklength        => $weeklength,
1389
            weeklength              => $weeklength,
1418
            monthlength       => $monthlength,
1390
            monthlength             => $monthlength,
1419
            lastvalue1        => $lastvalue1,
1391
            lastvalue1              => $lastvalue1,
1420
            innerloop1        => $innerloop1,
1392
            innerloop1              => $innerloop1,
1421
            lastvalue2        => $lastvalue2,
1393
            lastvalue2              => $lastvalue2,
1422
            innerloop2        => $innerloop2,
1394
            innerloop2              => $innerloop2,
1423
            lastvalue3        => $lastvalue3,
1395
            lastvalue3              => $lastvalue3,
1424
            innerloop3        => $innerloop3,
1396
            innerloop3              => $innerloop3,
1425
            status            => $status,
1397
            status                  => $status,
1426
            notes             => $notes,
1398
            notes                   => $notes,
1427
            letter            => $letter,
1399
            letter                  => $letter,
1428
            firstacquidate    => $firstacquidate,
1400
            firstacquidate          => $firstacquidate,
1429
            irregularity      => $irregularity,
1401
            irregularity            => $irregularity,
1430
            numberpattern     => $numberpattern,
1402
            permanent_irregularity  => $permanent_irregularity,
1431
            locale            => $locale,
1403
            numberpattern           => $numberpattern,
1432
            callnumber        => $callnumber,
1404
            locale                  => $locale,
1433
            manualhistory     => $manualhistory,
1405
            callnumber              => $callnumber,
1434
            internalnotes     => $internalnotes,
1406
            manualhistory           => $manualhistory,
1435
            serialsadditems   => $serialsadditems,
1407
            internalnotes           => $internalnotes,
1436
            staffdisplaycount => $staffdisplaycount,
1408
            serialsadditems         => $serialsadditems,
1437
            opacdisplaycount  => $opacdisplaycount,
1409
            staffdisplaycount       => $staffdisplaycount,
1438
            graceperiod       => $graceperiod,
1410
            opacdisplaycount        => $opacdisplaycount,
1439
            location          => $location,
1411
            graceperiod             => $graceperiod,
1440
            enddate           => $enddate,
1412
            location                => $location,
1441
            skip_serialseq    => $skip_serialseq,
1413
            enddate                 => $enddate,
1442
            itemtype          => $itemtype,
1414
            skip_serialseq          => $skip_serialseq,
1443
            previousitemtype  => $previousitemtype,
1415
            itemtype                => $itemtype,
1444
            mana_id           => $mana_id,
1416
            previousitemtype        => $previousitemtype,
1417
            mana_id                 => $mana_id,
1445
        }
1418
        }
1446
    )->store;
1419
    )->store;
1447
    $subscription->discard_changes;
1420
    $subscription->discard_changes;
Lines 2695-2700 sub findSerialsByStatus { Link Here
2695
    return @$serials;
2668
    return @$serials;
2696
}
2669
}
2697
2670
2671
=head2 issue_number
2672
2673
    my $week_number = issue_number($dt, 'week');
2674
2675
=cut
2676
2677
sub issue_number {
2678
    my ($date, $issue_type) = @_;
2679
2680
    unless ( ref($date) eq 'DateTime' ) {
2681
        Koha::Exceptions::WrongParameter->throw("Date passed to issue_number is not a valid DateTime object" );
2682
    }
2683
2684
    if ($issue_type eq 'day') {
2685
        return $date->dow;
2686
    }
2687
2688
    if ($issue_type eq 'week') {
2689
        return $date->week_number;
2690
    }
2691
2692
    if ($issue_type eq 'month') {
2693
        return $date->month;
2694
    }
2695
2696
    return 0;
2697
}
2698
2698
1;
2699
1;
2699
__END__
2700
__END__
2700
2701
(-)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 4841-4846 CREATE TABLE `subscription` ( Link Here
4841
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
4841
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
4842
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
4842
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
4843
  `irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any irregularities in the subscription',
4843
  `irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any irregularities in the subscription',
4844
  `permanent_irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permanent irregularities for renewal',
4844
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
4845
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
4845
  `letter` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4846
  `letter` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4846
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
4847
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
(-)a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss (+10 lines)
Lines 4644-4649 div .suggestion_note { Link Here
4644
    }
4644
    }
4645
}
4645
}
4646
4646
4647
.week-columns{
4648
    -moz-column-count: 2; /* Firefox */
4649
    -webkit-column-count: 2; /* Safari and Chrome */
4650
    column-count: 3;
4651
}
4652
4653
fieldset.rows label.inline {
4654
    float: none;
4655
}
4656
4647
@media (min-width: 200px) {
4657
@media (min-width: 200px) {
4648
4658
4649
}
4659
}
(-)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 564-569 fieldset.rows table { clear: none; margin: 0; } Link Here
564
        [%- END -%]
564
        [%- END -%]
565
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %];
565
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %];
566
    </script>
566
    </script>
567
    [% Asset.js("js/subscription.js") | $raw %]
567
    [% Asset.js("js/subscription-add.js") | $raw %]
568
    [% Asset.js("js/subscription-add.js") | $raw %]
568
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
569
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
569
[% END %]
570
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (+41 lines)
Lines 1-5 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
[% IF subscription %]
6
[% IF subscription %]
Lines 30-35 Link Here
30
<form name="f" action="/cgi-bin/koha/serials/subscription-renew.pl" method="post">
31
<form name="f" action="/cgi-bin/koha/serials/subscription-renew.pl" method="post">
31
		<input type="hidden" name="op" value="renew" />
32
		<input type="hidden" name="op" value="renew" />
32
		<input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
33
		<input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
34
        <input type="hidden" id="frequency" value="[% subscription.periodicity | html %]" />
35
        <input type="hidden" id="acqui_date" value="[% subscription.firstacquidate | html %]" />
36
        <input type="hidden" id="nextacquidate" value="[% nextacquidate | html %]" />
37
38
        <input type="hidden" id="to" value="[% enddate | html %]" />
39
        <input type="hidden" id="subtype" value="[% lengthtype | html %]" />
40
        <input type="hidden" id="sublength" value="[% sublength | html %]" />
41
        <input type="hidden" id="numberingmethod" value="[% numberpattern.numberingmethod | html %]" />
42
        <input type="hidden" id="lastvalue1" value="[% subscription.lastvalue1 | html %]" />
43
        <input type="hidden" id="lastvalue2" value="[% subscription.lastvalue2 | html %]" />
44
        <input type="hidden" id="lastvalue3" value="[% subscription.lastvalue3 | html %]" />
45
        <input type="hidden" id="add1" value="[% numberpattern.add1 | html %]" />
46
        <input type="hidden" id="add2" value="[% numberpattern.add2 | html %]" />
47
        <input type="hidden" id="add3" value="[% numberpattern.add3 | html %]" />
48
        <input type="hidden" id="every1" value="[% numberpattern.every1 | html %]" />
49
        <input type="hidden" id="every2" value="[% numberpattern.every2 | html %]" />
50
        <input type="hidden" id="every3" value="[% numberpattern.every3 | html %]" />
51
        <input type="hidden" id="innerloop1" value="[% subscription.innerloop1 | html %]" />
52
        <input type="hidden" id="innerloop2" value="[% subscription.innerloop2 | html %]" />
53
        <input type="hidden" id="innerloop3" value="[% subscription.innerloop3 | html %]" />
54
        <input type="hidden" id="setto1" value="[% numberpattern.setto1 | html %]" />
55
        <input type="hidden" id="setto2" value="[% numberpattern.setto2 | html %]" />
56
        <input type="hidden" id="setto3" value="[% numberpattern.setto3 | html %]" />
57
        <input type="hidden" id="numbering1" value="[% numberpattern.numbering1 | html %]" />
58
        <input type="hidden" id="numbering2" value="[% numberpattern.numbering2 | html %]" />
59
        <input type="hidden" id="numbering3" value="[% numberpattern.numbering3 | html %]" />
60
        <input type="hidden" id="whenmorethan1" value="[% numberpattern.whenmorethan1 | html %]" />
61
        <input type="hidden" id="whenmorethan2" value="[% numberpattern.whenmorethan2 | html %]" />
62
        <input type="hidden" id="whenmorethan3" value="[% numberpattern.whenmorethan3 | html %]" />
63
        <input type="hidden" id="locale" value="[% subscription.locale | html %]" />
33
		<fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
64
		<fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
34
        <ol>
65
        <ol>
35
            <li>
66
            <li>
Lines 78-83 Link Here
78
            <textarea name="note" id="note" rows="5" cols="50"></textarea>
109
            <textarea name="note" id="note" rows="5" cols="50"></textarea>
79
        </li>
110
        </li>
80
    [% END %]
111
    [% END %]
112
113
    <li id="displayexample"></li>
81
</ol>
114
</ol>
82
</fieldset>
115
</fieldset>
83
<fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
116
<fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
Lines 87-93 Link Here
87
[% MACRO jsinclude BLOCK %]
120
[% MACRO jsinclude BLOCK %]
88
    [% INCLUDE 'calendar.inc' %]
121
    [% INCLUDE 'calendar.inc' %]
89
    <script>
122
    <script>
123
        var subscriptionid = "[% subscription.subscriptionid %]";
124
        var irregularity = "[% subscription.irregularity %]";
125
        var more_than_one_serial = "[% more_than_one_serial %]";
90
        $(document).ready(function(){
126
        $(document).ready(function(){
127
            if (subscriptionid) {
128
                testPredictionPattern();
129
            }
91
            $(".close").on("click", function(e){
130
            $(".close").on("click", function(e){
92
                e.preventDefault();
131
                e.preventDefault();
93
                window.opener.location.reload(false);
132
                window.opener.location.reload(false);
Lines 95-100 Link Here
95
            });
134
            });
96
        });
135
        });
97
    </script>
136
    </script>
137
    [% Asset.js("js/subscription.js") | $raw %]
138
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
98
[% END %]
139
[% END %]
99
140
100
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
141
[% 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 535-541 function showPredictionPatternTest( data ){ Link Here
535
    $("#page_2 > div").attr("class","col-xs-6");
535
    $("#page_2 > div").attr("class","col-xs-6");
536
}
536
}
537
537
538
function hidePredcitionPatternTest(){
538
function hidePredictionPatternTest(){
539
    $("#displayexample").hide();
539
    $("#displayexample").hide();
540
    $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2");
540
    $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2");
541
}
541
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription.js (+78 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
console.log(data);
69
            showPredictionPatternTest( data );
70
            patternneedtobetested = 0;
71
        }
72
    });
73
}
74
75
function showPredictionPatternTest( data ){
76
    $("#displayexample").html(data).show();
77
    $("#page_2 > div").attr("class","col-xs-6");
78
}
(-)a/serials/showpredictionpattern.pl (-5 / +10 lines)
Lines 124-138 if(defined $subscriptionid) { Link Here
124
124
125
my @predictions_loop;
125
my @predictions_loop;
126
my ($calculated) = GetSeq(\%subscription, \%pattern);
126
my ($calculated) = GetSeq(\%subscription, \%pattern);
127
my $dow = issue_number( dt_from_string($date), $frequency->{unit} );
127
push @predictions_loop, {
128
push @predictions_loop, {
128
    number => $calculated,
129
    number => $calculated,
129
    publicationdate => $date,
130
    publicationdate => $date,
130
    issuenumber => $issuenumber,
131
    issuenumber => $issuenumber,
131
    dow => Day_of_Week(split /-/, $date),
132
    dow => $dow,
132
};
133
};
133
my @irreg = ();
134
my @irreg = ();
135
my @permanent_irreg = ();
134
if(defined $subscriptionid) {
136
if(defined $subscriptionid) {
135
    @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
137
    my $subscription_o = Koha::Subscriptions->find($subscriptionid);
138
    @irreg = $subscription_o->irregularities;
139
    @permanent_irreg = $subscription_o->permanent_irregularities;
136
    while(@irreg && $issuenumber > $irreg[0]) {
140
    while(@irreg && $issuenumber > $irreg[0]) {
137
        shift @irreg;
141
        shift @irreg;
138
    }
142
    }
Lines 151-157 while( $i < 1000 ) { Link Here
151
    }
155
    }
152
    if(defined $date){
156
    if(defined $date){
153
        $line{'publicationdate'} = $date;
157
        $line{'publicationdate'} = $date;
154
        $line{'dow'} = Day_of_Week(split /-/, $date);
158
        $line{dow} = issue_number( dt_from_string($date), $frequency->{unit} );
155
    }
159
    }
156
160
157
    # Check if we don't have exceed end date
161
    # Check if we don't have exceed end date
Lines 187-194 $template->param( Link Here
187
191
188
if ( $frequency->{unit} and not $custompattern ) {
192
if ( $frequency->{unit} and not $custompattern ) {
189
    $template->param( ask_for_irregularities => 1 );
193
    $template->param( ask_for_irregularities => 1 );
190
    if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {
194
    if ( $frequency->{unit} =~ /^(day|month|week)$/ and $frequency->{unitsperissue} == 1 ) {
191
        $template->param( daily_options => 1 );
195
        $template->param( show_irregularity_options => $frequency->{unit} );
196
        $template->param( permanent_irreg => \@permanent_irreg );
192
    }
197
    }
193
}
198
}
194
199
(-)a/serials/subscription-add.pl (-37 / +26 lines)
Lines 251-284 sub get_letter_loop { Link Here
251
    ];
251
    ];
252
}
252
}
253
253
254
sub _guess_enddate {
255
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
256
    my ($year, $month, $day);
257
    my $enddate;
258
    if($numberlength != 0) {
259
        my $frequency = GetSubscriptionFrequency($frequencyid);
260
        if($frequency->{'unit'} eq 'day') {
261
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
262
        } elsif($frequency->{'unit'} eq 'week') {
263
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
264
        } elsif($frequency->{'unit'} eq 'month') {
265
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
266
        } elsif($frequency->{'unit'} eq 'year') {
267
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
268
        }
269
    } elsif($weeklength != 0) {
270
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
271
    } elsif($monthlength != 0) {
272
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
273
    }
274
    if(defined $year) {
275
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
276
    } else {
277
        undef $enddate;
278
    }
279
    return $enddate;
280
}
281
282
sub redirect_add_subscription {
254
sub redirect_add_subscription {
283
    my $periodicity = $query->param('frequency');
255
    my $periodicity = $query->param('frequency');
284
    if ($periodicity eq 'mana') {
256
    if ($periodicity eq 'mana') {
Lines 300-305 sub redirect_add_subscription { Link Here
300
    my $cost           = $query->param('cost');
272
    my $cost           = $query->param('cost');
301
    my $aqbudgetid     = $query->param('aqbudgetid');
273
    my $aqbudgetid     = $query->param('aqbudgetid');
302
    my @irregularity   = $query->multi_param('irregularity');
274
    my @irregularity   = $query->multi_param('irregularity');
275
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
303
    my $locale         = $query->param('locale');
276
    my $locale         = $query->param('locale');
304
    my $graceperiod    = $query->param('graceperiod') || 0;
277
    my $graceperiod    = $query->param('graceperiod') || 0;
305
278
Lines 340-358 sub redirect_add_subscription { Link Here
340
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
313
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
341
314
342
    if(!defined $enddate || $enddate eq '') {
315
    if(!defined $enddate || $enddate eq '') {
316
        my $subscription = Koha::Subscriptions->new({
317
            startdate       => $startdate,
318
            periodicity     => $periodicity,
319
            weeklength      => $weeklength,
320
            monthlength     =>$monthlength,
321
            numberlength    => $numberlength
322
        });
323
343
        if($subtype eq "issues") {
324
        if($subtype eq "issues") {
344
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength)
325
            $subscription->startdate($firstacquidate);
345
        } else {
346
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
347
        }
326
        }
327
        $enddate = $subscription->guess_enddate;
348
    }
328
    }
349
    my $subscriptionid = NewSubscription(
329
    my $subscriptionid = NewSubscription(
350
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
330
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
351
        $startdate, $periodicity, $numberlength, $weeklength,
331
        $startdate, $periodicity, $numberlength, $weeklength,
352
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
332
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
353
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
333
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
354
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
334
        join(";",@irregularity), join(';', @permanent_irregularity), $numberpattern, $locale,
355
        $manualhistory, $internalnotes, $serialsadditems,
335
        $callnumber, $manualhistory, $internalnotes, $serialsadditems,
356
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
336
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
357
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
337
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
358
    );
338
    );
Lines 386-391 sub redirect_add_subscription { Link Here
386
sub redirect_mod_subscription {
366
sub redirect_mod_subscription {
387
    my $subscriptionid = $query->param('subscriptionid');
367
    my $subscriptionid = $query->param('subscriptionid');
388
    my @irregularity = $query->multi_param('irregularity');
368
    my @irregularity = $query->multi_param('irregularity');
369
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
389
    my $auser = $query->param('user');
370
    my $auser = $query->param('user');
390
    my $librarian => scalar $query->param('librarian'),
371
    my $librarian => scalar $query->param('librarian'),
391
    my $branchcode = $query->param('branchcode');
372
    my $branchcode = $query->param('branchcode');
Lines 453-463 sub redirect_mod_subscription { Link Here
453
434
454
    # Guess end date
435
    # Guess end date
455
    if(!defined $enddate || $enddate eq '') {
436
    if(!defined $enddate || $enddate eq '') {
437
        my $subscription = Koha::Subscriptions->new({
438
            startdate       => $startdate,
439
            periodicity     => $periodicity,
440
            weeklength      => $weeklength,
441
            monthlength     =>$monthlength,
442
            numberlength    => $numberlength
443
        });
444
456
        if($subtype eq "issues") {
445
        if($subtype eq "issues") {
457
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
446
            $subscription->startdate($nextacquidate);
458
        } else {
459
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
460
        }
447
        }
448
        $enddate = $subscription->guess_enddate;
461
    }
449
    }
462
450
463
    my $nextexpected = GetNextExpected($subscriptionid);
451
    my $nextexpected = GetNextExpected($subscriptionid);
Lines 471-477 sub redirect_mod_subscription { Link Here
471
    ModSubscription(
459
    ModSubscription(
472
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
460
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
473
        $periodicity, $firstacquidate, join(";",@irregularity),
461
        $periodicity, $firstacquidate, join(";",@irregularity),
474
        $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1,
462
        join(';', @permanent_irregularity), $numberpattern, $locale,
463
        $numberlength, $weeklength, $monthlength, $lastvalue1,
475
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
464
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
476
        $status, $biblionumber, $callnumber, $notes, $letter,
465
        $status, $biblionumber, $callnumber, $notes, $letter,
477
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
466
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
(-)a/serials/subscription-renew.pl (-2 / +51 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 81-86 if ( $op eq "renew" ) { Link Here
81
    # Make sure the subscription exists
84
    # Make sure the subscription exists
82
    my $subscription = GetSubscription( $subscriptionid );
85
    my $subscription = GetSubscription( $subscriptionid );
83
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
86
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
87
88
    my @permanent_irregularities = $query->param('permanent_irregularity');
89
    my @irregularities = $query->param('irregularity');
84
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
90
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
85
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
91
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
86
    ReNewSubscription(
92
    ReNewSubscription(
Lines 95-100 if ( $op eq "renew" ) { Link Here
95
            branchcode     => $branchcode
101
            branchcode     => $branchcode
96
        }
102
        }
97
    );
103
    );
104
105
    $subscription = Koha::Subscriptions->find($subscriptionid);
106
    $subscription->permanent_irregularity(join(';', @permanent_irregularities));
107
    $subscription->irregularity(join(';', @irregularities));
108
    $subscription->store;
98
} elsif ( $op eq 'multi_renew' ) {
109
} elsif ( $op eq 'multi_renew' ) {
99
    for my $subscriptionid ( @subscriptionids ) {
110
    for my $subscriptionid ( @subscriptionids ) {
100
        my $subscription = GetSubscription( $subscriptionid );
111
        my $subscription = GetSubscription( $subscriptionid );
Lines 109-114 if ( $op eq "renew" ) { Link Here
109
                monthlength    => $subscription->{monthlength},
120
                monthlength    => $subscription->{monthlength},
110
            }
121
            }
111
        );
122
        );
123
124
        $subscription = Koha::Subscriptions->find( $subscriptionid );
125
        my @irregularities = $subscription->guess_irregularities;
126
        $subscription->irregularity( join(';', @irregularities) )->store;
112
    }
127
    }
113
} else {
128
} else {
114
    my $subscriptionid = $subscriptionids[0];
129
    my $subscriptionid = $subscriptionids[0];
Lines 122-135 if ( $op eq "renew" ) { Link Here
122
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
137
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
123
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
138
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
124
139
140
    my ($serials_number) = GetSerials($subscriptionid);
141
    if ($serials_number > 1) {
142
        $template->param(more_than_one_serial => 1);
143
    }
144
145
    my $subscription_o = Koha::Subscriptions->find($subscription->{subscriptionid});
146
    my $lengthtype = $subscription_o->lengthtype;
147
    my $nextexpected = GetNextExpected($subscriptionid);
148
    $subscription_o->update({
149
        startdate       => $subscription->{enddate},
150
        periodicity     => $subscription->{periodicity},
151
        weeklength      => $subscription->{weeklength},
152
        monthlength     => $subscription->{monthlength},
153
        numberlength    => $subscription->{numberlength}
154
    });
155
    my $enddate = $subscription_o->guess_enddate;
156
157
    my $sub_length;
158
    foreach my $length_unit (qw(numberlength weeklength monthlength)) {
159
        if ($subscription->{$length_unit}) {
160
            $sub_length=$subscription->{$length_unit};
161
            last;
162
        }
163
    }
164
165
    my $numberpattern = GetSubscriptionNumberpattern($subscription->{numberpattern});
166
125
    $template->param(
167
    $template->param(
126
        startdate      => $newstartdate,
168
        startdate       => $newstartdate,
127
        subscription   => $subscription,
169
        subscription    => $subscription,
170
        numberpattern   => $numberpattern,
171
        startdate       => $newstartdate,
172
        nextacquidate   => $nextexpected->{planneddate},
173
        enddate         => $enddate,
174
        lengthtype      => $lengthtype,
175
        sublength       => $sub_length,
128
    );
176
    );
129
}
177
}
130
178
131
$template->param(
179
$template->param(
132
    op => $op,
180
    op => $op,
181
    popup => ($mode eq 'popup'),
133
);
182
);
134
183
135
output_html_with_http_headers $query, $cookie, $template->output;
184
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 106-111 subtest 'Koha::Subscription->frequency' => sub { Link Here
106
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
106
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
107
};
107
};
108
108
109
subtest 'Koha::Subscription::lengthtype' => sub {
110
    plan tests => 3;
111
112
    my $subs = $builder->build({
113
        source => 'Subscription',
114
        value => {
115
            numberlength => 7,
116
            weeklength => 0,
117
            monthlength => 0,
118
        }
119
    });
120
    my $subscription = Koha::Subscriptions->find($subs->{subscriptionid});
121
    is($subscription->lengthtype, 'issues', 'Subscription with numberlength has issues type');
122
123
    my $subs2 = $builder->build({
124
        source => 'Subscription',
125
        value => {
126
            numberlength => 0,
127
            weeklength => 52,
128
            monthlength => 0,
129
        }
130
    });
131
    my $subscription2 = Koha::Subscriptions->find($subs2->{subscriptionid});
132
    is($subscription2->lengthtype, 'weeks', 'Subscription with weeklength has weeks type');
133
134
    my $subs3 = $builder->build({
135
        source => 'Subscription',
136
        value => {
137
            numberlength => 0,
138
            weeklength => 0,
139
            monthlength => 12,
140
        }
141
    });
142
    my $subscription3 = Koha::Subscriptions->find($subs3->{subscriptionid});
143
    is($subscription3->lengthtype, 'months', 'Subscription with monthlength has months type');
144
};
145
109
my $nb_of_subs = Koha::Subscriptions->search->count;
146
my $nb_of_subs = Koha::Subscriptions->search->count;
110
my $biblio_1   = $builder->build_sample_biblio;
147
my $biblio_1   = $builder->build_sample_biblio;
111
my $bi_1       = $biblio_1->biblioitem;
148
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