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

(-)a/C4/Serials.pm (-71 / +71 lines)
Lines 87-92 BEGIN { Link Here
87
      &CountIssues
87
      &CountIssues
88
      HasItems
88
      HasItems
89
      &subscriptionCurrentlyOnOrder
89
      &subscriptionCurrentlyOnOrder
90
      &issue_number
90
91
91
    );
92
    );
92
}
93
}
Lines 1263-1299 sub ModNextExpected { Link Here
1263
1264
1264
}
1265
}
1265
1266
1266
=head2 GetSubscriptionIrregularities
1267
1268
=over 4
1269
1270
=item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1271
get the list of irregularities for a subscription
1272
1273
=back
1274
1275
=cut
1276
1277
sub GetSubscriptionIrregularities {
1278
    my $subscriptionid = shift;
1279
1280
    return unless $subscriptionid;
1281
1282
    my $dbh = C4::Context->dbh;
1283
    my $query = qq{
1284
        SELECT irregularity
1285
        FROM subscription
1286
        WHERE subscriptionid = ?
1287
    };
1288
    my $sth = $dbh->prepare($query);
1289
    $sth->execute($subscriptionid);
1290
1291
    my ($result) = $sth->fetchrow_array;
1292
    my @irreg = split /;/, $result;
1293
1294
    return @irreg;
1295
}
1296
1297
=head2 ModSubscription
1267
=head2 ModSubscription
1298
1268
1299
this function modifies a subscription. Put all new values on input args.
1269
this function modifies a subscription. Put all new values on input args.
Lines 1304-1310 returns the number of rows affected Link Here
1304
sub ModSubscription {
1274
sub ModSubscription {
1305
    my (
1275
    my (
1306
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1276
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1307
    $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale,
1277
    $periodicity, $firstacquidate, $irregularity, $permanent_irregularity, $numberpattern, $locale,
1308
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1278
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1309
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1279
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1310
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1280
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
Lines 1338-1343 sub ModSubscription { Link Here
1338
            letter            => $letter,
1308
            letter            => $letter,
1339
            firstacquidate    => $firstacquidate,
1309
            firstacquidate    => $firstacquidate,
1340
            irregularity      => $irregularity,
1310
            irregularity      => $irregularity,
1311
            permanent_irregularity  => $permanent_irregularity,
1341
            numberpattern     => $numberpattern,
1312
            numberpattern     => $numberpattern,
1342
            locale            => $locale,
1313
            locale            => $locale,
1343
            callnumber        => $callnumber,
1314
            callnumber        => $callnumber,
Lines 1388-1438 sub NewSubscription { Link Here
1388
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1359
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1389
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1360
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1390
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1361
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1391
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1362
    $permanent_irregularity, $numberpattern, $locale, $callnumber, $manualhistory,
1392
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1363
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1393
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1364
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1394
    ) = @_;
1365
    ) = @_;
1395
    my $dbh = C4::Context->dbh;
1366
    my $dbh = C4::Context->dbh;
1396
1367
1397
    my $subscription = Koha::Subscription->new(
1368
    my $subscription = Koha::Subscription->new(
1398
        {
1369
        {
1399
            librarian         => $auser,
1370
            librarian               => $auser,
1400
            branchcode        => $branchcode,
1371
            branchcode              => $branchcode,
1401
            aqbooksellerid    => $aqbooksellerid,
1372
            aqbooksellerid          => $aqbooksellerid,
1402
            cost              => $cost,
1373
            cost                    => $cost,
1403
            aqbudgetid        => $aqbudgetid,
1374
            aqbudgetid              => $aqbudgetid,
1404
            biblionumber      => $biblionumber,
1375
            biblionumber            => $biblionumber,
1405
            startdate         => $startdate,
1376
            startdate               => $startdate,
1406
            periodicity       => $periodicity,
1377
            periodicity             => $periodicity,
1407
            numberlength      => $numberlength,
1378
            numberlength            => $numberlength,
1408
            weeklength        => $weeklength,
1379
            weeklength              => $weeklength,
1409
            monthlength       => $monthlength,
1380
            monthlength             => $monthlength,
1410
            lastvalue1        => $lastvalue1,
1381
            lastvalue1              => $lastvalue1,
1411
            innerloop1        => $innerloop1,
1382
            innerloop1              => $innerloop1,
1412
            lastvalue2        => $lastvalue2,
1383
            lastvalue2              => $lastvalue2,
1413
            innerloop2        => $innerloop2,
1384
            innerloop2              => $innerloop2,
1414
            lastvalue3        => $lastvalue3,
1385
            lastvalue3              => $lastvalue3,
1415
            innerloop3        => $innerloop3,
1386
            innerloop3              => $innerloop3,
1416
            status            => $status,
1387
            status                  => $status,
1417
            notes             => $notes,
1388
            notes                   => $notes,
1418
            letter            => $letter,
1389
            letter                  => $letter,
1419
            firstacquidate    => $firstacquidate,
1390
            firstacquidate          => $firstacquidate,
1420
            irregularity      => $irregularity,
1391
            irregularity            => $irregularity,
1421
            numberpattern     => $numberpattern,
1392
            permanent_irregularity  => $permanent_irregularity,
1422
            locale            => $locale,
1393
            numberpattern           => $numberpattern,
1423
            callnumber        => $callnumber,
1394
            locale                  => $locale,
1424
            manualhistory     => $manualhistory,
1395
            callnumber              => $callnumber,
1425
            internalnotes     => $internalnotes,
1396
            manualhistory           => $manualhistory,
1426
            serialsadditems   => $serialsadditems,
1397
            internalnotes           => $internalnotes,
1427
            staffdisplaycount => $staffdisplaycount,
1398
            serialsadditems         => $serialsadditems,
1428
            opacdisplaycount  => $opacdisplaycount,
1399
            staffdisplaycount       => $staffdisplaycount,
1429
            graceperiod       => $graceperiod,
1400
            opacdisplaycount        => $opacdisplaycount,
1430
            location          => $location,
1401
            graceperiod             => $graceperiod,
1431
            enddate           => $enddate,
1402
            location                => $location,
1432
            skip_serialseq    => $skip_serialseq,
1403
            enddate                 => $enddate,
1433
            itemtype          => $itemtype,
1404
            skip_serialseq          => $skip_serialseq,
1434
            previousitemtype  => $previousitemtype,
1405
            itemtype                => $itemtype,
1435
            mana_id           => $mana_id,
1406
            previousitemtype        => $previousitemtype,
1407
            mana_id                 => $mana_id,
1436
        }
1408
        }
1437
    )->store;
1409
    )->store;
1438
    $subscription->discard_changes;
1410
    $subscription->discard_changes;
Lines 2687-2692 sub findSerialsByStatus { Link Here
2687
    return @$serials;
2659
    return @$serials;
2688
}
2660
}
2689
2661
2662
=head2 issue_number
2663
2664
    my $week_number = issue_number($dt, 'week');
2665
2666
=cut
2667
2668
sub issue_number {
2669
    my ($date, $issue_type) = @_;
2670
2671
    unless ( ref($date) eq 'DateTime' ) {
2672
        Koha::Exceptions::WrongParameter->throw("Date passed to issue_number is not a valid DateTime object" );
2673
    }
2674
2675
    if ($issue_type eq 'day') {
2676
        return $date->dow;
2677
    }
2678
2679
    if ($issue_type eq 'week') {
2680
        return $date->week_number;
2681
    }
2682
2683
    if ($issue_type eq 'month') {
2684
        return $date->month;
2685
    }
2686
2687
    return 0;
2688
}
2689
2690
1;
2690
1;
2691
__END__
2691
__END__
2692
2692
(-)a/Koha/Subscription.pm (-1 / +130 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Carp;
22
use Carp;
23
23
24
use C4::Serials::Frequency;
25
use C4::Serials qw(issue_number);
26
24
use Koha::Database;
27
use Koha::Database;
25
use Koha::Biblios;
28
use Koha::Biblios;
26
use Koha::Acquisition::Booksellers;
29
use Koha::Acquisition::Booksellers;
Lines 28-34 use Koha::Biblioitems; Link Here
28
use Koha::Subscriptions;
31
use Koha::Subscriptions;
29
use Koha::Subscription::Frequencies;
32
use Koha::Subscription::Frequencies;
30
use Koha::Subscription::Numberpatterns;
33
use Koha::Subscription::Numberpatterns;
34
use Koha::DateUtils;
31
use JSON;
35
use JSON;
36
use Date::Calc qw( Delta_Days Add_Delta_Days Add_Delta_YM );
32
37
33
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
38
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
34
39
Lines 197-203 sub get_sharable_info { Link Here
197
}
202
}
198
203
199
204
200
=head3 _type
205
=head2 irregularities
206
207
Returns an array containing irregularities
208
209
=cut
210
211
sub irregularities {
212
    my ($self) = @_;
213
214
    return split(';', $self->irregularity);
215
}
216
217
=head2 permanent_irregularities
218
219
Returns an array containing permanent irregularities
220
221
=cut
222
223
sub permanent_irregularities {
224
    my ($self) = @_;
225
226
    return split(';', $self->permanent_irregularity);
227
}
228
229
=head3 lengthtype
230
231
Return the length type (issues, weeks, months)
232
233
=cut
234
235
sub lengthtype {
236
    my ($self) = @_;
237
238
    if ($self->numberlength) {
239
        return 'issues';
240
    }
241
242
    if ($self->weeklength) {
243
        return 'weeks';
244
    }
245
246
    if ($self->monthlength) {
247
        return 'months';
248
    }
249
}
250
251
=head3 guess_irregularities
252
253
my @irregularities = $subscription->guess_irregularities
254
255
=cut
256
257
sub guess_irregularities {
258
    my ($self) = @_;
259
260
    my @irregularities;
261
    my %permanent_irregularities = map { $_ => 1 } $self->permanent_irregularities;
262
263
    my $schema = Koha::Database->new->schema;
264
    my $frequency = $schema->resultset('SubscriptionFrequency')->find($self->periodicity);
265
266
    my $enddate = $self->enddate;
267
    my $nextexpected = C4::Serials::GetNextExpected($self->id);
268
    my $date = $nextexpected->{planneddate};
269
270
    my ($issuenumber) = C4::Serials::GetFictiveIssueNumber($self->unblessed, $date);
271
    my $dow = issue_number( dt_from_string($date), $frequency->unit );
272
273
    if ( defined( $permanent_irregularities{$dow} ) ) {
274
        push @irregularities, $issuenumber;
275
    }
276
277
    while ( Delta_Days( split(/-/, $date), split(/-/, $enddate) ) >= 0 ) {
278
        $issuenumber++;
279
        $date = C4::Serials::GetNextDate($self->unblessed, $date);
280
        $dow = issue_number( dt_from_string($date), $frequency->unit );
281
282
        if ( defined( $permanent_irregularities{$dow} ) ) {
283
            push @irregularities, $issuenumber;
284
        }
285
    }
286
287
    return @irregularities;
288
}
289
290
=head2 guess_enddate
291
292
my $enddate = $subscription->guess_enddate;
293
294
=cut
295
296
sub guess_enddate {
297
    my ($self) = @_;
298
299
    my ($year, $month, $day, $enddate);
300
    my $startdate = $self->startdate;
301
    my $numberlength = $self->numberlength;
302
    my $weeklength = $self->weeklength;
303
    my $monthlength = $self->monthlength;
304
305
    if($numberlength != 0) {
306
        my $frequency = GetSubscriptionFrequency($self->periodicity);
307
        if($frequency->{'unit'} eq 'day') {
308
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
309
        } elsif($frequency->{'unit'} eq 'week') {
310
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
311
        } elsif($frequency->{'unit'} eq 'month') {
312
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
313
        } elsif($frequency->{'unit'} eq 'year') {
314
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
315
        }
316
    } elsif($weeklength != 0) {
317
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $weeklength * 7);
318
    } elsif($monthlength != 0) {
319
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), 0, $monthlength);
320
    }
321
    if(defined $year) {
322
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
323
    } else {
324
        undef $enddate;
325
    }
326
    return $enddate;
327
}
328
329
=head3 type
201
330
202
=cut
331
=cut
203
332
(-)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 4779-4784 CREATE TABLE `subscription` ( Link Here
4779
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
4779
  `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date',
4780
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
4780
  `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually',
4781
  `irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any irregularities in the subscription',
4781
  `irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any irregularities in the subscription',
4782
  `permanent_irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permanent irregularities for renewal',
4782
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
4783
  `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0,
4783
  `letter` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4784
  `letter` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4784
  `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id',
4785
  `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 4426-4431 div .suggestion_note { Link Here
4426
    }
4426
    }
4427
}
4427
}
4428
4428
4429
.week-columns{
4430
    -moz-column-count: 2; /* Firefox */
4431
    -webkit-column-count: 2; /* Safari and Chrome */
4432
    column-count: 3;
4433
}
4434
4435
fieldset.rows label.inline {
4436
    float: none;
4437
}
4438
4429
@media (min-width: 200px) {
4439
@media (min-width: 200px) {
4430
4440
4431
}
4441
}
(-)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 587-592 fieldset.rows table { clear: none; margin: 0; } Link Here
587
587
588
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | $raw %];
588
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | $raw %];
589
    </script>
589
    </script>
590
    [% Asset.js("js/subscription.js") | $raw %]
590
    [% Asset.js("js/subscription-add.js") | $raw %]
591
    [% Asset.js("js/subscription-add.js") | $raw %]
591
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
592
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
592
[% END %]
593
[% 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 (-76 / +1 lines)
Lines 266-341 function restoreAdvancedPattern() { Link Here
266
    advancedpatternlocked = 1;
266
    advancedpatternlocked = 1;
267
}
267
}
268
268
269
function testPredictionPattern() {
270
    var frequencyid = $("#frequency").val();
271
    var acquidate;
272
    var error = 0;
273
    var error_msg = "";
274
    if(frequencyid == undefined || frequencyid == ""){
275
        error_msg += "- " + MSG_FREQUENCY_UNDEFINED + "\n";
276
        error ++;
277
    }
278
    acquidate = $("#acqui_date").val();
279
    if(acquidate == undefined || acquidate == ""){
280
        error_msg += "-" + MSG_PUB_DATE_UNDEFINED + "\n";
281
        error ++;
282
    }
283
    if( more_than_one_serial !== "" ){
284
        var nextacquidate = $("#nextacquidate").val();
285
        if(nextacquidate == undefined || nextacquidate == ""){
286
            error_msg += "-" + MSG_NEXT_ISSUE_UNDEFINED + "\n";
287
            error ++;
288
        }
289
    }
290
291
    if(error){
292
        alert( MSG_PATTERN_TEST_FAILED.format(error_msg) );
293
        return false;
294
    }
295
296
    var custompattern = 0;
297
    if(advancedpatternlocked == 0) {
298
        custompattern = 1;
299
    }
300
301
    var ajaxData = {
302
        'custompattern': custompattern,
303
        'firstacquidate': acquidate
304
    };
305
306
    if( subscriptionid !== "" ){
307
        ajaxData.subscriptionid = subscriptionid;
308
    }
309
    if( more_than_one_serial !== "" ){
310
        ajaxData.nextacquidate = nextacquidate;
311
    }
312
313
314
    var ajaxParams = [
315
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
316
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
317
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
318
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
319
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale',
320
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
321
    ];
322
    for(i in ajaxParams) {
323
        var param = ajaxParams[i];
324
        var value = $("#"+param).val();
325
        if(value.length > 0)
326
            ajaxData[param] = value;
327
    }
328
329
    $.ajax({
330
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
331
        data: ajaxData,
332
        success: function(data) {
333
            showPredictionPatternTest( data );
334
            patternneedtobetested = 0;
335
        }
336
    });
337
}
338
339
function saveAdvancedPattern() {
269
function saveAdvancedPattern() {
340
    if ($("#patternname").val().length == 0) {
270
    if ($("#patternname").val().length == 0) {
341
        alert( MSG_PATTERN_NAME );
271
        alert( MSG_PATTERN_NAME );
Lines 530-547 function mana_comment_close(){ Link Here
530
    $("#new_mana_comment").hide();
460
    $("#new_mana_comment").hide();
531
}
461
}
532
462
533
function showPredictionPatternTest( data ){
534
    $("#displayexample").html(data).show();
535
    $("#page_2 > div").attr("class","col-xs-6");
536
}
537
538
function hidePredcitionPatternTest(){
463
function hidePredcitionPatternTest(){
539
    $("#displayexample").hide();
464
    $("#displayexample").hide();
540
    $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2");
465
    $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2");
541
}
466
}
542
467
543
$(document).ready(function() {
468
$(document).ready(function() {
544
    if ( mana_enabled == 1 ) {
469
    if ( typeof mana_enabled !== 'undefined'&& mana_enabled == 1 ) {
545
        mana_search();
470
        mana_search();
546
    }
471
    }
547
    $("#displayexample").hide();
472
    $("#displayexample").hide();
(-)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 (-35 / +34 lines)
Lines 255-286 sub get_letter_loop { Link Here
255
    ];
255
    ];
256
}
256
}
257
257
258
sub _guess_enddate {
258
sub _get_sub_length {
259
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
259
    my ($type, $length) = @_;
260
    my ($year, $month, $day);
260
    return
261
    my $enddate;
261
        (
262
    if($numberlength != 0) {
262
            $type eq 'issues' ? $length : 0,
263
        my $frequency = GetSubscriptionFrequency($frequencyid);
263
            $type eq 'weeks'   ? $length : 0,
264
        if($frequency->{'unit'} eq 'day') {
264
            $type eq 'months'  ? $length : 0,
265
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
265
        );
266
        } elsif($frequency->{'unit'} eq 'week') {
267
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
268
        } elsif($frequency->{'unit'} eq 'month') {
269
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
270
        } elsif($frequency->{'unit'} eq 'year') {
271
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
272
        }
273
    } elsif($weeklength != 0) {
274
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
275
    } elsif($monthlength != 0) {
276
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
277
    }
278
    if(defined $year) {
279
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
280
    } else {
281
        undef $enddate;
282
    }
283
    return $enddate;
284
}
266
}
285
267
286
sub redirect_add_subscription {
268
sub redirect_add_subscription {
Lines 304-309 sub redirect_add_subscription { Link Here
304
    my $cost           = $query->param('cost');
286
    my $cost           = $query->param('cost');
305
    my $aqbudgetid     = $query->param('aqbudgetid');
287
    my $aqbudgetid     = $query->param('aqbudgetid');
306
    my @irregularity   = $query->multi_param('irregularity');
288
    my @irregularity   = $query->multi_param('irregularity');
289
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
307
    my $locale         = $query->param('locale');
290
    my $locale         = $query->param('locale');
308
    my $graceperiod    = $query->param('graceperiod') || 0;
291
    my $graceperiod    = $query->param('graceperiod') || 0;
309
292
Lines 344-362 sub redirect_add_subscription { Link Here
344
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
327
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
345
328
346
    if(!defined $enddate || $enddate eq '') {
329
    if(!defined $enddate || $enddate eq '') {
330
        my $subscription = Koha::Subscriptions->new({
331
            startdate       => $startdate,
332
            periodicity     => $periodicity,
333
            weeklength      => $weeklength,
334
            monthlength     =>$monthlength,
335
            numberlength    => $numberlength
336
        });
337
347
        if($subtype eq "issues") {
338
        if($subtype eq "issues") {
348
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength)
339
            $subscription->startdate($firstacquidate);
349
        } else {
350
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
351
        }
340
        }
341
        $enddate = $subscription->guess_enddate;
352
    }
342
    }
353
    my $subscriptionid = NewSubscription(
343
    my $subscriptionid = NewSubscription(
354
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
344
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
355
        $startdate, $periodicity, $numberlength, $weeklength,
345
        $startdate, $periodicity, $numberlength, $weeklength,
356
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
346
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
357
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
347
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
358
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
348
        join(";",@irregularity), join(';', @permanent_irregularity), $numberpattern, $locale,
359
        $manualhistory, $internalnotes, $serialsadditems,
349
        $callnumber, $manualhistory, $internalnotes, $serialsadditems,
360
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
350
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
361
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
351
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
362
    );
352
    );
Lines 390-395 sub redirect_add_subscription { Link Here
390
sub redirect_mod_subscription {
380
sub redirect_mod_subscription {
391
    my $subscriptionid = $query->param('subscriptionid');
381
    my $subscriptionid = $query->param('subscriptionid');
392
    my @irregularity = $query->multi_param('irregularity');
382
    my @irregularity = $query->multi_param('irregularity');
383
    my @permanent_irregularity = $query->multi_param('permanent_irregularity');
393
    my $auser = $query->param('user');
384
    my $auser = $query->param('user');
394
    my $librarian => scalar $query->param('librarian'),
385
    my $librarian => scalar $query->param('librarian'),
395
    my $branchcode = $query->param('branchcode');
386
    my $branchcode = $query->param('branchcode');
Lines 457-467 sub redirect_mod_subscription { Link Here
457
448
458
    # Guess end date
449
    # Guess end date
459
    if(!defined $enddate || $enddate eq '') {
450
    if(!defined $enddate || $enddate eq '') {
451
        my $subscription = Koha::Subscriptions->new({
452
            startdate       => $startdate,
453
            periodicity     => $periodicity,
454
            weeklength      => $weeklength,
455
            monthlength     =>$monthlength,
456
            numberlength    => $numberlength
457
        });
458
460
        if($subtype eq "issues") {
459
        if($subtype eq "issues") {
461
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
460
            $subscription->startdate($nextacquidate);
462
        } else {
463
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
464
        }
461
        }
462
        $enddate = $subscription->guess_enddate;
465
    }
463
    }
466
464
467
    my $nextexpected = GetNextExpected($subscriptionid);
465
    my $nextexpected = GetNextExpected($subscriptionid);
Lines 475-481 sub redirect_mod_subscription { Link Here
475
    ModSubscription(
473
    ModSubscription(
476
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
474
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
477
        $periodicity, $firstacquidate, join(";",@irregularity),
475
        $periodicity, $firstacquidate, join(";",@irregularity),
478
        $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1,
476
        join(';', @permanent_irregularity), $numberpattern, $locale,
477
        $numberlength, $weeklength, $monthlength, $lastvalue1,
479
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
478
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
480
        $status, $biblionumber, $callnumber, $notes, $letter,
479
        $status, $biblionumber, $callnumber, $notes, $letter,
481
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
480
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
(-)a/serials/subscription-renew.pl (-2 / +51 lines)
Lines 53-58 use C4::Context; Link Here
53
use C4::Auth;
53
use C4::Auth;
54
use C4::Output;
54
use C4::Output;
55
use C4::Serials;
55
use C4::Serials;
56
use C4::Serials::Frequency;
57
use C4::Serials::Numberpattern;
58
use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM);
56
use Koha::DateUtils;
59
use Koha::DateUtils;
57
60
58
my $query = CGI->new;
61
my $query = CGI->new;
Lines 82-87 if ( $op eq "renew" ) { Link Here
82
    # Make sure the subscription exists
85
    # Make sure the subscription exists
83
    my $subscription = GetSubscription( $subscriptionid );
86
    my $subscription = GetSubscription( $subscriptionid );
84
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
87
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
88
89
    my @permanent_irregularities = $query->param('permanent_irregularity');
90
    my @irregularities = $query->param('irregularity');
85
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
91
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
86
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
92
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
87
    ReNewSubscription(
93
    ReNewSubscription(
Lines 96-101 if ( $op eq "renew" ) { Link Here
96
            branchcode     => $branchcode
102
            branchcode     => $branchcode
97
        }
103
        }
98
    );
104
    );
105
106
    $subscription = Koha::Subscriptions->find($subscriptionid);
107
    $subscription->permanent_irregularity(join(';', @permanent_irregularities));
108
    $subscription->irregularity(join(';', @irregularities));
109
    $subscription->store;
99
} elsif ( $op eq 'multi_renew' ) {
110
} elsif ( $op eq 'multi_renew' ) {
100
    for my $subscriptionid ( @subscriptionids ) {
111
    for my $subscriptionid ( @subscriptionids ) {
101
        my $subscription = GetSubscription( $subscriptionid );
112
        my $subscription = GetSubscription( $subscriptionid );
Lines 110-115 if ( $op eq "renew" ) { Link Here
110
                monthlength    => $subscription->{monthlength},
121
                monthlength    => $subscription->{monthlength},
111
            }
122
            }
112
        );
123
        );
124
125
        $subscription = Koha::Subscriptions->find( $subscriptionid );
126
        my @irregularities = $subscription->guess_irregularities;
127
        $subscription->irregularity( join(';', @irregularities) )->store;
113
    }
128
    }
114
} else {
129
} else {
115
    my $subscriptionid = $subscriptionids[0];
130
    my $subscriptionid = $subscriptionids[0];
Lines 123-136 if ( $op eq "renew" ) { Link Here
123
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
138
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
124
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
139
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
125
140
141
    my ($serials_number) = GetSerials($subscriptionid);
142
    if ($serials_number > 1) {
143
        $template->param(more_than_one_serial => 1);
144
    }
145
146
    my $subscription_o = Koha::Subscriptions->find($subscription->{subscriptionid});
147
    my $lengthtype = $subscription_o->lengthtype;
148
    my $nextexpected = GetNextExpected($subscriptionid);
149
    $subscription_o->update({
150
        startdate       => $subscription->{enddate},
151
        periodicity     => $subscription->{periodicity},
152
        weeklength      => $subscription->{weeklength},
153
        monthlength     => $subscription->{monthlength},
154
        numberlength    => $subscription->{numberlength}
155
    });
156
    my $enddate = $subscription_o->guess_enddate;
157
158
    my $sub_length;
159
    foreach my $length_unit (qw(numberlength weeklength monthlength)) {
160
        if ($subscription->{$length_unit}) {
161
            $sub_length=$subscription->{$length_unit};
162
            last;
163
        }
164
    }
165
166
    my $numberpattern = GetSubscriptionNumberpattern($subscription->{numberpattern});
167
126
    $template->param(
168
    $template->param(
127
        startdate      => $newstartdate,
169
        startdate       => $newstartdate,
128
        subscription   => $subscription,
170
        subscription    => $subscription,
171
        numberpattern   => $numberpattern,
172
        startdate       => $newstartdate,
173
        nextacquidate   => $nextexpected->{planneddate},
174
        enddate         => $enddate,
175
        lengthtype      => $lengthtype,
176
        sublength       => $sub_length,
129
    );
177
    );
130
}
178
}
131
179
132
$template->param(
180
$template->param(
133
    op => $op,
181
    op => $op,
182
    popup => ($mode eq 'popup'),
134
);
183
);
135
184
136
output_html_with_http_headers $query, $cookie, $template->output;
185
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