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

(-)a/C4/Serials.pm (-11 / +108 lines)
Lines 49-54 use Koha::Subscription::Histories; Link Here
49
use Koha::Subscriptions;
49
use Koha::Subscriptions;
50
use Koha::Suggestions;
50
use Koha::Suggestions;
51
use Koha::TemplateUtils qw( process_tt );
51
use Koha::TemplateUtils qw( process_tt );
52
use List::Util qw( first );
53
use Locale::PO;
52
54
53
# Define statuses
55
# Define statuses
54
use constant {
56
use constant {
Lines 106-111 BEGIN { Link Here
106
108
107
      findSerialsByStatus
109
      findSerialsByStatus
108
110
111
      GetSeasonsTranslations
109
    );
112
    );
110
}
113
}
111
114
Lines 863-868 sub GetNextSeq { Link Here
863
        $newinnerloop1 = $subscription->{innerloop1} || 0;
866
        $newinnerloop1 = $subscription->{innerloop1} || 0;
864
        $newinnerloop2 = $subscription->{innerloop2} || 0;
867
        $newinnerloop2 = $subscription->{innerloop2} || 0;
865
        $newinnerloop3 = $subscription->{innerloop3} || 0;
868
        $newinnerloop3 = $subscription->{innerloop3} || 0;
869
        my $translations = $subscription->{translations};
866
        my %calc;
870
        my %calc;
867
        foreach(qw/X Y Z/) {
871
        foreach(qw/X Y Z/) {
868
            $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/);
872
            $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/);
Lines 901-915 sub GetNextSeq { Link Here
901
            }
905
            }
902
        }
906
        }
903
        if($calc{'X'}) {
907
        if($calc{'X'}) {
904
            my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale );
908
            my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale, $translations );
905
            $calculated =~ s/\{X\}/$newlastvalue1string/g;
909
            $calculated =~ s/\{X\}/$newlastvalue1string/g;
906
        }
910
        }
907
        if($calc{'Y'}) {
911
        if($calc{'Y'}) {
908
            my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale );
912
            my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale, $translations );
909
            $calculated =~ s/\{Y\}/$newlastvalue2string/g;
913
            $calculated =~ s/\{Y\}/$newlastvalue2string/g;
910
        }
914
        }
911
        if($calc{'Z'}) {
915
        if($calc{'Z'}) {
912
            my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale );
916
            my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale, $translations );
913
            $calculated =~ s/\{Z\}/$newlastvalue3string/g;
917
            $calculated =~ s/\{Z\}/$newlastvalue3string/g;
914
        }
918
        }
915
919
Lines 945-962 sub GetSeq { Link Here
945
949
946
    my $locale = $subscription->{locale};
950
    my $locale = $subscription->{locale};
947
951
952
    my $translations = $subscription->{translations};
953
948
    my $calculated = $pattern->{numberingmethod};
954
    my $calculated = $pattern->{numberingmethod};
949
955
950
    my $newlastvalue1 = $subscription->{'lastvalue1'} || 0;
956
    my $newlastvalue1 = $subscription->{'lastvalue1'} || 0;
951
    $newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale) if ($pattern->{numbering1}); # reset counter if needed.
957
    $newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale, $translations) if ($pattern->{numbering1}); # reset counter if needed.
952
    $calculated =~ s/\{X\}/$newlastvalue1/g;
958
    $calculated =~ s/\{X\}/$newlastvalue1/g;
953
959
954
    my $newlastvalue2 = $subscription->{'lastvalue2'} || 0;
960
    my $newlastvalue2 = $subscription->{'lastvalue2'} || 0;
955
    $newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale) if ($pattern->{numbering2}); # reset counter if needed.
961
    $newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale, $translations) if ($pattern->{numbering2}); # reset counter if needed.
956
    $calculated =~ s/\{Y\}/$newlastvalue2/g;
962
    $calculated =~ s/\{Y\}/$newlastvalue2/g;
957
963
958
    my $newlastvalue3 = $subscription->{'lastvalue3'} || 0;
964
    my $newlastvalue3 = $subscription->{'lastvalue3'} || 0;
959
    $newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed.
965
    $newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale, $translations) if ($pattern->{numbering3}); # reset counter if needed.
960
    $calculated =~ s/\{Z\}/$newlastvalue3/g;
966
    $calculated =~ s/\{Z\}/$newlastvalue3/g;
961
967
962
    my $dt = dt_from_string( $subscription->{firstacquidate} );
968
    my $dt = dt_from_string( $subscription->{firstacquidate} );
Lines 2522-2528 num_type can take : Link Here
2522
=cut
2528
=cut
2523
2529
2524
sub _numeration {
2530
sub _numeration {
2525
    my ($value, $num_type, $locale) = @_;
2531
    my ($value, $num_type, $locale, $translations) = @_;
2526
    $value ||= 0;
2532
    $value ||= 0;
2527
    $num_type //= '';
2533
    $num_type //= '';
2528
    $locale ||= 'en';
2534
    $locale ||= 'en';
Lines 2550-2562 sub _numeration { Link Here
2550
            ? $dt->format_cldr( "LLLL" )
2556
            ? $dt->format_cldr( "LLLL" )
2551
            : $dt->strftime("%b");
2557
            : $dt->strftime("%b");
2552
    } elsif ( $num_type =~ /^season$/ ) {
2558
    } elsif ( $num_type =~ /^season$/ ) {
2553
        my @seasons= qw( Spring Summer Fall Winter );
2554
        $value = $value % 4;
2559
        $value = $value % 4;
2555
        $string = $seasons[$value];
2560
        $string = $translations->{seasons}->[$value];
2556
    } elsif ( $num_type =~ /^seasonabrv$/ ) {
2561
    } elsif ( $num_type =~ /^seasonabrv$/ ) {
2557
        my @seasonsabrv= qw( Spr Sum Fal Win );
2558
        $value = $value % 4;
2562
        $value = $value % 4;
2559
        $string = $seasonsabrv[$value];
2563
        $string = $translations->{seasonsabrv}->[$value];
2560
    } else {
2564
    } else {
2561
        $string = $value;
2565
        $string = $value;
2562
    }
2566
    }
Lines 2618-2623 sub ReopenSubscription { Link Here
2618
    $sth->execute( EXPECTED, $subscriptionid, STOPPED );
2622
    $sth->execute( EXPECTED, $subscriptionid, STOPPED );
2619
}
2623
}
2620
2624
2625
=head2 GetSeasonsTranslations
2626
2627
Provide translations for the seasons and their abbreviations for the specified locale
2628
2629
=cut
2630
2631
sub GetSeasonsTranslations {
2632
    my ( $need_seasons, $need_seasonsabrv, $subtag ) = @_;
2633
    my @seasons        = qw( Spring Summer Fall Winter );
2634
    my @seasonsabrv    = qw( Spr Sum Fal Win );
2635
    my @error_messages = qw();
2636
2637
    my @dirs = (
2638
        C4::Context->config('intranetdir') . '/misc/translator/po',
2639
        C4::Context->config('intranetdir') . '/../../misc/translator/po',
2640
    );
2641
2642
    my $dir = first { -d } @dirs;
2643
2644
    if ($dir) {
2645
        my @po_paths = glob("$dir/$subtag*staff-prog.po");
2646
        if (@po_paths) {
2647
            my $po_path     = $po_paths[0];
2648
            my $po_filename = ( $po_path =~ s/$dir\///gr );
2649
            my $po_data     = Locale::PO->load_file_ashash( $po_path, 'utf8' );
2650
2651
            if ($need_seasons) {
2652
                my $response = _translate( $po_data, @seasons );
2653
                @seasons = @{ $response->{translations} };
2654
                @error_messages =
2655
                    ( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } );
2656
            }
2657
2658
            if ($need_seasonsabrv) {
2659
                my $response = _translate( $po_data, @seasonsabrv );
2660
                @seasonsabrv = @{ $response->{translations} };
2661
                @error_messages =
2662
                    ( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } );
2663
            }
2664
        } else {
2665
            push(
2666
                @error_messages,
2667
                "No translation file found for $subtag. Ensure that the translation files for $subtag are installed."
2668
            );
2669
        }
2670
    } else {
2671
        push( @error_messages, "The PO directory has not been found. There is a problem in your Koha installation." );
2672
    }
2673
2674
    return { seasons => \@seasons, seasonsabrv => \@seasonsabrv, error_messages => \@error_messages };
2675
}
2676
2621
=head2 subscriptionCurrentlyOnOrder
2677
=head2 subscriptionCurrentlyOnOrder
2622
2678
2623
    $bool = subscriptionCurrentlyOnOrder( $subscriptionid );
2679
    $bool = subscriptionCurrentlyOnOrder( $subscriptionid );
Lines 2712-2717 sub _can_do_on_subscription { Link Here
2712
    return 0;
2768
    return 0;
2713
}
2769
}
2714
2770
2771
=head2 _translate
2772
2773
Provide translations for the given words based on the provided data
2774
2775
=cut
2776
2777
sub _translate {
2778
    my ( $data, @words ) = @_;
2779
2780
    my @translations   = qw();
2781
    my @error_messages = qw();
2782
2783
    for my $word (@words) {
2784
        my $regex       = qr/^"$word"$|\%s$word\%s/;
2785
        my @msgids      = grep /$regex/, keys %{$data};
2786
        my $translation = "";
2787
2788
        while ( ( $translation eq "" ) && ( my $msgid = shift(@msgids) ) ) {
2789
            next unless ( $data->{$msgid}->reference =~ /serials/ );
2790
            my $msgstr = $data->{$msgid}->msgstr;
2791
            my @ids    = split( /\%s/, $msgid );
2792
            my @strs   = split( /\%s/, $msgstr );
2793
2794
            next unless ( scalar @ids == scalar @strs );
2795
2796
            my $idx = first { $ids[$_] eq $word || $ids[$_] eq $msgid } 0 .. $#ids;
2797
            $translation = Locale::PO->dequote( $strs[$idx] ) if ( defined $idx );
2798
        }
2799
2800
        if ( $translation eq "" ) {
2801
            push( @translations,   $word );
2802
            push( @error_messages, "The translation for $word doesn't exist in the file \%s" );
2803
            next;
2804
        }
2805
2806
        push( @translations, $translation );
2807
    }
2808
2809
    return { translations => \@translations, error_messages => \@error_messages };
2810
}
2811
2715
=head2 findSerialsByStatus
2812
=head2 findSerialsByStatus
2716
2813
2717
    @serials = findSerialsByStatus($status, $subscriptionid);
2814
    @serials = findSerialsByStatus($status, $subscriptionid);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt (+9 lines)
Lines 84-89 Link Here
84
  </tbody>
84
  </tbody>
85
</table>
85
</table>
86
86
87
[% IF (error_messages) %]
88
    <div class="alert alert-warning">
89
        <h4 class="alert-heading"><i class="bi-exclamation-triangle-fill"></i> Warning</h4>
90
        [% FOREACH error_message IN error_messages %]
91
            <p>[% error_message | html %]</p>
92
        [% END %]
93
    </div>
94
[% END %]
95
87
<fieldset class="action">
96
<fieldset class="action">
88
    <button class="btn btn-default btn-sm" id="hidepredictionpattern">Done</button>
97
    <button class="btn btn-default btn-sm" id="hidepredictionpattern">Done</button>
89
</fieldset>
98
</fieldset>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-2 / +3 lines)
Lines 393-404 fieldset.rows table { clear: none; margin: 0; } Link Here
393
                                            <option value=""></option>
393
                                            <option value=""></option>
394
                                            [% FOREACH l IN locales %]
394
                                            [% FOREACH l IN locales %]
395
                                                [% IF l.language == locale %]
395
                                                [% IF l.language == locale %]
396
                                                    <option value="[% l.language | html %]" selected="selected">[% l.description | html %]</option>
396
                                                    <option value="[% l.language | html %]" data-subtag="[% l.subtag | html %]" selected="selected">[% l.description | html %]</option>
397
                                                [% ELSE %]
397
                                                [% ELSE %]
398
                                                    <option value="[% l.language | html %]">[% l.description | html %]</option>
398
                                                    <option value="[% l.language | html %]" data-subtag="[% l.subtag | html %]">[% l.description | html %]</option>
399
                                                [% END %]
399
                                                [% END %]
400
                                            [% END %]
400
                                            [% END %]
401
                                        </select>
401
                                        </select>
402
                                        <input type="hidden" id="subtag" name="subtag" value="">
402
                                        <div class="hint">If empty, English is used</div>
403
                                        <div class="hint">If empty, English is used</div>
403
                                    </li>
404
                                    </li>
404
                                    <li id="more_options">
405
                                    <li id="more_options">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt (-2 / +12 lines)
Lines 220-229 Link Here
220
                  <select id="locale" name="locale">
220
                  <select id="locale" name="locale">
221
                      <option value=""></option>
221
                      <option value=""></option>
222
                      [% FOREACH locale IN locales %]
222
                      [% FOREACH locale IN locales %]
223
                        <option value="[% locale.language | html %]">[% locale.description | html %]</option>
223
                        <option value="[% locale.language | html %]" data-subtag="[% locale.subtag | html %]">[% locale.description | html %]</option>
224
                      [% END %]
224
                      [% END %]
225
                    </select>
225
                    </select>
226
                  <span class="hint">If empty, English is used</span>
226
                  <span class="hint">If empty, English is used</span>
227
                  <input type="hidden" id="subtag" name="subtag" value="">
227
                </li>
228
                </li>
228
              </ol>
229
              </ol>
229
              <table>
230
              <table>
Lines 344-349 Link Here
344
    [% INCLUDE 'calendar.inc' %]
345
    [% INCLUDE 'calendar.inc' %]
345
    [% INCLUDE 'datatables.inc' %]
346
    [% INCLUDE 'datatables.inc' %]
346
    <script>
347
    <script>
348
        function setSubtag () {
349
            $("#subtag").val($("#locale").find(':selected').data('subtag'));
350
        }
351
347
        function confirmDelete() {
352
        function confirmDelete() {
348
            return confirm(_("Are you sure you want to delete this numbering pattern?"));
353
            return confirm(_("Are you sure you want to delete this numbering pattern?"));
349
        }
354
        }
Lines 377-383 Link Here
377
                    'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
382
                    'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
378
                    'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
383
                    'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
379
                    'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
384
                    'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
380
                    'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
385
                    'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale', 'subtag'
381
                ];
386
                ];
382
                for(i in ajaxParams) {
387
                for(i in ajaxParams) {
383
                    var param = ajaxParams[i];
388
                    var param = ajaxParams[i];
Lines 420-425 Link Here
420
            $("#test_pattern").on("click",function(){
425
            $("#test_pattern").on("click",function(){
421
                 testPattern();
426
                 testPattern();
422
            });
427
            });
428
            $("#locale").on("change", function() {
429
                setSubtag();
430
            });
431
432
            setSubtag();
423
        });
433
        });
424
    </script>
434
    </script>
425
[% END %]
435
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js (-1 / +10 lines)
Lines 329-335 function testPredictionPattern() { Link Here
329
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
329
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
330
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
330
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
331
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
331
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
332
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale',
332
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale', 'subtag',
333
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
333
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
334
    ];
334
    ];
335
    for(i in ajaxParams) {
335
    for(i in ajaxParams) {
Lines 543-548 function mana_comment_close(){ Link Here
543
    $("#new_mana_comment").hide();
543
    $("#new_mana_comment").hide();
544
}
544
}
545
545
546
function setSubtag () {
547
    $("#subtag").val($("#locale").find(':selected').data('subtag'));
548
}
549
546
function showPredictionPatternTest( data ){
550
function showPredictionPatternTest( data ){
547
    $("#displayexample").html(data).show();
551
    $("#displayexample").html(data).show();
548
    $("#page_2 > div").attr("class","col-xs-6");
552
    $("#page_2 > div").attr("class","col-xs-6");
Lines 742-745 $(document).ready(function() { Link Here
742
        $(".use_items").css('display', display).find("select").val("")
746
        $(".use_items").css('display', display).find("select").val("")
743
    });
747
    });
744
748
749
    $("#locale").on("change", function() {
750
        setSubtag();
751
    });
752
753
    setSubtag();
745
});
754
});
(-)a/serials/showpredictionpattern.pl (-64 / +86 lines)
Lines 34-60 use CGI qw ( -utf8 ); Link Here
34
use Date::Calc qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days );
34
use Date::Calc qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days );
35
use C4::Auth qw( get_template_and_user );
35
use C4::Auth qw( get_template_and_user );
36
use C4::Output qw( output_html_with_http_headers );
36
use C4::Output qw( output_html_with_http_headers );
37
use C4::Serials qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq );
37
use C4::Serials
38
    qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq GetSeasonsTranslations );
38
use C4::Serials::Frequency;
39
use C4::Serials::Frequency;
39
use Koha::DateUtils qw( dt_from_string );
40
use Koha::DateUtils qw( dt_from_string );
40
41
41
my $input = CGI->new;
42
my $input = CGI->new;
42
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
43
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
43
    template_name   => 'serials/showpredictionpattern.tt',
44
    {
44
    query           => $input,
45
        template_name => 'serials/showpredictionpattern.tt',
45
    type            => 'intranet',
46
        query         => $input,
46
    flagsrequired   => { 'serials' => '*' },
47
        type          => 'intranet',
47
} );
48
        flagsrequired => { 'serials' => '*' },
49
    }
50
);
48
51
49
my $subscriptionid = $input->param('subscriptionid');
52
my $subscriptionid = $input->param('subscriptionid');
50
my $frequencyid = $input->param('frequency');
53
my $frequencyid    = $input->param('frequency');
51
my $firstacquidate = $input->param('firstacquidate');
54
my $firstacquidate = $input->param('firstacquidate');
52
my $nextacquidate = $input->param('nextacquidate');
55
my $nextacquidate  = $input->param('nextacquidate');
53
my $enddate = $input->param('to');
56
my $enddate        = $input->param('to');
54
my $subtype = $input->param('subtype');
57
my $subtype        = $input->param('subtype');
55
my $sublength = $input->param('sublength');
58
my $sublength      = $input->param('sublength');
56
my $custompattern = $input->param('custompattern');
59
my $custompattern  = $input->param('custompattern');
57
58
60
59
my $frequency;
61
my $frequency;
60
if ( $frequencyid eq 'mana' ) {
62
if ( $frequencyid eq 'mana' ) {
Lines 64-93 if ( $frequencyid eq 'mana' ) { Link Here
64
        'description'   => scalar $input->param('sfdescription') // '',
66
        'description'   => scalar $input->param('sfdescription') // '',
65
        'unitsperissue' => scalar $input->param('unitsperissue') // '',
67
        'unitsperissue' => scalar $input->param('unitsperissue') // '',
66
        'issuesperunit' => scalar $input->param('issuesperunit') // '',
68
        'issuesperunit' => scalar $input->param('issuesperunit') // '',
67
        'unit'          => scalar $input->param('unit') // ''
69
        'unit'          => scalar $input->param('unit')          // ''
68
    };
70
    };
69
}
71
} else {
70
else {
71
    $frequency = GetSubscriptionFrequency($frequencyid);
72
    $frequency = GetSubscriptionFrequency($frequencyid);
72
}
73
}
73
74
74
my %pattern = (
75
my %pattern = (
75
    numberingmethod => scalar $input->param('numberingmethod') // '',
76
    numberingmethod => scalar $input->param('numberingmethod') // '',
76
    numbering1      => scalar $input->param('numbering1') // '',
77
    numbering1      => scalar $input->param('numbering1')      // '',
77
    numbering2      => scalar $input->param('numbering2') // '',
78
    numbering2      => scalar $input->param('numbering2')      // '',
78
    numbering3      => scalar $input->param('numbering3') // '',
79
    numbering3      => scalar $input->param('numbering3')      // '',
79
    add1            => scalar $input->param('add1') // '',
80
    add1            => scalar $input->param('add1')            // '',
80
    add2            => scalar $input->param('add2') // '',
81
    add2            => scalar $input->param('add2')            // '',
81
    add3            => scalar $input->param('add3') // '',
82
    add3            => scalar $input->param('add3')            // '',
82
    whenmorethan1   => scalar $input->param('whenmorethan1') // '',
83
    whenmorethan1   => scalar $input->param('whenmorethan1')   // '',
83
    whenmorethan2   => scalar $input->param('whenmorethan2') // '',
84
    whenmorethan2   => scalar $input->param('whenmorethan2')   // '',
84
    whenmorethan3   => scalar $input->param('whenmorethan3') // '',
85
    whenmorethan3   => scalar $input->param('whenmorethan3')   // '',
85
    setto1          => scalar $input->param('setto1') // '',
86
    setto1          => scalar $input->param('setto1')          // '',
86
    setto2          => scalar $input->param('setto2') // '',
87
    setto2          => scalar $input->param('setto2')          // '',
87
    setto3          => scalar $input->param('setto3') // '',
88
    setto3          => scalar $input->param('setto3')          // '',
88
    every1          => scalar $input->param('every1') // '',
89
    every1          => scalar $input->param('every1')          // '',
89
    every2          => scalar $input->param('every2') // '',
90
    every2          => scalar $input->param('every2')          // '',
90
    every3          => scalar $input->param('every3') // '',
91
    every3          => scalar $input->param('every3')          // '',
91
);
92
);
92
93
93
$firstacquidate = $firstacquidate ? dt_from_string($firstacquidate)->ymd : dt_from_string->ymd;
94
$firstacquidate = $firstacquidate ? dt_from_string($firstacquidate)->ymd : dt_from_string->ymd;
Lines 97-173 $enddate = dt_from_string($enddate)->ymd if $enddate; Link Here
97
$nextacquidate = $nextacquidate ? dt_from_string($nextacquidate)->ymd : $firstacquidate;
98
$nextacquidate = $nextacquidate ? dt_from_string($nextacquidate)->ymd : $firstacquidate;
98
my $date = $nextacquidate;
99
my $date = $nextacquidate;
99
100
101
my $need_seasons     = grep { $_ =~ /^season$/ } %pattern;
102
my $need_seasonsabrv = grep { $_ =~ /^seasonabrv$/ } %pattern;
103
my $subtag           = scalar $input->param('subtag');
104
105
my $translations;
106
$translations = GetSeasonsTranslations( $need_seasons, $need_seasonsabrv, $subtag )
107
    if ( $need_seasons || $need_seasonsabrv );
108
100
my %subscription = (
109
my %subscription = (
101
    locale      => scalar $input->param('locale') // '',
110
    locale             => scalar $input->param('locale')     // '',
102
    lastvalue1      => scalar $input->param('lastvalue1') // '',
111
    lastvalue1         => scalar $input->param('lastvalue1') // '',
103
    lastvalue2      => scalar $input->param('lastvalue2') // '',
112
    lastvalue2         => scalar $input->param('lastvalue2') // '',
104
    lastvalue3      => scalar $input->param('lastvalue3') // '',
113
    lastvalue3         => scalar $input->param('lastvalue3') // '',
105
    innerloop1      => scalar $input->param('innerloop1') // '',
114
    innerloop1         => scalar $input->param('innerloop1') // '',
106
    innerloop2      => scalar $input->param('innerloop2') // '',
115
    innerloop2         => scalar $input->param('innerloop2') // '',
107
    innerloop3      => scalar $input->param('innerloop3') // '',
116
    innerloop3         => scalar $input->param('innerloop3') // '',
108
    irregularity    => '',
117
    irregularity       => '',
109
    countissuesperunit  => 1,
118
    countissuesperunit => 1,
110
    firstacquidate  => $firstacquidate,
119
    firstacquidate     => $firstacquidate,
120
    translations       => $translations,
111
);
121
);
112
122
113
my $issuenumber;
123
my $issuenumber;
114
if(defined $subscriptionid) {
124
if ( defined $subscriptionid ) {
115
    ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date, $frequency);
125
    ($issuenumber) = C4::Serials::GetFictiveIssueNumber( \%subscription, $date, $frequency );
116
} else {
126
} else {
117
    $issuenumber = 1;
127
    $issuenumber = 1;
118
}
128
}
119
129
120
my @predictions_loop;
130
my @predictions_loop;
121
my ($calculated) = GetSeq(\%subscription, \%pattern);
131
my ($calculated) = GetSeq( \%subscription, \%pattern );
122
push @predictions_loop, {
132
push @predictions_loop, {
123
    number => $calculated,
133
    number          => $calculated,
124
    publicationdate => $date,
134
    publicationdate => $date,
125
    issuenumber => $issuenumber,
135
    issuenumber     => $issuenumber,
126
    dow => Day_of_Week(split /-/, $date),
136
    dow             => Day_of_Week( split /-/, $date ),
127
};
137
};
128
my @irreg = ();
138
my @irreg = ();
129
if(defined $subscriptionid) {
139
if ( defined $subscriptionid ) {
130
    @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
140
    @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
131
    while(@irreg && $issuenumber > $irreg[0]) {
141
    while ( @irreg && $issuenumber > $irreg[0] ) {
132
        shift @irreg;
142
        shift @irreg;
133
    }
143
    }
134
    if(@irreg && $issuenumber == $irreg[0]){
144
    if ( @irreg && $issuenumber == $irreg[0] ) {
135
        $predictions_loop[0]->{'not_published'} = 1;
145
        $predictions_loop[0]->{'not_published'} = 1;
136
        shift @irreg;
146
        shift @irreg;
137
    }
147
    }
138
}
148
}
139
149
140
my $i = 1;
150
my $i = 1;
141
while( $i < 1000 ) {
151
while ( $i < 1000 ) {
142
    my %line;
152
    my %line;
143
153
144
    if(defined $date){
154
    if ( defined $date ) {
145
        $date = GetNextDate(\%subscription, $date, $frequency);
155
        $date = GetNextDate( \%subscription, $date, $frequency );
146
    }
156
    }
147
    if(defined $date){
157
    if ( defined $date ) {
148
        $line{'publicationdate'} = $date;
158
        $line{'publicationdate'} = $date;
149
        $line{'dow'} = Day_of_Week(split /-/, $date);
159
        $line{'dow'}             = Day_of_Week( split /-/, $date );
150
    }
160
    }
151
161
152
    # Check if we don't have exceed end date
162
    # Check if we don't have exceed end date
153
    if($sublength){
163
    if ($sublength) {
154
        if($subtype eq "issues" && $i >= $sublength){
164
        if ( $subtype eq "issues" && $i >= $sublength ) {
155
            last;
165
            last;
156
        } elsif($subtype eq "weeks" && $date && Delta_Days( split(/-/, $date), Add_Delta_Days( split(/-/, $firstacquidate), 7*$sublength - 1 ) ) < 0) {
166
        } elsif ( $subtype eq "weeks"
167
            && $date
168
            && Delta_Days( split( /-/, $date ), Add_Delta_Days( split( /-/, $firstacquidate ), 7 * $sublength - 1 ) ) <
169
            0 )
170
        {
157
            last;
171
            last;
158
        } elsif($subtype eq "months" && $date && (Delta_Days( split(/-/, $date), Add_Delta_YM( split(/-/, $firstacquidate), 0, $sublength) ) - 1) < 0 ) {
172
        } elsif ( $subtype eq "months"
173
            && $date
174
            && ( Delta_Days( split( /-/, $date ), Add_Delta_YM( split( /-/, $firstacquidate ), 0, $sublength ) ) - 1 )
175
            < 0 )
176
        {
159
            last;
177
            last;
160
        }
178
        }
161
    }
179
    }
162
    if($enddate && $date && Delta_Days( split(/-/, $date), split(/-/, $enddate) ) <= 0 ) {
180
    if ( $enddate && $date && Delta_Days( split( /-/, $date ), split( /-/, $enddate ) ) <= 0 ) {
163
        last;
181
        last;
164
    }
182
    }
165
183
166
    ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern, $frequency, $date);
184
    (
185
        $calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'},
186
        $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}
187
    ) = GetNextSeq( \%subscription, \%pattern, $frequency, $date );
167
    $issuenumber++;
188
    $issuenumber++;
168
    $line{'number'} = $calculated;
189
    $line{'number'}      = $calculated;
169
    $line{'issuenumber'} = $issuenumber;
190
    $line{'issuenumber'} = $issuenumber;
170
    if(@irreg && $issuenumber == $irreg[0]){
191
    if ( @irreg && $issuenumber == $irreg[0] ) {
171
        $line{'not_published'} = 1;
192
        $line{'not_published'} = 1;
172
        shift @irreg;
193
        shift @irreg;
173
    }
194
    }
Lines 178-183 while( $i < 1000 ) { Link Here
178
199
179
$template->param(
200
$template->param(
180
    predictions_loop => \@predictions_loop,
201
    predictions_loop => \@predictions_loop,
202
    error_messages   => \@{ $translations->{error_messages} },
181
);
203
);
182
204
183
if ( $frequency->{unit} and not $custompattern ) {
205
if ( $frequency->{unit} and not $custompattern ) {
(-)a/serials/subscription-add.pl (-192 / +224 lines)
Lines 23-29 use C4::Koha qw( GetAuthorisedValues ); Link Here
23
use C4::Auth qw( get_template_and_user );
23
use C4::Auth qw( get_template_and_user );
24
use C4::Output qw( output_and_exit output_html_with_http_headers );
24
use C4::Output qw( output_and_exit output_html_with_http_headers );
25
use C4::Context;
25
use C4::Context;
26
use C4::Serials qw( GetSubscription GetNextExpected GetSerials GetSubscriptionLength NewSubscription ModNextExpected ModSubscription );
26
use C4::Serials
27
    qw( GetSubscription GetNextExpected GetSerials GetSubscriptionLength NewSubscription ModNextExpected ModSubscription );
27
use C4::Serials::Frequency;
28
use C4::Serials::Frequency;
28
use C4::Serials::Numberpattern;
29
use C4::Serials::Numberpattern;
29
use C4::Letters qw( GetLetters );
30
use C4::Letters qw( GetLetters );
Lines 38-61 use Koha::Subscription::Frequency; Link Here
38
use Koha::SharedContent;
39
use Koha::SharedContent;
39
40
40
our $query = CGI->new;
41
our $query = CGI->new;
41
my $op = $query->param('op') || '';
42
my $op  = $query->param('op') || '';
42
my $dbh = C4::Context->dbh;
43
my $dbh = C4::Context->dbh;
43
my $sub_length;
44
my $sub_length;
44
45
45
46
# Permission needed if it is a modification : edit_subscription
46
# Permission needed if it is a modification : edit_subscription
47
# Permission needed otherwise (nothing or dup) : create_subscription
47
# Permission needed otherwise (nothing or dup) : create_subscription
48
my $permission =
48
my $permission = ( $op eq 'modify' || $op eq 'cud-modsubscription' ) ? "edit_subscription" : "create_subscription";
49
  ( $op eq 'modify' || $op eq 'cud-modsubscription' ) ? "edit_subscription" : "create_subscription";
49
50
50
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51
our ($template, $loggedinuser, $cookie)
51
    {
52
= get_template_and_user({template_name => "serials/subscription-add.tt",
52
        template_name => "serials/subscription-add.tt",
53
				query => $query,
53
        query         => $query,
54
				type => "intranet",
54
        type          => "intranet",
55
				flagsrequired => {serials => $permission},
55
        flagsrequired => { serials => $permission },
56
				});
56
    }
57
57
);
58
59
58
60
my $sub_on;
59
my $sub_on;
61
60
Lines 66-119 my $mana_url = C4::Context->config('mana_config'); Link Here
66
$template->param( 'mana_url' => $mana_url );
65
$template->param( 'mana_url' => $mana_url );
67
my $subscriptionid = $query->param('subscriptionid');
66
my $subscriptionid = $query->param('subscriptionid');
68
67
69
if ($op eq 'modify' || $op eq 'dup' || $op eq 'cud-modsubscription') {
68
if ( $op eq 'modify' || $op eq 'dup' || $op eq 'cud-modsubscription' ) {
70
69
71
    $subs = GetSubscription($subscriptionid);
70
    $subs = GetSubscription($subscriptionid);
72
71
73
    output_and_exit( $query, $cookie, $template, 'unknown_subscription')
72
    output_and_exit( $query, $cookie, $template, 'unknown_subscription' )
74
        unless $subs;
73
        unless $subs;
75
74
76
    ## FIXME : Check rights to edit if mod. Could/Should display an error message.
75
    ## FIXME : Check rights to edit if mod. Could/Should display an error message.
77
    if ($subs->{'cannotedit'} && $op eq 'modify'){
76
    if ( $subs->{'cannotedit'} && $op eq 'modify' ) {
78
      carp "Attempt to modify subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
77
        carp "Attempt to modify subscription $subscriptionid by " . C4::Context->userenv->{'id'} . " not allowed";
79
      print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
78
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
80
    }
79
    }
81
    $firstissuedate = $subs->{firstacquidate} || '';  # in iso format.
80
    $firstissuedate = $subs->{firstacquidate} || '';    # in iso format.
82
    if (!defined $subs->{letter}) {
81
    if ( !defined $subs->{letter} ) {
83
        $subs->{letter}= q{};
82
        $subs->{letter} = q{};
84
    }
83
    }
85
    my $nextexpected = GetNextExpected($subscriptionid);
84
    my $nextexpected = GetNextExpected($subscriptionid);
86
    $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate} eq $firstissuedate ;
85
    $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate} eq $firstissuedate;
87
    $subs->{nextacquidate} = $nextexpected->{planneddate}  if($op eq 'modify');
86
    $subs->{nextacquidate}          = $nextexpected->{planneddate} if ( $op eq 'modify' );
88
    unless($op eq 'cud-modsubscription') {
87
    unless ( $op eq 'cud-modsubscription' ) {
89
        foreach my $length_unit (qw(numberlength weeklength monthlength)) {
88
        foreach my $length_unit (qw(numberlength weeklength monthlength)) {
90
            if ($subs->{$length_unit}) {
89
            if ( $subs->{$length_unit} ) {
91
                $sub_length=$subs->{$length_unit};
90
                $sub_length = $subs->{$length_unit};
92
                $sub_on=$length_unit;
91
                $sub_on     = $length_unit;
93
                last;
92
                last;
94
            }
93
            }
95
        }
94
        }
96
95
97
        $template->param( %{$subs} );
96
        $template->param( %{$subs} );
98
        $template->param(
97
        $template->param(
99
                    $op => 1,
98
            $op               => 1,
100
                    "subtype_$sub_on" => 1,
99
            "subtype_$sub_on" => 1,
101
                    sublength =>$sub_length,
100
            sublength         => $sub_length,
102
                    history => ($op eq 'modify'),
101
            history           => ( $op eq 'modify' ),
103
                    firstacquiyear => substr($firstissuedate,0,4),
102
            firstacquiyear    => substr( $firstissuedate, 0, 4 ),
104
                    );
103
        );
105
104
106
        if($op eq 'modify') {
105
        if ( $op eq 'modify' ) {
107
            my ($serials_number) = GetSerials($subscriptionid);
106
            my ($serials_number) = GetSerials($subscriptionid);
108
            if($serials_number > 1) {
107
            if ( $serials_number > 1 ) {
109
                $template->param(more_than_one_serial => 1);
108
                $template->param( more_than_one_serial => 1 );
110
            }
109
            }
111
        }
110
        }
112
    }
111
    }
113
112
114
    if ( $op eq 'dup' ) {
113
    if ( $op eq 'dup' ) {
115
        my $dont_copy_fields = C4::Context->preference('SubscriptionDuplicateDroppedInput');
114
        my $dont_copy_fields = C4::Context->preference('SubscriptionDuplicateDroppedInput');
116
        my @fields_id = map { fieldid => $_ }, split '\|', $dont_copy_fields;
115
        my @fields_id        = map { fieldid => $_ }, split '\|', $dont_copy_fields;
117
        $template->param( dont_export_field_loop => \@fields_id );
116
        $template->param( dont_export_field_loop => \@fields_id );
118
    }
117
    }
119
118
Lines 123-134 if ($op eq 'modify' || $op eq 'dup' || $op eq 'cud-modsubscription') { Link Here
123
}
122
}
124
123
125
my $locations_loop = GetAuthorisedValues("LOC");
124
my $locations_loop = GetAuthorisedValues("LOC");
126
my $ccodes_loop     = GetAuthorisedValues("CCODE");
125
my $ccodes_loop    = GetAuthorisedValues("CCODE");
127
126
128
$template->param(
127
$template->param(
129
    branchcode => $subs->{branchcode},
128
    branchcode     => $subs->{branchcode},
130
    locations_loop=>$locations_loop,
129
    locations_loop => $locations_loop,
131
    ccodes_loop=>$ccodes_loop
130
    ccodes_loop    => $ccodes_loop
132
);
131
);
133
132
134
my @additional_fields = Koha::AdditionalFields->search({ tablename => 'subscription' })->as_list;
133
my @additional_fields = Koha::AdditionalFields->search({ tablename => 'subscription' })->as_list;
Lines 144-176 my $typeloop = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_lo Link Here
144
143
145
# FIXME We should use the translated_description for item types
144
# FIXME We should use the translated_description for item types
146
my @typearg =
145
my @typearg =
147
    map { { code => $_, value => $typeloop->{$_}{'description'}, selected => ( ( $subs->{itemtype} and $_ eq $subs->{itemtype} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$typeloop};
146
    map {
147
    {
148
        code     => $_, value => $typeloop->{$_}{'description'},
149
        selected => ( ( $subs->{itemtype} and $_ eq $subs->{itemtype} ) ? "selected=\"selected\"" : "" ),
150
    }
151
    } sort keys %{$typeloop};
148
my @previoustypearg =
152
my @previoustypearg =
149
    map { { code => $_, value => $typeloop->{$_}{'description'}, selected => ( ( $subs->{previousitemtype} and $_ eq $subs->{previousitemtype} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$typeloop};
153
    map {
154
    {
155
        code => $_, value => $typeloop->{$_}{'description'}, selected =>
156
            ( ( $subs->{previousitemtype} and $_ eq $subs->{previousitemtype} ) ? "selected=\"selected\"" : "" ),
157
    }
158
    } sort keys %{$typeloop};
150
159
151
$template->param(
160
$template->param(
152
    typeloop                 => \@typearg,
161
    typeloop         => \@typearg,
153
    previoustypeloop         => \@previoustypearg,
162
    previoustypeloop => \@previoustypearg,
154
    locations_loop=>$locations_loop,
163
    locations_loop   => $locations_loop,
155
);
164
);
156
165
157
# prepare template variables common to all $op conditions:
166
# prepare template variables common to all $op conditions:
158
$template->param('makePreviousSerialAvailable' => 1) if (C4::Context->preference('makePreviousSerialAvailable'));
167
$template->param( 'makePreviousSerialAvailable' => 1 ) if ( C4::Context->preference('makePreviousSerialAvailable') );
159
168
160
if ($op!~/^mod/) {
169
if ( $op !~ /^mod/ ) {
161
    my $letters = get_letter_loop();
170
    my $letters = get_letter_loop();
162
    $template->param( letterloop => $letters );
171
    $template->param( letterloop => $letters );
163
}
172
}
164
173
165
if ($op eq 'cud-addsubscription') {
174
if ( $op eq 'cud-addsubscription' ) {
166
    redirect_add_subscription();
175
    redirect_add_subscription();
167
} elsif ($op eq 'cud-modsubscription') {
176
} elsif ( $op eq 'cud-modsubscription' ) {
168
    redirect_mod_subscription();
177
    redirect_mod_subscription();
169
} else {
178
} else {
170
179
171
    $template->param(
180
    $template->param(
172
        subtypes => [ qw( numberlength weeklength monthlength ) ],
181
        subtypes => [qw( numberlength weeklength monthlength )],
173
        subtype => $sub_on,
182
        subtype  => $sub_on,
174
    );
183
    );
175
184
176
    if ( $op ne 'cud-modsubscription' && $op ne 'dup' && $op ne 'modify' ) {
185
    if ( $op ne 'cud-modsubscription' && $op ne 'dup' && $op ne 'modify' ) {
Lines 179-228 if ($op eq 'cud-addsubscription') { Link Here
179
    }
188
    }
180
189
181
    my $new_biblionumber = $query->param('biblionumber_for_new_subscription');
190
    my $new_biblionumber = $query->param('biblionumber_for_new_subscription');
182
    if (defined $new_biblionumber) {
191
    if ( defined $new_biblionumber ) {
183
        my $biblio = Koha::Biblios->find( $new_biblionumber );
192
        my $biblio = Koha::Biblios->find($new_biblionumber);
184
        if (defined $biblio) {
193
        if ( defined $biblio ) {
185
            $template->param(bibnum      => $new_biblionumber);
194
            $template->param( bibnum      => $new_biblionumber );
186
            $template->param(bibliotitle => $biblio->title);
195
            $template->param( bibliotitle => $biblio->title );
187
        }
196
        }
188
    }
197
    }
189
198
190
    $template->param((uc(C4::Context->preference("marcflavour"))) => 1);
199
    $template->param( ( uc( C4::Context->preference("marcflavour") ) ) => 1 );
191
200
192
    my @frequencies = GetSubscriptionFrequencies;
201
    my @frequencies = GetSubscriptionFrequencies;
193
    my @frqloop;
202
    my @frqloop;
194
    foreach my $freq (@frequencies) {
203
    foreach my $freq (@frequencies) {
195
        my $selected = 0;
204
        my $selected = 0;
196
        $selected = 1 if ($subs->{periodicity} and $freq->{id} eq $subs->{periodicity});
205
        $selected = 1 if ( $subs->{periodicity} and $freq->{id} eq $subs->{periodicity} );
197
        my $row = {
206
        my $row = {
198
            id => $freq->{'id'},
207
            id       => $freq->{'id'},
199
            selected => $selected,
208
            selected => $selected,
200
            label => $freq->{'description'},
209
            label    => $freq->{'description'},
201
        };
210
        };
202
        push @frqloop, $row;
211
        push @frqloop, $row;
203
    }
212
    }
204
    $template->param(frequencies => \@frqloop);
213
    $template->param( frequencies => \@frqloop );
205
214
206
    my @numpatterns = GetSubscriptionNumberpatterns;
215
    my @numpatterns = GetSubscriptionNumberpatterns;
207
    my @numberpatternloop;
216
    my @numberpatternloop;
208
    foreach my $numpattern (@numpatterns) {
217
    foreach my $numpattern (@numpatterns) {
209
        my $selected = 0;
218
        my $selected = 0;
210
        $selected = 1 if($subs->{numberpattern} and $numpattern->{id} eq $subs->{numberpattern});
219
        $selected = 1 if ( $subs->{numberpattern} and $numpattern->{id} eq $subs->{numberpattern} );
211
        my $row = {
220
        my $row = {
212
            id => $numpattern->{'id'},
221
            id       => $numpattern->{'id'},
213
            selected => $selected,
222
            selected => $selected,
214
            label => $numpattern->{'label'},
223
            label    => $numpattern->{'label'},
215
        };
224
        };
216
        push @numberpatternloop, $row;
225
        push @numberpatternloop, $row;
217
    }
226
    }
218
    $template->param(numberpatterns => \@numberpatternloop);
227
    $template->param( numberpatterns => \@numberpatternloop );
219
228
220
    my $languages = [ map {
229
    my $languages = [
221
        {
230
        map {
222
            language => $_->{iso639_2_code},
231
            {
223
            description => $_->{language_description} || $_->{language}
232
                language    => $_->{iso639_2_code},
224
        }
233
                subtag      => $_->{subtag},
225
    } @{ C4::Languages::getAllLanguages() } ];
234
                description => $_->{language_description} || $_->{language}
235
            }
236
        } @{ C4::Languages::getAllLanguages() }
237
    ];
226
238
227
    $template->param( locales => $languages );
239
    $template->param( locales => $languages );
228
240
Lines 235-241 if ($op eq 'cud-addsubscription') { Link Here
235
sub get_letter_loop {
247
sub get_letter_loop {
236
    my ($selected_lettercode) = @_;
248
    my ($selected_lettercode) = @_;
237
    $selected_lettercode //= '';
249
    $selected_lettercode //= '';
238
    my $letters = GetLetters({ module => 'serial' });
250
    my $letters = GetLetters( { module => 'serial' } );
239
    return [
251
    return [
240
        map {
252
        map {
241
            {
253
            {
Lines 243-274 sub get_letter_loop { Link Here
243
                lettername => $_->{name},
255
                lettername => $_->{name},
244
                ( $_->{code} eq $selected_lettercode ? ( selected => 1 ) : () ),
256
                ( $_->{code} eq $selected_lettercode ? ( selected => 1 ) : () ),
245
            }
257
            }
246
          } @$letters
258
        } @$letters
247
    ];
259
    ];
248
}
260
}
249
261
250
sub _guess_enddate {
262
sub _guess_enddate {
251
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
263
    my ( $startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength ) = @_;
252
    my ($year, $month, $day);
264
    my ( $year, $month, $day );
253
    my $enddate;
265
    my $enddate;
254
    if($numberlength != 0) {
266
    if ( $numberlength != 0 ) {
255
        my $frequency = GetSubscriptionFrequency($frequencyid);
267
        my $frequency = GetSubscriptionFrequency($frequencyid);
256
        if($frequency->{'unit'} eq 'day') {
268
        if ( $frequency->{'unit'} eq 'day' ) {
257
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
269
            ( $year, $month, $day ) = Add_Delta_Days(
258
        } elsif($frequency->{'unit'} eq 'week') {
270
                split( /-/, $startdate_iso ),
259
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
271
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
260
        } elsif($frequency->{'unit'} eq 'month') {
272
            );
261
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
273
        } elsif ( $frequency->{'unit'} eq 'week' ) {
262
        } elsif($frequency->{'unit'} eq 'year') {
274
            ( $year, $month, $day ) = Add_Delta_Days(
263
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
275
                split( /-/, $startdate_iso ),
276
                $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
277
            );
278
        } elsif ( $frequency->{'unit'} eq 'month' ) {
279
            ( $year, $month, $day ) = Add_Delta_YM(
280
                split( /-/, $startdate_iso ), 0,
281
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}
282
            );
283
        } elsif ( $frequency->{'unit'} eq 'year' ) {
284
            ( $year, $month, $day ) = Add_Delta_YM(
285
                split( /-/, $startdate_iso ),
286
                $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0
287
            );
264
        }
288
        }
265
    } elsif($weeklength != 0) {
289
    } elsif ( $weeklength != 0 ) {
266
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
290
        ( $year, $month, $day ) = Add_Delta_Days( split( /-/, $startdate_iso ), $weeklength * 7 );
267
    } elsif($monthlength != 0) {
291
    } elsif ( $monthlength != 0 ) {
268
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
292
        ( $year, $month, $day ) = Add_Delta_YM( split( /-/, $startdate_iso ), 0, $monthlength );
269
    }
293
    }
270
    if(defined $year) {
294
    if ( defined $year ) {
271
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
295
        $enddate = sprintf( "%04d-%02d-%02d", $year, $month, $day );
272
    } else {
296
    } else {
273
        undef $enddate;
297
        undef $enddate;
274
    }
298
    }
Lines 277-283 sub _guess_enddate { Link Here
277
301
278
sub redirect_add_subscription {
302
sub redirect_add_subscription {
279
    my $periodicity = $query->param('frequency');
303
    my $periodicity = $query->param('frequency');
280
    if ($periodicity eq 'mana') {
304
    if ( $periodicity eq 'mana' ) {
281
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
305
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
282
            {
306
            {
283
                description   => $query->param('sfdescription'),
307
                description   => $query->param('sfdescription'),
Lines 288-294 sub redirect_add_subscription { Link Here
288
        )->store();
312
        )->store();
289
        $periodicity = $subscription_freq->id;
313
        $periodicity = $subscription_freq->id;
290
    }
314
    }
291
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing({ $query->Vars });
315
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing( { $query->Vars } );
292
316
293
    my $auser          = $query->param('user');
317
    my $auser          = $query->param('user');
294
    my $branchcode     = $query->param('branchcode');
318
    my $branchcode     = $query->param('branchcode');
Lines 299-361 sub redirect_add_subscription { Link Here
299
    my $locale         = $query->param('locale');
323
    my $locale         = $query->param('locale');
300
    my $graceperiod    = $query->param('graceperiod') || 0;
324
    my $graceperiod    = $query->param('graceperiod') || 0;
301
325
302
    my $subtype = $query->param('subtype');
326
    my $subtype   = $query->param('subtype');
303
    my $sublength = $query->param('sublength');
327
    my $sublength = $query->param('sublength');
304
    my ( $numberlength, $weeklength, $monthlength )
328
    my ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength );
305
        = GetSubscriptionLength( $subtype, $sublength );
329
    my $add1                  = $query->param('add1');
306
    my $add1              = $query->param('add1');
330
    my $lastvalue1            = $query->param('lastvalue1');
307
    my $lastvalue1        = $query->param('lastvalue1');
331
    my $innerloop1            = $query->param('innerloop1');
308
    my $innerloop1        = $query->param('innerloop1');
332
    my $innerloop2            = $query->param('innerloop2');
309
    my $innerloop2        = $query->param('innerloop2');
333
    my $lastvalue2            = $query->param('lastvalue2');
310
    my $lastvalue2        = $query->param('lastvalue2');
334
    my $lastvalue3            = $query->param('lastvalue3');
311
    my $lastvalue3        = $query->param('lastvalue3');
335
    my $innerloop3            = $query->param('innerloop3');
312
    my $innerloop3        = $query->param('innerloop3');
336
    my $status                = 1;
313
    my $status            = 1;
337
    my $biblionumber          = $query->param('biblionumber');
314
    my $biblionumber      = $query->param('biblionumber');
338
    my $callnumber            = $query->param('callnumber');
315
    my $callnumber        = $query->param('callnumber');
339
    my $notes                 = $query->param('notes');
316
    my $notes             = $query->param('notes');
340
    my $internalnotes         = $query->param('internalnotes');
317
    my $internalnotes     = $query->param('internalnotes');
341
    my $letter                = $query->param('letter');
318
    my $letter            = $query->param('letter');
342
    my $manualhistory         = $query->param('manualhist') ? 1 : 0;
319
    my $manualhistory     = $query->param('manualhist') ? 1 : 0;
343
    my $serialsadditems       = $query->param('serialsadditems');
320
    my $serialsadditems   = $query->param('serialsadditems');
344
    my $staffdisplaycount     = $query->param('staffdisplaycount');
321
    my $staffdisplaycount = $query->param('staffdisplaycount');
345
    my $opacdisplaycount      = $query->param('opacdisplaycount');
322
    my $opacdisplaycount  = $query->param('opacdisplaycount');
346
    my $location              = $query->param('location');
323
    my $location          = $query->param('location');
347
    my $itemtype              = $query->param('itemtype');
324
    my $itemtype          = $query->param('itemtype');
348
    my $previousitemtype      = $query->param('previousitemtype');
325
    my $previousitemtype  = $query->param('previousitemtype');
349
    my $skip_serialseq        = $query->param('skip_serialseq');
326
    my $skip_serialseq    = $query->param('skip_serialseq');
350
    my $ccode                 = $query->param('ccode');
327
    my $ccode             = $query->param('ccode');
328
    my $published_on_template = $query->param('published_on_template');
351
    my $published_on_template = $query->param('published_on_template');
329
352
330
    my $mana_id;
353
    my $mana_id;
331
    if ( $query->param('mana_id') ne "" ) {
354
    if ( $query->param('mana_id') ne "" ) {
332
        $mana_id = $query->param('mana_id');
355
        $mana_id = $query->param('mana_id');
333
        Koha::SharedContent::increment_entity_value("subscription",$mana_id, "nbofusers");
356
        Koha::SharedContent::increment_entity_value( "subscription", $mana_id, "nbofusers" );
334
    }
357
    }
335
358
336
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
359
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
337
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
360
    my $enddate   = output_pref( { str => scalar $query->param('enddate'),   dateonly => 1, dateformat => 'iso' } );
338
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
361
    my $firstacquidate =
362
        output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
339
363
340
    if(!defined $enddate || $enddate eq '') {
364
    if ( !defined $enddate || $enddate eq '' ) {
341
        if($subtype eq "issues") {
365
        if ( $subtype eq "issues" ) {
342
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength)
366
            $enddate = _guess_enddate( $firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength );
343
        } else {
367
        } else {
344
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
368
            $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength );
345
        }
369
        }
346
    }
370
    }
347
    my $subscriptionid = NewSubscription(
371
    my $subscriptionid = NewSubscription(
348
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
372
        $auser,                     $branchcode,       $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
349
        $startdate, $periodicity, $numberlength, $weeklength,
373
        $startdate,                 $periodicity,      $numberlength,   $weeklength,
350
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
374
        $monthlength,               $lastvalue1,       $innerloop1,     $lastvalue2, $innerloop2,
351
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
375
        $lastvalue3,                $innerloop3,       $status,         $notes, $letter, $firstacquidate,
352
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
376
        join( ";", @irregularity ), $numberpattern,    $locale,         $callnumber,
353
        $manualhistory, $internalnotes, $serialsadditems,
377
        $manualhistory,             $internalnotes,    $serialsadditems,
354
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
378
        $staffdisplaycount,         $opacdisplaycount, $graceperiod, $location, $enddate,
355
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
379
        $skip_serialseq,            $itemtype,         $previousitemtype, $mana_id, $ccode, $published_on_template
356
    );
380
    );
357
    if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
381
    if (    ( C4::Context->preference('Mana') == 1 )
358
        my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
382
        and ( grep { $_ eq "subscription" } split( /,/, C4::Context->preference('AutoShareWithMana') ) ) )
383
    {
384
        my $result = Koha::SharedContent::send_entity(
385
            $query->param('mana_language') || '', $loggedinuser, $subscriptionid,
386
            'subscription'
387
        );
359
        $template->param( mana_msg => $result->{msg} );
388
        $template->param( mana_msg => $result->{msg} );
360
    }
389
    }
361
390
Lines 369-394 sub redirect_add_subscription { Link Here
369
398
370
sub redirect_mod_subscription {
399
sub redirect_mod_subscription {
371
    my $subscriptionid = $query->param('subscriptionid');
400
    my $subscriptionid = $query->param('subscriptionid');
372
    my @irregularity = $query->multi_param('irregularity');
401
    my @irregularity   = $query->multi_param('irregularity');
373
    my $auser = $query->param('user');
402
    my $auser          = $query->param('user');
374
    my $librarian => scalar $query->param('librarian'),
403
    my $librarian => scalar $query->param('librarian'),
375
    my $branchcode = $query->param('branchcode');
404
        my $branchcode = $query->param('branchcode');
376
    my $cost = $query->param('cost');
405
    my $cost           = $query->param('cost');
377
    my $aqbooksellerid = $query->param('aqbooksellerid');
406
    my $aqbooksellerid = $query->param('aqbooksellerid');
378
    my $biblionumber = $query->param('biblionumber');
407
    my $biblionumber   = $query->param('biblionumber');
379
    my $aqbudgetid = $query->param('aqbudgetid');
408
    my $aqbudgetid     = $query->param('aqbudgetid');
380
409
381
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
410
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
382
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
411
    my $enddate   = output_pref( { str => scalar $query->param('enddate'),   dateonly => 1, dateformat => 'iso' } );
383
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
412
    my $firstacquidate =
413
        output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
384
414
385
    my $nextacquidate  = $query->param('nextacquidate');
415
    my $nextacquidate = $query->param('nextacquidate');
386
    $nextacquidate = $nextacquidate
416
    $nextacquidate =
417
        $nextacquidate
387
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
418
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
388
        : $firstacquidate;
419
        : $firstacquidate;
389
420
390
    my $periodicity = $query->param('frequency');
421
    my $periodicity = $query->param('frequency');
391
    if ($periodicity eq 'mana') {
422
    if ( $periodicity eq 'mana' ) {
392
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
423
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
393
            {
424
            {
394
                description   => $query->param('sfdescription'),
425
                description   => $query->param('sfdescription'),
Lines 399-468 sub redirect_mod_subscription { Link Here
399
        )->store();
430
        )->store();
400
        $periodicity = $subscription_freq->id;
431
        $periodicity = $subscription_freq->id;
401
    }
432
    }
402
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing({ $query->Vars });
433
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing( { $query->Vars } );
403
434
404
    my $subtype = $query->param('subtype');
435
    my $subtype   = $query->param('subtype');
405
    my $sublength = $query->param('sublength');
436
    my $sublength = $query->param('sublength');
406
    my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
437
    my ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength );
407
    my $locale = $query->param('locale');
438
    my $locale                = $query->param('locale');
408
    my $lastvalue1 = $query->param('lastvalue1');
439
    my $lastvalue1            = $query->param('lastvalue1');
409
    my $innerloop1 = $query->param('innerloop1');
440
    my $innerloop1            = $query->param('innerloop1');
410
    my $lastvalue2 = $query->param('lastvalue2');
441
    my $lastvalue2            = $query->param('lastvalue2');
411
    my $innerloop2 = $query->param('innerloop2');
442
    my $innerloop2            = $query->param('innerloop2');
412
    my $lastvalue3 = $query->param('lastvalue3');
443
    my $lastvalue3            = $query->param('lastvalue3');
413
    my $innerloop3 = $query->param('innerloop3');
444
    my $innerloop3            = $query->param('innerloop3');
414
    my $status = 1;
445
    my $status                = 1;
415
    my $callnumber = $query->param('callnumber');
446
    my $callnumber            = $query->param('callnumber');
416
    my $notes = $query->param('notes');
447
    my $notes                 = $query->param('notes');
417
    my $internalnotes = $query->param('internalnotes');
448
    my $internalnotes         = $query->param('internalnotes');
418
    my $letter = $query->param('letter');
449
    my $letter                = $query->param('letter');
419
    my $manualhistory = $query->param('manualhist') ? 1 : 0;
450
    my $manualhistory         = $query->param('manualhist') ? 1 : 0;
420
    my $serialsadditems = $query->param('serialsadditems');
451
    my $serialsadditems       = $query->param('serialsadditems');
421
	my $staffdisplaycount = $query->param('staffdisplaycount');
452
    my $staffdisplaycount     = $query->param('staffdisplaycount');
422
	my $opacdisplaycount = $query->param('opacdisplaycount');
453
    my $opacdisplaycount      = $query->param('opacdisplaycount');
423
    my $graceperiod     = $query->param('graceperiod') || 0;
454
    my $graceperiod           = $query->param('graceperiod') || 0;
424
    my $location = $query->param('location');
455
    my $location              = $query->param('location');
425
    my $itemtype          = $query->param('itemtype');
456
    my $itemtype              = $query->param('itemtype');
426
    my $previousitemtype  = $query->param('previousitemtype');
457
    my $previousitemtype      = $query->param('previousitemtype');
427
    my $skip_serialseq    = $query->param('skip_serialseq');
458
    my $skip_serialseq        = $query->param('skip_serialseq');
428
    my $ccode             = $query->param('ccode');
459
    my $ccode                 = $query->param('ccode');
429
    my $published_on_template = $query->param('published_on_template');
460
    my $published_on_template = $query->param('published_on_template');
430
461
431
    my $mana_id;
462
    my $mana_id;
432
    if ( $query->param('mana_id') ne "" ) {
463
    if ( $query->param('mana_id') ne "" ) {
433
        $mana_id = $query->param('mana_id');
464
        $mana_id = $query->param('mana_id');
434
        Koha::SharedContent::increment_entity_value("subscription",$mana_id, "nbofusers");
465
        Koha::SharedContent::increment_entity_value( "subscription", $mana_id, "nbofusers" );
435
    }
466
    } else {
436
    else {
437
        $mana_id = undef;
467
        $mana_id = undef;
438
    }
468
    }
439
469
440
    # Guess end date
470
    # Guess end date
441
    if(!defined $enddate || $enddate eq '') {
471
    if ( !defined $enddate || $enddate eq '' ) {
442
        if($subtype eq "issues") {
472
        if ( $subtype eq "issues" ) {
443
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
473
            $enddate = _guess_enddate( $nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength );
444
        } else {
474
        } else {
445
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
475
            $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength );
446
        }
476
        }
447
    }
477
    }
448
478
449
    my $nextexpected = GetNextExpected($subscriptionid);
479
    my $nextexpected = GetNextExpected($subscriptionid);
480
450
    #  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary.
481
    #  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary.
451
    if ( $nextexpected->{planneddate} && $nextacquidate ne $nextexpected->{planneddate} ) {
482
    if ( $nextexpected->{planneddate} && $nextacquidate ne $nextexpected->{planneddate} ) {
452
        ModNextExpected($subscriptionid, $nextacquidate);
483
        ModNextExpected( $subscriptionid, $nextacquidate );
484
453
        # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
485
        # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
454
        $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue});
486
        $firstissuedate = $nextacquidate if ( $nextexpected->{isfirstissue} );
455
    }
487
    }
456
488
457
    ModSubscription(
489
    ModSubscription(
458
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
490
        $auser,            $branchcode,     $aqbooksellerid, $cost, $aqbudgetid, $startdate,
459
        $periodicity, $firstacquidate, join(";",@irregularity),
491
        $periodicity,      $firstacquidate, join( ";", @irregularity ),
460
        $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1,
492
        $numberpattern,    $locale,         $numberlength,     $weeklength, $monthlength, $lastvalue1,
461
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
493
        $innerloop1,       $lastvalue2,     $innerloop2,       $lastvalue3, $innerloop3,
462
        $status, $biblionumber, $callnumber, $notes, $letter,
494
        $status,           $biblionumber,   $callnumber,       $notes,      $letter,
463
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
495
        $manualhistory,    $internalnotes,  $serialsadditems,  $staffdisplaycount,
464
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
496
        $opacdisplaycount, $graceperiod,    $location,         $enddate, $subscriptionid,
465
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
497
        $skip_serialseq,   $itemtype,       $previousitemtype, $mana_id, $ccode, $published_on_template
466
    );
498
    );
467
499
468
    my @additional_fields =
500
    my @additional_fields =
(-)a/serials/subscription-numberpatterns.pl (-39 / +44 lines)
Lines 44-111 use C4::Serials::Numberpattern qw( Link Here
44
use C4::Serials::Frequency qw( GetSubscriptionFrequencies );
44
use C4::Serials::Frequency qw( GetSubscriptionFrequencies );
45
45
46
my @NUMBERPATTERN_FIELDS = qw/
46
my @NUMBERPATTERN_FIELDS = qw/
47
      label description numberingmethod displayorder
47
    label description numberingmethod displayorder
48
      label1 label2 label3 add1 add2 add3 every1 every2 every3
48
    label1 label2 label3 add1 add2 add3 every1 every2 every3
49
      setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
49
    setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
50
      numbering1 numbering2 numbering3 /;
50
    numbering1 numbering2 numbering3 /;
51
51
52
my $input = CGI->new;
52
my $input = CGI->new;
53
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
53
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
54
    template_name   => 'serials/subscription-numberpatterns.tt',
54
    {
55
    query           => $input,
55
        template_name => 'serials/subscription-numberpatterns.tt',
56
    type            => 'intranet',
56
        query         => $input,
57
    flagsrequired   => { 'serials' => "*" }
57
        type          => 'intranet',
58
} );
58
        flagsrequired => { 'serials' => "*" }
59
    }
60
);
59
61
60
my $op = $input->param('op');
62
my $op = $input->param('op');
61
63
62
if($op && $op eq 'cud-savenew') {
64
if ( $op && $op eq 'cud-savenew' ) {
63
    my $label = $input->param('label');
65
    my $label = $input->param('label');
64
    my $numberpattern;
66
    my $numberpattern;
65
    foreach(@NUMBERPATTERN_FIELDS) {
67
    foreach (@NUMBERPATTERN_FIELDS) {
66
        $numberpattern->{$_} = $input->param($_);
68
        $numberpattern->{$_} = $input->param($_);
67
        if(defined $numberpattern->{$_} and $numberpattern->{$_} eq '') {
69
        if ( defined $numberpattern->{$_} and $numberpattern->{$_} eq '' ) {
68
            $numberpattern->{$_} = undef;
70
            $numberpattern->{$_} = undef;
69
        }
71
        }
70
    }
72
    }
71
    my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
73
    my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
72
74
73
    if(!defined $numberpattern2) {
75
    if ( !defined $numberpattern2 ) {
74
        AddSubscriptionNumberpattern($numberpattern);
76
        AddSubscriptionNumberpattern($numberpattern);
75
    } else {
77
    } else {
76
        $op = 'new';
78
        $op = 'new';
77
        $template->param(error_existing_numberpattern => 1);
79
        $template->param( error_existing_numberpattern => 1 );
78
        $template->param(%$numberpattern);
80
        $template->param(%$numberpattern);
79
    }
81
    }
80
} elsif ($op && $op eq 'cud-savemod') {
82
} elsif ( $op && $op eq 'cud-savemod' ) {
81
    my $id = $input->param('id');
83
    my $id            = $input->param('id');
82
    my $label = $input->param('label');
84
    my $label         = $input->param('label');
83
    my $numberpattern = GetSubscriptionNumberpattern($id);
85
    my $numberpattern = GetSubscriptionNumberpattern($id);
84
    my $mod_ok = 1;
86
    my $mod_ok        = 1;
85
    if($numberpattern->{'label'} ne $label) {
87
    if ( $numberpattern->{'label'} ne $label ) {
86
        my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
88
        my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
87
        if(defined $numberpattern2 && $id != $numberpattern2->{'id'}) {
89
        if ( defined $numberpattern2 && $id != $numberpattern2->{'id'} ) {
88
            $mod_ok = 0;
90
            $mod_ok = 0;
89
        }
91
        }
90
    }
92
    }
91
    if($mod_ok) {
93
    if ($mod_ok) {
92
        foreach(@NUMBERPATTERN_FIELDS) {
94
        foreach (@NUMBERPATTERN_FIELDS) {
93
            $numberpattern->{$_} = $input->param($_) || undef;
95
            $numberpattern->{$_} = $input->param($_) || undef;
94
            if(defined $numberpattern->{$_} and $numberpattern->{$_} eq '') {
96
            if ( defined $numberpattern->{$_} and $numberpattern->{$_} eq '' ) {
95
                $numberpattern->{$_} = undef;
97
                $numberpattern->{$_} = undef;
96
            }
98
            }
97
        }
99
        }
98
        ModSubscriptionNumberpattern($numberpattern);
100
        ModSubscriptionNumberpattern($numberpattern);
99
    } else {
101
    } else {
100
        $op = 'cud-modify';
102
        $op = 'cud-modify';
101
        $template->param(error_existing_numberpattern => 1);
103
        $template->param( error_existing_numberpattern => 1 );
102
    }
104
    }
103
}
105
}
104
106
105
if($op && ($op eq 'new' || $op eq 'modify')) {
107
if ( $op && ( $op eq 'new' || $op eq 'modify' ) ) {
106
    if($op eq 'modify') {
108
    if ( $op eq 'modify' ) {
107
        my $id = $input->param('id');
109
        my $id = $input->param('id');
108
        if(defined $id) {
110
        if ( defined $id ) {
109
            my $numberpattern = GetSubscriptionNumberpattern($id);
111
            my $numberpattern = GetSubscriptionNumberpattern($id);
110
            $template->param(%$numberpattern);
112
            $template->param(%$numberpattern);
111
        } else {
113
        } else {
Lines 113-135 if($op && ($op eq 'new' || $op eq 'modify')) { Link Here
113
        }
115
        }
114
    }
116
    }
115
    my @frequencies = GetSubscriptionFrequencies();
117
    my @frequencies = GetSubscriptionFrequencies();
116
    my $languages = [ map {
118
    my $languages   = [
117
        {
119
        map {
118
            language => $_->{iso639_2_code},
120
            {
119
            description => $_->{language_description} || $_->{language}
121
                language    => $_->{iso639_2_code},
120
        }
122
                subtag      => $_->{subtag},
121
    } @{ C4::Languages::getAllLanguages() } ];
123
                description => $_->{language_description} || $_->{language}
124
            }
125
        } @{ C4::Languages::getAllLanguages() }
126
    ];
122
127
123
    $template->param(
128
    $template->param(
124
        $op => 1,
129
        $op              => 1,
125
        frequencies_loop => \@frequencies,
130
        frequencies_loop => \@frequencies,
126
        locales => $languages,
131
        locales          => $languages,
127
    );
132
    );
128
    output_html_with_http_headers $input, $cookie, $template->output;
133
    output_html_with_http_headers $input, $cookie, $template->output;
129
    exit;
134
    exit;
130
}
135
}
131
136
132
if($op && $op eq 'cud-del') {
137
if ( $op && $op eq 'cud-del' ) {
133
    my $id = $input->param('id');
138
    my $id = $input->param('id');
134
    if ($id) {
139
    if ($id) {
135
        my $confirm = $input->param('confirm');
140
        my $confirm = $input->param('confirm');
Lines 139-146 if($op && $op eq 'cud-del') { Link Here
139
            my @subs = GetSubscriptionsWithNumberpattern($id);
144
            my @subs = GetSubscriptionsWithNumberpattern($id);
140
            if (@subs) {
145
            if (@subs) {
141
                $template->param(
146
                $template->param(
142
                    id => $id,
147
                    id            => $id,
143
                    still_used => 1,
148
                    still_used    => 1,
144
                    subscriptions => \@subs
149
                    subscriptions => \@subs
145
                );
150
                );
146
            } else {
151
            } else {
(-)a/t/db_dependent/Serials.t (-210 / +377 lines)
Lines 5-26 Link Here
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
7
8
use C4::Serials qw( getroutinglist updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate );
8
use C4::Serials
9
    qw( getroutinglist updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations );
9
use C4::Serials::Frequency;
10
use C4::Serials::Frequency;
10
use C4::Serials::Numberpattern;
11
use C4::Serials::Numberpattern;
11
use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
12
use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
12
use C4::Budgets qw( AddBudgetPeriod AddBudget );
13
use C4::Budgets qw( AddBudgetPeriod AddBudget );
14
use C4::Context;
13
use C4::Items qw( AddItemFromMarc );
15
use C4::Items qw( AddItemFromMarc );
16
use Encode qw( encode );
17
use File::Temp;
14
use Koha::Database;
18
use Koha::Database;
15
use Koha::DateUtils qw( dt_from_string output_pref );
19
use Koha::DateUtils qw( dt_from_string output_pref );
16
use Koha::Acquisition::Booksellers;
20
use Koha::Acquisition::Booksellers;
17
use t::lib::Mocks;
21
use t::lib::Mocks;
18
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
19
use Test::MockModule;
23
use Test::MockModule;
20
use Test::More tests => 63;
24
use Test::More tests => 64;
21
25
22
BEGIN {
26
BEGIN {
23
    use_ok('C4::Serials', qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate ));
27
    use_ok(
28
        'C4::Serials',
29
        qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations )
30
    );
24
}
31
}
25
32
26
# Auth required for cataloguing plugins
33
# Auth required for cataloguing plugins
Lines 37-87 my $builder = t::lib::TestBuilder->new(); Link Here
37
44
38
# This could/should be used for all untested methods
45
# This could/should be used for all untested methods
39
my @methods = ('updateClaim');
46
my @methods = ('updateClaim');
40
can_ok('C4::Serials', @methods);
47
can_ok( 'C4::Serials', @methods );
41
48
42
$dbh->do(q|UPDATE marc_subfield_structure SET value_builder="callnumber.pl" where kohafield="items.itemcallnumber" and frameworkcode=''|);
49
$dbh->do(
50
    q|UPDATE marc_subfield_structure SET value_builder="callnumber.pl" where kohafield="items.itemcallnumber" and frameworkcode=''|
51
);
43
52
44
my $bookseller = Koha::Acquisition::Bookseller->new(
53
my $bookseller = Koha::Acquisition::Bookseller->new(
45
    {
54
    {
46
        name => "my vendor",
55
        name     => "my vendor",
47
        address1 => "bookseller's address",
56
        address1 => "bookseller's address",
48
        phone => "0123456",
57
        phone    => "0123456",
49
        active => 1
58
        active   => 1
59
    }
60
);
61
62
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( MARC::Record->new, '' );
63
64
my $bpid = AddBudgetPeriod(
65
    {
66
        budget_period_startdate   => '2015-01-01',
67
        budget_period_enddate     => '2015-12-31',
68
        budget_period_description => "budget desc"
50
    }
69
    }
51
);
70
);
52
71
53
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
72
my $budget_id = AddBudget(
54
73
    {
55
my $bpid = AddBudgetPeriod({
74
        budget_code      => "ABCD",
56
    budget_period_startdate   => '2015-01-01',
75
        budget_amount    => "123.132",
57
    budget_period_enddate     => '2015-12-31',
76
        budget_name      => "Périodiques",
58
    budget_period_description => "budget desc"
77
        budget_notes     => "This is a note",
59
});
78
        budget_period_id => $bpid
60
79
    }
61
my $budget_id = AddBudget({
80
);
62
    budget_code        => "ABCD",
81
63
    budget_amount      => "123.132",
82
my $frequency_id = AddSubscriptionFrequency( { description => "Test frequency 1" } );
64
    budget_name        => "Périodiques",
83
my $pattern_id   = AddSubscriptionNumberpattern(
65
    budget_notes       => "This is a note",
84
    {
66
    budget_period_id   => $bpid
85
        label           => 'Test numberpattern 1',
67
});
86
        description     => 'Description for numberpattern 1',
68
87
        numberingmethod => '{X}',
69
my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
88
        label1          => q{},
70
my $pattern_id = AddSubscriptionNumberpattern({
89
        add1            => 1,
71
    label => 'Test numberpattern 1',
90
        every1          => 1,
72
    description => 'Description for numberpattern 1',
91
        every1          => 1,
73
    numberingmethod => '{X}',
92
        numbering1      => 1,
74
    label1 => q{},
93
        whenmorethan1   => 1,
75
    add1 => 1,
94
    }
76
    every1 => 1,
95
);
77
    every1 => 1,
96
78
    numbering1 => 1,
97
my $notes          = "a\nnote\non\nseveral\nlines";
79
    whenmorethan1 => 1,
98
my $internalnotes  = 'intnotes';
80
});
99
my $ccode          = 'FIC';
81
82
my $notes = "a\nnote\non\nseveral\nlines";
83
my $internalnotes = 'intnotes';
84
my $ccode = 'FIC';
85
my $subscriptionid = NewSubscription(
100
my $subscriptionid = NewSubscription(
86
    undef,
101
    undef,
87
    "",
102
    "",
Lines 163-198 NewSubscription( Link Here
163
    $ccode
178
    $ccode
164
);
179
);
165
180
166
my $subscriptioninformation = GetSubscription( $subscriptionid );
181
my $subscriptioninformation = GetSubscription($subscriptionid);
167
182
168
is( $subscriptioninformation->{notes}, $notes, 'NewSubscription should set notes' );
183
is( $subscriptioninformation->{notes},         $notes,         'NewSubscription should set notes' );
169
is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' );
184
is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' );
170
is( $subscriptioninformation->{ccode}, $ccode, 'NewSubscription should set ccode' );
185
is( $subscriptioninformation->{ccode},         $ccode,         'NewSubscription should set ccode' );
171
186
172
my $subscription_history = C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
187
my $subscription_history = C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
173
is( $subscription_history->{opacnote}, undef, 'NewSubscription should not set subscriptionhistory opacnotes' );
188
is( $subscription_history->{opacnote}, undef, 'NewSubscription should not set subscriptionhistory opacnotes' );
174
is( $subscription_history->{librariannote}, undef, 'NewSubscription should not set subscriptionhistory librariannotes' );
189
is(
190
    $subscription_history->{librariannote}, undef,
191
    'NewSubscription should not set subscriptionhistory librariannotes'
192
);
175
193
176
my @subscriptions = SearchSubscriptions({string => $subscriptioninformation->{bibliotitle}, orderby => 'title' });
194
my @subscriptions = SearchSubscriptions( { string => $subscriptioninformation->{bibliotitle}, orderby => 'title' } );
177
isa_ok( \@subscriptions, 'ARRAY' );
195
isa_ok( \@subscriptions, 'ARRAY' );
178
196
179
@subscriptions = SearchSubscriptions({ issn => $subscriptioninformation->{issn}, orderby => 'title' });
197
@subscriptions = SearchSubscriptions( { issn => $subscriptioninformation->{issn}, orderby => 'title' } );
180
isa_ok( \@subscriptions, 'ARRAY' );
198
isa_ok( \@subscriptions, 'ARRAY' );
181
199
182
@subscriptions = SearchSubscriptions({ ean => $subscriptioninformation->{ean}, orderby => 'title' });
200
@subscriptions = SearchSubscriptions( { ean => $subscriptioninformation->{ean}, orderby => 'title' } );
183
isa_ok( \@subscriptions, 'ARRAY' );
201
isa_ok( \@subscriptions, 'ARRAY' );
184
202
185
@subscriptions = SearchSubscriptions({ biblionumber => $subscriptioninformation->{bibnum}, orderby => 'title' });
203
@subscriptions = SearchSubscriptions( { biblionumber => $subscriptioninformation->{bibnum}, orderby => 'title' } );
186
isa_ok( \@subscriptions, 'ARRAY' );
204
isa_ok( \@subscriptions, 'ARRAY' );
187
205
188
@subscriptions = SearchSubscriptions({});
206
@subscriptions = SearchSubscriptions( {} );
189
is(
207
is(
190
    @subscriptions,
208
    @subscriptions,
191
    2,
209
    2,
192
    'SearchSubscriptions returned the expected number of subscriptions when results_limit is not set'
210
    'SearchSubscriptions returned the expected number of subscriptions when results_limit is not set'
193
);
211
);
194
212
195
@subscriptions = SearchSubscriptions({}, { results_limit => 1 });
213
@subscriptions = SearchSubscriptions( {}, { results_limit => 1 } );
196
is(
214
is(
197
    @subscriptions,
215
    @subscriptions,
198
    1,
216
    1,
Lines 254-309 is( Link Here
254
    'SearchSubscriptions returned the correct subscription'
272
    'SearchSubscriptions returned the correct subscription'
255
);
273
);
256
274
257
my $frequency = GetSubscriptionFrequency($subscriptioninformation->{periodicity});
275
my $frequency = GetSubscriptionFrequency( $subscriptioninformation->{periodicity} );
258
my $old_frequency;
276
my $old_frequency;
259
if (not $frequency->{unit}) {
277
if ( not $frequency->{unit} ) {
260
    $old_frequency = $frequency->{id};
278
    $old_frequency                              = $frequency->{id};
261
    $frequency->{unit} = "month";
279
    $frequency->{unit}                          = "month";
262
    $frequency->{unitsperissue} = 1;
280
    $frequency->{unitsperissue}                 = 1;
263
    $frequency->{issuesperunit} = 1;
281
    $frequency->{issuesperunit}                 = 1;
264
    $frequency->{description} = "Frequency created by t/db_dependant/Serials.t";
282
    $frequency->{description}                   = "Frequency created by t/db_dependant/Serials.t";
265
    $subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency);
283
    $subscriptioninformation->{periodicity}     = AddSubscriptionFrequency($frequency);
266
    $subscriptioninformation->{serialsadditems} = 1;
284
    $subscriptioninformation->{serialsadditems} = 1;
267
    $subscriptioninformation->{ccode} = 'NFIC';
285
    $subscriptioninformation->{ccode}           = 'NFIC';
268
286
269
    ModSubscription( @$subscriptioninformation{qw(
287
    ModSubscription(
270
        librarian branchcode aqbooksellerid cost aqbudgetid startdate
288
        @$subscriptioninformation{
271
        periodicity firstacquidate irregularity numberpattern locale
289
            qw(
272
        numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
290
                librarian branchcode aqbooksellerid cost aqbudgetid startdate
273
        innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
291
                periodicity firstacquidate irregularity numberpattern locale
274
        letter manualhistory internalnotes serialsadditems staffdisplaycount
292
                numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
275
        opacdisplaycount graceperiod location enddate subscriptionid
293
                innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
276
        skip_serialseq itemtype previousitemtype mana_id ccode
294
                letter manualhistory internalnotes serialsadditems staffdisplaycount
277
    )} );
295
                opacdisplaycount graceperiod location enddate subscriptionid
296
                skip_serialseq itemtype previousitemtype mana_id ccode
297
            )
298
        }
299
    );
278
}
300
}
279
my $expirationdate = GetExpirationDate($subscriptionid) ;
301
my $expirationdate = GetExpirationDate($subscriptionid);
280
ok( $expirationdate, "expiration date is not NULL" );
302
ok( $expirationdate, "expiration date is not NULL" );
281
303
282
# Check ModSubscription has updated the ccode
304
# Check ModSubscription has updated the ccode
283
my $subscriptioninformation2 = GetSubscription($subscriptionid);
305
my $subscriptioninformation2 = GetSubscription($subscriptionid);
284
is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' );
306
is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' );
285
307
286
ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');
308
ok( C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription' );
287
309
288
my ($serials_count, @serials) = GetSerials($subscriptionid);
310
my ( $serials_count, @serials ) = GetSerials($subscriptionid);
289
ok($serials_count > 0, 'Subscription has at least one serial');
311
ok( $serials_count > 0, 'Subscription has at least one serial' );
290
my $serial = $serials[0];
312
my $serial = $serials[0];
291
313
292
isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information');
314
isa_ok( C4::Serials::GetSerialInformation( $serial->{serialid} ), 'HASH', 'test getting Serial Information' );
293
315
294
subtest 'Values should not be erased on editing' => sub {
316
subtest 'Values should not be erased on editing' => sub {
295
317
296
    plan tests => 1;
318
    plan tests => 1;
297
319
298
    my $biblio = $builder->build_sample_biblio();
320
    my $biblio       = $builder->build_sample_biblio();
299
    my $biblionumber = $biblio->biblionumber;
321
    my $biblionumber = $biblio->biblionumber;
300
    my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber' );
322
    my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField('items.itemcallnumber');
301
    my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype' );
323
    my ( $it_tag, $it_sf )   = GetMarcFromKohaField('items.itype');
302
324
303
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
325
    my $itemtype       = $builder->build( { source => 'Itemtype' } )->{itemtype};
304
    my $itemcallnumber = 'XXXmy itemcallnumberXXX';
326
    my $itemcallnumber = 'XXXmy itemcallnumberXXX';
305
327
306
    my $item_record    = MARC::Record->new;
328
    my $item_record = MARC::Record->new;
307
329
308
    $item_record->append_fields(
330
    $item_record->append_fields(
309
        MARC::Field->new( '080', '', '', "a" => "default" ),
331
        MARC::Field->new( '080', '', '', "a" => "default" ),
Lines 314-325 subtest 'Values should not be erased on editing' => sub { Link Here
314
        )
336
        )
315
    );
337
    );
316
    my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber );
338
    my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber );
317
    my $serialid = C4::Serials::NewIssue( "serialseq", $subscriptionid, $biblionumber,
339
    my $serialid = C4::Serials::NewIssue(
318
                                          1, undef, undef, "publisheddatetext", "notes", "routingnotes" );
340
        "serialseq", $subscriptionid, $biblionumber,
341
        1, undef, undef, "publisheddatetext", "notes", "routingnotes"
342
    );
319
    C4::Serials::AddItem2Serial( $serialid, $itemnumber );
343
    C4::Serials::AddItem2Serial( $serialid, $itemnumber );
320
    my $serial_info = C4::Serials::GetSerialInformation($serialid);
344
    my $serial_info = C4::Serials::GetSerialInformation($serialid);
321
    my ($itemcallnumber_info) = grep { $_->{kohafield} eq 'items.itemcallnumber' }
345
    my ($itemcallnumber_info) =
322
                                     @{ $serial_info->{items}[0]->{iteminformation} };
346
        grep { $_->{kohafield} eq 'items.itemcallnumber' } @{ $serial_info->{items}[0]->{iteminformation} };
323
    like( $itemcallnumber_info->{marc_value}, qr|value="$itemcallnumber"| );
347
    like( $itemcallnumber_info->{marc_value}, qr|value="$itemcallnumber"| );
324
};
348
};
325
349
Lines 328-411 if ($old_frequency) { Link Here
328
    my $freq_to_delete = $subscriptioninformation->{periodicity};
352
    my $freq_to_delete = $subscriptioninformation->{periodicity};
329
    $subscriptioninformation->{periodicity} = $old_frequency;
353
    $subscriptioninformation->{periodicity} = $old_frequency;
330
354
331
    ModSubscription( @$subscriptioninformation{qw(
355
    ModSubscription(
332
        librarian branchcode aqbooksellerid cost aqbudgetid startdate
356
        @$subscriptioninformation{
333
        periodicity firstacquidate irregularity numberpattern locale
357
            qw(
334
        numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
358
                librarian branchcode aqbooksellerid cost aqbudgetid startdate
335
        innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
359
                periodicity firstacquidate irregularity numberpattern locale
336
        letter manualhistory internalnotes serialsadditems staffdisplaycount
360
                numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
337
        opacdisplaycount graceperiod location enddate subscriptionid
361
                innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
338
        skip_serialseq
362
                letter manualhistory internalnotes serialsadditems staffdisplaycount
339
    )} );
363
                opacdisplaycount graceperiod location enddate subscriptionid
364
                skip_serialseq
365
            )
366
        }
367
    );
340
368
341
    DelSubscriptionFrequency($freq_to_delete);
369
    DelSubscriptionFrequency($freq_to_delete);
342
}
370
}
343
371
344
# Test calling subs without parameters
372
# Test calling subs without parameters
345
is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial');
373
is( C4::Serials::AddItem2Serial(),      undef, 'test adding item to serial' );
346
is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription');
374
is( C4::Serials::GetFullSubscription(), undef, 'test getting full subscription' );
347
is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data');
375
is( C4::Serials::PrepareSerialsData(),  undef, 'test preparing serial data' );
348
376
349
subtest 'GetSubscriptionsFromBiblionumber' => sub {
377
subtest 'GetSubscriptionsFromBiblionumber' => sub {
350
    plan tests => 4;
378
    plan tests => 4;
351
379
352
    is( C4::Serials::GetSubscriptionsFromBiblionumber(),
380
    is(
353
        undef, 'test getting subscriptions form biblio number' );
381
        C4::Serials::GetSubscriptionsFromBiblionumber(),
382
        undef, 'test getting subscriptions form biblio number'
383
    );
354
384
355
    my $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber);
385
    my $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber);
356
    ModSubscriptionHistory( $subscriptions->[0]->{subscriptionid},
386
    ModSubscriptionHistory(
357
        undef, undef, $notes, $notes, $notes );
387
        $subscriptions->[0]->{subscriptionid},
388
        undef, undef, $notes, $notes, $notes
389
    );
358
390
359
    $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber);
391
    $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber);
360
    is( $subscriptions->[0]->{opacnote}, $notes,
392
    is(
393
        $subscriptions->[0]->{opacnote}, $notes,
361
        'GetSubscriptionsFromBiblionumber should have returned the opacnote as it is in DB, ie. without br tags'
394
        'GetSubscriptionsFromBiblionumber should have returned the opacnote as it is in DB, ie. without br tags'
362
    );
395
    );
363
    is( $subscriptions->[0]->{recievedlist}, $notes,
396
    is(
397
        $subscriptions->[0]->{recievedlist}, $notes,
364
        'GetSubscriptionsFromBiblionumber should have returned recievedlist as it is in DB, ie. without br tags'
398
        'GetSubscriptionsFromBiblionumber should have returned recievedlist as it is in DB, ie. without br tags'
365
    );
399
    );
366
    is( $subscriptions->[0]->{missinglist}, $notes,
400
    is(
401
        $subscriptions->[0]->{missinglist}, $notes,
367
        'GetSubscriptionsFromBiblionumber should have returned missinglist as it is in DB, ie. without br tags'
402
        'GetSubscriptionsFromBiblionumber should have returned missinglist as it is in DB, ie. without br tags'
368
    );
403
    );
369
};
404
};
370
405
371
is(C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing');
406
is( C4::Serials::GetSerials(),  undef, 'test getting serials when you enter nothing' );
372
is(C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing');
407
is( C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing' );
373
408
374
is(C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials');
409
is( C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials' );
375
410
376
is(C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing');
411
is( C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing' );
377
412
378
is(C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing');
413
is( C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing' );
379
414
380
is(C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered');
415
is( C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered' );
381
416
382
is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history');
417
is( C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history' );
383
418
384
is(C4::Serials::ModSerialStatus(),undef, 'test modding serials');
419
is( C4::Serials::ModSerialStatus(), undef, 'test modding serials' );
385
420
386
is(C4::Serials::findSerialsByStatus(), 0, 'test finding serial by status with no parameters');
421
is( C4::Serials::findSerialsByStatus(), 0, 'test finding serial by status with no parameters' );
387
422
388
is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered');
423
is( C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered' );
389
424
390
is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired');
425
is( C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired' );
391
is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired');
426
is( C4::Serials::HasSubscriptionExpired(),         undef, 'test if the subscriptions has expired' );
392
427
393
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
428
is( C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues' );
394
429
395
subtest 'test_updateClaim' => sub {
430
subtest 'test_updateClaim' => sub {
396
    plan tests => 11;
431
    plan tests => 11;
397
432
398
    my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
433
    my $today = output_pref( { dt => dt_from_string, dateonly => 1 } );
434
399
    # Given ... nothing much
435
    # Given ... nothing much
400
    # When ... Then ...
436
    # When ... Then ...
401
    my $result_0 = C4::Serials::updateClaim(undef);
437
    my $result_0 = C4::Serials::updateClaim(undef);
402
    is($result_0, undef, 'Got the expected undef from update claim with nothin');
438
    is( $result_0, undef, 'Got the expected undef from update claim with nothin' );
403
439
404
    # Given ... 3 serial. 2 of them updated.
440
    # Given ... 3 serial. 2 of them updated.
405
    my $claimdate_1   = dt_from_string('2001-01-13'); # arbitrary date some time in the past.
441
    my $claimdate_1   = dt_from_string('2001-01-13');    # arbitrary date some time in the past.
406
    my $claim_count_1 = 5;
442
    my $claim_count_1 = 5;
407
    my $biblio = $builder->build_sample_biblio;
443
    my $biblio        = $builder->build_sample_biblio;
408
    my $serial1 = $builder->build_object(
444
    my $serial1       = $builder->build_object(
409
        {
445
        {
410
            class => 'Koha::Serials',
446
            class => 'Koha::Serials',
411
            value => {
447
            value => {
Lines 446-536 subtest 'test_updateClaim' => sub { Link Here
446
    );
482
    );
447
483
448
    # When ...
484
    # When ...
449
    my $result_1 = C4::Serials::updateClaim([$serial1->serialid, $serial2->serialid]);
485
    my $result_1 = C4::Serials::updateClaim( [ $serial1->serialid, $serial2->serialid ] );
450
486
451
    # Then ...
487
    # Then ...
452
    is($result_1, 2, 'Got the expected 2 from update claim with 2 serial ids');
488
    is( $result_1, 2, 'Got the expected 2 from update claim with 2 serial ids' );
453
489
454
    my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues(undef, $serial1->serialid);
490
    my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues( undef, $serial1->serialid );
455
    is(output_pref({str => $late_or_missing_issues_1_0[0]->{claimdate}, dateonly => 1}), $today, 'Got the expected first different claim date from update claim');
491
    is(
456
    is($late_or_missing_issues_1_0[0]->{claims_count}, $claim_count_1+1, 'Got the expected first claim count from update claim');
492
        output_pref( { str => $late_or_missing_issues_1_0[0]->{claimdate}, dateonly => 1 } ), $today,
457
    is($late_or_missing_issues_1_0[0]->{status}, 7, 'Got the expected first claim status from update claim');
493
        'Got the expected first different claim date from update claim'
458
494
    );
459
    my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues(undef, $serial2->serialid);
495
    is(
460
    is(output_pref({str => $late_or_missing_issues_1_1[0]->{claimdate}, dateonly => 1}), $today, 'Got the expected second different claim date from update claim');
496
        $late_or_missing_issues_1_0[0]->{claims_count}, $claim_count_1 + 1,
461
    is($late_or_missing_issues_1_1[0]->{claims_count}, $claim_count_1+1, 'Got the expected second claim count from update claim');
497
        'Got the expected first claim count from update claim'
462
    is($late_or_missing_issues_1_1[0]->{status}, 7, 'Got the expected second claim status from update claim');
498
    );
463
499
    is( $late_or_missing_issues_1_0[0]->{status}, 7, 'Got the expected first claim status from update claim' );
464
    my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues(undef, $serial3->serialid);
500
465
    is(output_pref({str => $late_or_missing_issues_1_2[0]->{claimdate}, dateonly => 1}), output_pref({ dt => $claimdate_1, dateonly => 1}), 'Got the expected unchanged claim date from update claim');
501
    my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues( undef, $serial2->serialid );
466
    is($late_or_missing_issues_1_2[0]->{claims_count}, $claim_count_1, 'Got the expected unchanged claim count from update claim');
502
    is(
467
    is($late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim');
503
        output_pref( { str => $late_or_missing_issues_1_1[0]->{claimdate}, dateonly => 1 } ), $today,
504
        'Got the expected second different claim date from update claim'
505
    );
506
    is(
507
        $late_or_missing_issues_1_1[0]->{claims_count}, $claim_count_1 + 1,
508
        'Got the expected second claim count from update claim'
509
    );
510
    is( $late_or_missing_issues_1_1[0]->{status}, 7, 'Got the expected second claim status from update claim' );
511
512
    my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues( undef, $serial3->serialid );
513
    is(
514
        output_pref( { str => $late_or_missing_issues_1_2[0]->{claimdate}, dateonly => 1 } ),
515
        output_pref( { dt  => $claimdate_1,                                dateonly => 1 } ),
516
        'Got the expected unchanged claim date from update claim'
517
    );
518
    is(
519
        $late_or_missing_issues_1_2[0]->{claims_count}, $claim_count_1,
520
        'Got the expected unchanged claim count from update claim'
521
    );
522
    is( $late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim' );
468
};
523
};
469
524
470
is(C4::Serials::check_routing(), undef, 'test checking route');
525
is( C4::Serials::check_routing(),                undef, 'test checking route' );
471
is(C4::Serials::check_routing($subscriptionid), 0, 'There should not have any routing list for the subscription');
526
is( C4::Serials::check_routing($subscriptionid), 0,     'There should not have any routing list for the subscription' );
472
# TODO really test this check_routing subroutine
473
527
474
is(C4::Serials::addroutingmember(),undef, 'test adding route member');
528
# TODO really test this check_routing subroutine
475
529
530
is( C4::Serials::addroutingmember(), undef, 'test adding route member' );
476
531
477
# Unit tests for statuses management (Bug 11689)
532
# Unit tests for statuses management (Bug 11689)
478
$subscriptionid = NewSubscription(
533
$subscriptionid = NewSubscription(
479
    undef,      "",     undef, undef, $budget_id, $biblionumber,
534
    undef,        "",            undef, undef,          $budget_id, $biblionumber,
480
    '2013-01-01', $frequency_id, undef, undef,  undef,
535
    '2013-01-01', $frequency_id, undef, undef,          undef,
481
    undef,      undef,  undef, undef, undef, undef,
536
    undef,        undef,         undef, undef,          undef, undef,
482
    1,          $notes,undef, '2013-01-01', undef, $pattern_id,
537
    1,            $notes,        undef, '2013-01-01',   undef, $pattern_id,
483
    undef,       undef,  0,    $internalnotes,  0,
538
    undef,        undef,         0,     $internalnotes, 0,
484
    undef, undef, 0,          undef,         '2013-12-31', 0
539
    undef,        undef,         0,     undef,          '2013-12-31', 0
485
);
540
);
486
my $total_issues;
541
my $total_issues;
487
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
542
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid);
488
is( $total_issues, 1, "NewSubscription created a first serial" );
543
is( $total_issues, 1, "NewSubscription created a first serial" );
489
is( @serials, 1, "GetSerials returns the serial" );
544
is( @serials,      1, "GetSerials returns the serial" );
490
my $subscription = C4::Serials::GetSubscription($subscriptionid);
545
my $subscription = C4::Serials::GetSubscription($subscriptionid);
491
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
546
my $pattern      = C4::Serials::Numberpattern::GetSubscriptionNumberpattern( $subscription->{numberpattern} );
492
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
547
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid);
493
my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
548
my $publisheddate = output_pref( { dt => dt_from_string, dateformat => 'iso', dateonly => 1 } );
494
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
549
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid);
495
$frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
550
$frequency = C4::Serials::Frequency::GetSubscriptionFrequency( $subscription->{periodicity} );
496
my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, $frequency, 1);
551
my $nextpublisheddate = C4::Serials::GetNextDate( $subscription, $publisheddate, $frequency, 1 );
497
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
552
my @statuses          = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
553
498
# Add 14 serials
554
# Add 14 serials
499
my $counter = 0;
555
my $counter = 0;
500
for my $status ( @statuses ) {
556
for my $status (@statuses) {
501
    my $serialseq = "No.".$counter;
557
    my $serialseq = "No." . $counter;
502
    my ( $expected_serial ) = GetSerials2( $subscriptionid, [1] );
558
    my ($expected_serial) = GetSerials2( $subscriptionid, [1] );
503
    C4::Serials::ModSerialStatus( $expected_serial->{serialid}, $serialseq, $publisheddate, $publisheddate, $publisheddate, $statuses[$counter], 'an useless note' );
559
    C4::Serials::ModSerialStatus(
560
        $expected_serial->{serialid}, $serialseq, $publisheddate, $publisheddate,
561
        $publisheddate, $statuses[$counter], 'an useless note'
562
    );
504
    $counter++;
563
    $counter++;
505
}
564
}
565
506
# Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1
566
# Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1
507
my @serialsByStatus = C4::Serials::findSerialsByStatus(2,$subscriptionid);
567
my @serialsByStatus = C4::Serials::findSerialsByStatus( 2, $subscriptionid );
508
is(@serialsByStatus,2,"findSerialsByStatus returns all serials with chosen status");
568
is( @serialsByStatus, 2, "findSerialsByStatus returns all serials with chosen status" );
509
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
569
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid);
510
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
570
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
511
my @arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;
571
my @arrived_missing = map {
512
my @others = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ } @serials;
572
    my $status = $_->{status};
573
    ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : ()
574
} @serials;
575
my @others = map {
576
    my $status = $_->{status};
577
    ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_
578
} @serials;
513
is( @arrived_missing, 5, "GetSerials returns 5 arrived/missing by default" );
579
is( @arrived_missing, 5, "GetSerials returns 5 arrived/missing by default" );
514
is( @others, 6, "GetSerials returns all serials not arrived and not missing" );
580
is( @others,          6, "GetSerials returns all serials not arrived and not missing" );
515
581
516
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid, 10 );
582
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid, 10 );
517
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
583
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
518
@arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;
584
@arrived_missing = map {
519
@others = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ } @serials;
585
    my $status = $_->{status};
586
    ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : ()
587
} @serials;
588
@others = map {
589
    my $status = $_->{status};
590
    ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_
591
} @serials;
520
is( @arrived_missing, 9, "GetSerials returns all arrived/missing if count given" );
592
is( @arrived_missing, 9, "GetSerials returns all arrived/missing if count given" );
521
is( @others, 6, "GetSerials returns all serials not arrived and not missing if count given" );
593
is( @others,          6, "GetSerials returns all serials not arrived and not missing if count given" );
522
594
523
$subscription = C4::Serials::GetSubscription($subscriptionid); # Retrieve the updated subscription
595
$subscription = C4::Serials::GetSubscription($subscriptionid);    # Retrieve the updated subscription
524
596
525
my @serialseqs;
597
my @serialseqs;
526
for my $am ( @arrived_missing ) {
598
for my $am (@arrived_missing) {
527
    if ( grep {/^$am->{status}$/} qw( 4 41 42 43 44 ) ) {
599
    if ( grep { /^$am->{status}$/ } qw( 4 41 42 43 44 ) ) {
528
        push @serialseqs, $am->{serialseq}
600
        push @serialseqs, $am->{serialseq};
529
    } elsif ( grep {/^$am->{status}$/} qw( 5 ) ) {
601
    } elsif ( grep { /^$am->{status}$/ } qw( 5 ) ) {
530
        push @serialseqs, 'not issued ' . $am->{serialseq};
602
        push @serialseqs, 'not issued ' . $am->{serialseq};
531
    }
603
    }
532
}
604
}
533
is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" );
605
is(
606
    $subscription->{missinglist}, join( '; ', @serialseqs ),
607
    "subscription missinglist is updated after ModSerialStatus"
608
);
534
609
535
subtest "Do not generate an expected if one already exists" => sub {
610
subtest "Do not generate an expected if one already exists" => sub {
536
    plan tests => 2;
611
    plan tests => 2;
Lines 540-555 subtest "Do not generate an expected if one already exists" => sub { Link Here
540
    my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0];
615
    my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0];
541
616
542
    #delete serial with status Expected
617
    #delete serial with status Expected
543
    C4::Serials::ModSerialStatus( $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
618
    C4::Serials::ModSerialStatus(
619
        $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate,
620
        $publisheddate, $publisheddate, '1', 'an useless note'
621
    );
544
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
622
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
545
    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and create another if not exist" );
623
    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and create another if not exist" );
546
624
547
    # add 1 serial with status=Expected 1
625
    # add 1 serial with status=Expected 1
548
    C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
626
    C4::Serials::ModSerialStatus(
627
        $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate,
628
        $publisheddate, '1', 'an useless note'
629
    );
549
630
550
    #Now we have two serials it have status expected
631
    #Now we have two serials it have status expected
551
    #put status delete for last serial
632
    #put status delete for last serial
552
    C4::Serials::ModSerialStatus( $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
633
    C4::Serials::ModSerialStatus(
634
        $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate,
635
        $publisheddate, $publisheddate, '1', 'an useless note'
636
    );
553
637
554
    #try if create or not another serial with status is expected
638
    #try if create or not another serial with status is expected
555
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
639
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
Lines 562-610 subtest "PreserveSerialNotes preference" => sub { Link Here
562
646
563
    t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 1 );
647
    t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 1 );
564
648
565
    C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
649
    C4::Serials::ModSerialStatus(
650
        $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate,
651
        $publisheddate, '1', 'an useless note'
652
    );
566
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
653
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
567
    is( $serialsByStatus[0]->{note},$expected_serial->{note}, "note passed through if supposed to");
654
    is( $serialsByStatus[0]->{note}, $expected_serial->{note}, "note passed through if supposed to" );
568
655
569
    t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 0 );
656
    t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 0 );
570
    $expected_serial = $serialsByStatus[0];
657
    $expected_serial = $serialsByStatus[0];
571
    C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
658
    C4::Serials::ModSerialStatus(
572
    is( $serialsByStatus[0]->{note},$expected_serial->{note}, "note not passed through if not supposed to");
659
        $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate,
660
        $publisheddate, '1', 'an useless note'
661
    );
662
    is( $serialsByStatus[0]->{note}, $expected_serial->{note}, "note not passed through if not supposed to" );
573
663
574
};
664
};
575
665
576
subtest "NewSubscription|ModSubscription" => sub {
666
subtest "NewSubscription|ModSubscription" => sub {
577
    plan tests => 4;
667
    plan tests => 4;
578
    my $subscriptionid = NewSubscription(
668
    my $subscriptionid = NewSubscription(
579
        "",      "",     "", "", $budget_id, $biblionumber,
669
        "",           "",            "", "",             $budget_id, $biblionumber,
580
        '2013-01-01', $frequency_id, "", "",  "",
670
        '2013-01-01', $frequency_id, "", "",             "",
581
        "",      "",  "", "", "", "",
671
        "",           "",            "", "",             "", "",
582
        1,          $notes,"", '2013-01-01', "", $pattern_id,
672
        1,            $notes,        "", '2013-01-01',   "", $pattern_id,
583
        "",       "",  0,    $internalnotes,  0,
673
        "",           "",            0,  $internalnotes, 0,
584
        "", "", 0,          "",         '2013-12-31', 0
674
        "",           "",            0,  "",             '2013-12-31', 0
585
    );
675
    );
586
    ok($subscriptionid, "Sending empty string instead of undef to reflect use of the interface");
676
    ok( $subscriptionid, "Sending empty string instead of undef to reflect use of the interface" );
587
677
588
    my $subscription = Koha::Subscriptions->find($subscriptionid);
678
    my $subscription = Koha::Subscriptions->find($subscriptionid);
589
    my $serials = Koha::Serials->search({ subscriptionid => $subscriptionid });
679
    my $serials      = Koha::Serials->search( { subscriptionid => $subscriptionid } );
590
    is( $serials->count, 1, "NewSubscription created a first serial" );
680
    is( $serials->count, 1, "NewSubscription created a first serial" );
591
681
592
    my $biblio_2 = $builder->build_sample_biblio;
682
    my $biblio_2          = $builder->build_sample_biblio;
593
    my $subscription_info = $subscription->unblessed;
683
    my $subscription_info = $subscription->unblessed;
594
    $subscription_info->{biblionumber} = $biblio_2->biblionumber;
684
    $subscription_info->{biblionumber} = $biblio_2->biblionumber;
595
    ModSubscription( @$subscription_info{qw(
685
    ModSubscription(
596
        librarian branchcode aqbooksellerid cost aqbudgetid startdate
686
        @$subscription_info{
597
        periodicity firstacquidate irregularity numberpattern locale
687
            qw(
598
        numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
688
                librarian branchcode aqbooksellerid cost aqbudgetid startdate
599
        innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
689
                periodicity firstacquidate irregularity numberpattern locale
600
        letter manualhistory internalnotes serialsadditems staffdisplaycount
690
                numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
601
        opacdisplaycount graceperiod location enddate subscriptionid
691
                innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
602
        skip_serialseq
692
                letter manualhistory internalnotes serialsadditems staffdisplaycount
603
    )} );
693
                opacdisplaycount graceperiod location enddate subscriptionid
604
694
                skip_serialseq
605
    $serials = Koha::Serials->search({ subscriptionid => $subscriptionid });
695
            )
696
        }
697
    );
698
699
    $serials = Koha::Serials->search( { subscriptionid => $subscriptionid } );
606
    is( $serials->count, 1, "Still only one serial" );
700
    is( $serials->count, 1, "Still only one serial" );
607
    is( $serials->next->biblionumber, $biblio_2->biblionumber, 'ModSubscription should have updated serial.biblionumber');
701
    is(
702
        $serials->next->biblionumber, $biblio_2->biblionumber,
703
        'ModSubscription should have updated serial.biblionumber'
704
    );
608
};
705
};
609
706
610
subtest "test numbering pattern with dates in GetSeq GetNextSeq" => sub {
707
subtest "test numbering pattern with dates in GetSeq GetNextSeq" => sub {
Lines 645-663 subtest "test numbering pattern with dates in GetSeq GetNextSeq" => sub { Link Here
645
742
646
subtest "_numeration" => sub {
743
subtest "_numeration" => sub {
647
744
648
    plan tests => 6;
745
    plan tests => 8;
649
746
650
    my $s = C4::Serials::_numeration(0, 'monthname', 'cat');
747
    my $s = C4::Serials::_numeration( 0, 'monthname', 'cat' );
651
    is( $s, "gener" );
748
    is( $s, "gener" );
652
    $s = C4::Serials::_numeration(0, 'monthname', 'es');
749
    $s = C4::Serials::_numeration( 0, 'monthname', 'es' );
653
    is( $s, "enero" );
750
    is( $s, "enero" );
654
    $s = C4::Serials::_numeration(0, 'monthname', 'fr');
751
    $s = C4::Serials::_numeration( 0, 'monthname', 'fr' );
655
    is( $s, "janvier" );
752
    is( $s, "janvier" );
656
753
657
    $s = C4::Serials::_numeration(0, 'monthabrv', 'cat');
754
    $s = C4::Serials::_numeration( 0, 'monthabrv', 'cat' );
658
    is( $s, "de gen." );
755
    is( $s, "de gen." );
659
    $s = C4::Serials::_numeration(0, 'monthabrv', 'es');
756
    $s = C4::Serials::_numeration( 0, 'monthabrv', 'es' );
660
    like( $s, qr{^ene\.?} );
757
    like( $s, qr{^ene\.?} );
661
    $s = C4::Serials::_numeration(0, 'monthabrv', 'fr');
758
    $s = C4::Serials::_numeration( 0, 'monthabrv', 'fr' );
662
    is( $s, "janv." );
759
    is( $s, "janv." );
760
761
    my $translations = {
762
        seasons     => [ 'Spring', 'Summer', 'Fall', 'Winter' ],
763
        seasonsabrv => [ 'Spr',    'Sum',    'Fal',  'Win' ],
764
    };
765
766
    $s = C4::Serials::_numeration( 0, 'season', 'en', $translations );
767
    is( $s, "Spring" );
768
    $s = C4::Serials::_numeration( 0, 'seasonabrv', 'en', $translations );
769
    is( $s, "Spr" );
770
};
771
772
subtest "GetSeasonsTranslations" => sub {
773
774
    plan tests => 8;
775
776
    my @seasons     = qw( Printemps Été Automne Hiver );
777
    my @seasonsabrv = qw( Pri Été Aut Hiv );
778
779
    my $dir      = C4::Context->config('intranetdir') . '/misc/translator/po/';
780
    my $fh       = File::Temp->new( DIR => $dir, SUFFIX => '-staff-prog.po' );
781
    my $filename = $fh->filename;
782
783
    my $txt = '
784
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530
785
#, c-format
786
msgid "Spring"
787
msgstr "Printemps"
788
789
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530
790
#, c-format
791
msgid "Summer"
792
msgstr "Été"
793
794
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530
795
#, c-format
796
msgid "Fall"
797
msgstr "Automne"
798
799
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530
800
#, c-format
801
msgid "Winter"
802
msgstr "Hiver"
803
804
#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:208
805
#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:210
806
#, c-format
807
msgid "Sum"
808
msgstr "Total"
809
810
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt:248
811
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt:43
812
#, c-format
813
msgid ""
814
"%s %sSpring%s %s %sSummer%s %s %sFall%s %s %sWinter%s %s %sSpr%s %s %sSum%s "
815
"%s %sFal%s %s %sWin%s %s %s %s "
816
msgstr ""
817
"%s %sPrintemps%s %s %sÉté%s %s %sAutomne%s %s %sHiver%s %s %sPri%s %s %sÉté"
818
"%s %s %sAut%s %s %sHiv%s %s %s %s "
819
    ';
820
821
    print $fh encode( 'utf-8', $txt );
822
    close($fh);
823
824
    my $translations = GetSeasonsTranslations( 1, 1, $filename =~ s/($dir|-staff-prog.po)//gr );
825
826
    for my $idx ( 0 .. $#{ $translations->{seasons} } ) {
827
        is( $translations->{seasons}->[$idx],     $seasons[$idx] );
828
        is( $translations->{seasonsabrv}->[$idx], $seasonsabrv[$idx] );
829
    }
663
};
830
};
(-)a/t/db_dependent/Serials/GetNextSeq.t (-183 / +187 lines)
Lines 12-19 use C4::Serials::Frequency; Link Here
12
use C4::Serials qw( GetNextDate GetNextSeq );
12
use C4::Serials qw( GetNextDate GetNextSeq );
13
13
14
my $frequency = {
14
my $frequency = {
15
    description => "One issue per day",
15
    description   => "One issue per day",
16
    unit => 'day',
16
    unit          => 'day',
17
    issuesperunit => 1,
17
    issuesperunit => 1,
18
    unitsperissue => 1,
18
    unitsperissue => 1,
19
};
19
};
Lines 21-275 my $id = AddSubscriptionFrequency($frequency); Link Here
21
21
22
# TEST CASE 1 - 1 variable, from 1 to 4
22
# TEST CASE 1 - 1 variable, from 1 to 4
23
my $pattern = {
23
my $pattern = {
24
             add1 =>  1,          add2 =>  0,          add3 =>  0,
24
    add1            => 1, add2          => 0, add3          => 0,
25
           every1 =>  1,        every2 =>  0,        every3 =>  0,
25
    every1          => 1, every2        => 0, every3        => 0,
26
    whenmorethan1 =>  4, whenmorethan2 =>  0, whenmorethan3 =>  0,
26
    whenmorethan1   => 4, whenmorethan2 => 0, whenmorethan3 => 0,
27
           setto1 =>  1,        setto2 =>  0,        setto3 =>  0,
27
    setto1          => 1, setto2        => 0, setto3        => 0,
28
    numberingmethod => 'X: {X}',
28
    numberingmethod => 'X: {X}',
29
    numbering1 => '',
29
    numbering1      => '',
30
    numbering2 => '',
30
    numbering2      => '',
31
    numbering3 => '',
31
    numbering3      => '',
32
};
32
};
33
33
34
my $subscription = {
34
my $subscription = {
35
    periodicity => $id,
35
    periodicity        => $id,
36
    firstacquidate => '1970-01-01',
36
    firstacquidate     => '1970-01-01',
37
    lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
37
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
38
    innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
38
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
39
    skip_serialseq => 1,
39
    skip_serialseq     => 1,
40
    irregularity => '3;5',
40
    irregularity       => '3;5',
41
    countissuesperunit => 1,
41
    countissuesperunit => 1,
42
    locale => 'en',
42
    locale             => 'en',
43
};
43
};
44
my $publisheddate = $subscription->{firstacquidate};
44
my $publisheddate = $subscription->{firstacquidate};
45
45
46
my $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
46
my $seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
47
is($seq, 'X: 2');
47
is( $seq, 'X: 2' );
48
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
48
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
49
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
49
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
50
is($seq, 'X: 4');
50
is( $seq, 'X: 4' );
51
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
51
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
52
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
52
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
53
is($seq, 'X: 2');
53
is( $seq, 'X: 2' );
54
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
54
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
55
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
55
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
56
is($seq, 'X: 3');
56
is( $seq, 'X: 3' );
57
57
58
# TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
58
# TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
59
$subscription = {
59
$subscription = {
60
    periodicity => $id,
60
    periodicity        => $id,
61
    firstacquidate => '1970-01-01',
61
    firstacquidate     => '1970-01-01',
62
    lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
62
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
63
    innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
63
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
64
    skip_serialseq => 1,
64
    skip_serialseq     => 1,
65
    irregularity => '3;4;6',
65
    irregularity       => '3;4;6',
66
    countissuesperunit => 1,
66
    countissuesperunit => 1,
67
    locale => 'C',
67
    locale             => 'C',
68
};
68
};
69
$pattern = {
69
$pattern = {
70
             add1 =>  1,          add2 =>  0,          add3 =>  0,
70
    add1            => 1, add2          => 0, add3          => 0,
71
           every1 =>  1,        every2 =>  0,        every3 =>  0,
71
    every1          => 1, every2        => 0, every3        => 0,
72
    whenmorethan1 =>  7, whenmorethan2 =>  0, whenmorethan3 =>  0,
72
    whenmorethan1   => 7, whenmorethan2 => 0, whenmorethan3 => 0,
73
           setto1 =>  1,        setto2 =>  0,        setto3 =>  0,
73
    setto1          => 1, setto2        => 0, setto3        => 0,
74
    numberingmethod => 'X: {X}',
74
    numberingmethod => 'X: {X}',
75
    numbering1 => 'dayname',
75
    numbering1      => 'dayname',
76
    numbering2 => '',
76
    numbering2      => '',
77
    numbering3 => '',
77
    numbering3      => '',
78
};
78
};
79
79
80
$publisheddate = $subscription->{firstacquidate};
80
$publisheddate = $subscription->{firstacquidate};
81
81
82
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
82
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
83
is($seq, 'X: Tuesday');
83
is( $seq, 'X: Tuesday' );
84
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
84
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
85
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
85
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
86
is($seq, 'X: Friday');
86
is( $seq, 'X: Friday' );
87
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
87
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
88
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
88
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
89
is($seq, 'X: Sunday');
89
is( $seq, 'X: Sunday' );
90
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
90
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
91
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
91
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
92
is($seq, 'X: Monday');
92
is( $seq, 'X: Monday' );
93
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
93
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
94
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
94
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
95
is($seq, 'X: Tuesday');
95
is( $seq, 'X: Tuesday' );
96
96
97
# TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
97
# TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
98
$subscription = {
98
$subscription = {
99
    periodicity => $id,
99
    periodicity        => $id,
100
    firstacquidate => '1970-01-01',
100
    firstacquidate     => '1970-01-01',
101
    lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1,
101
    lastvalue1         => 0, lastvalue2 => 1, lastvalue3 => 1,
102
    innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
102
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
103
    skip_serialseq => 1,
103
    skip_serialseq     => 1,
104
    irregularity => '3;4;6',
104
    irregularity       => '3;4;6',
105
    countissuesperunit => 1,
105
    countissuesperunit => 1,
106
    locale => 'C',
106
    locale             => 'C',
107
};
107
};
108
$pattern = {
108
$pattern = {
109
             add1 =>  2,          add2 =>  0,          add3 =>  0,
109
    add1            => 2,  add2          => 0, add3          => 0,
110
           every1 =>  1,        every2 =>  0,        every3 =>  0,
110
    every1          => 1,  every2        => 0, every3        => 0,
111
    whenmorethan1 => 11, whenmorethan2 =>  0, whenmorethan3 =>  0,
111
    whenmorethan1   => 11, whenmorethan2 => 0, whenmorethan3 => 0,
112
           setto1 =>  0,        setto2 =>  0,        setto3 =>  0,
112
    setto1          => 0,  setto2        => 0, setto3        => 0,
113
    numberingmethod => 'X: {X}',
113
    numberingmethod => 'X: {X}',
114
    numbering1 => 'monthname',
114
    numbering1      => 'monthname',
115
    numbering2 => '',
115
    numbering2      => '',
116
    numbering3 => '',
116
    numbering3      => '',
117
};
117
};
118
118
119
$publisheddate = $subscription->{firstacquidate};
119
$publisheddate = $subscription->{firstacquidate};
120
120
121
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
121
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
122
is($seq, 'X: March');
122
is( $seq, 'X: March' );
123
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
123
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
124
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
124
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
125
is($seq, 'X: September');
125
is( $seq, 'X: September' );
126
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
126
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
127
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
127
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
128
is($seq, 'X: January');
128
is( $seq, 'X: January' );
129
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
129
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
130
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
130
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
131
is($seq, 'X: March');
131
is( $seq, 'X: March' );
132
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
132
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
133
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
133
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
134
is($seq, 'X: May');
134
is( $seq, 'X: May' );
135
135
136
# TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
136
# TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
137
$subscription = {
137
$subscription = {
138
    periodicity => $id,
138
    periodicity        => $id,
139
    firstacquidate => '1970-01-01',
139
    firstacquidate     => '1970-01-01',
140
    lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1,
140
    lastvalue1         => 0, lastvalue2 => 1, lastvalue3 => 1,
141
    innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
141
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
142
    skip_serialseq => 1,
142
    skip_serialseq     => 1,
143
    irregularity => '3;4;6',
143
    irregularity       => '3;4;6',
144
    countissuesperunit => 1,
144
    countissuesperunit => 1,
145
    locale => 'C',
145
    locale             => 'C',
146
    translations       => { seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ] },
146
};
147
};
147
$pattern = {
148
$pattern = {
148
             add1 =>  1,          add2 =>  0,          add3 =>  0,
149
    add1            => 1, add2          => 0, add3          => 0,
149
           every1 =>  1,        every2 =>  0,        every3 =>  0,
150
    every1          => 1, every2        => 0, every3        => 0,
150
    whenmorethan1 =>  3, whenmorethan2 =>  0, whenmorethan3 =>  0,
151
    whenmorethan1   => 3, whenmorethan2 => 0, whenmorethan3 => 0,
151
           setto1 =>  0,        setto2 =>  0,        setto3 =>  0,
152
    setto1          => 0, setto2        => 0, setto3        => 0,
152
    numberingmethod => 'X: {X}',
153
    numberingmethod => 'X: {X}',
153
    numbering1 => 'season',
154
    numbering1      => 'season',
154
    numbering2 => '',
155
    numbering2      => '',
155
    numbering3 => '',
156
    numbering3      => '',
156
};
157
};
157
158
158
$publisheddate = $subscription->{firstacquidate};
159
$publisheddate = $subscription->{firstacquidate};
159
160
160
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
161
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
161
is($seq, 'X: Summer');
162
is( $seq, 'X: Summer' );
162
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
163
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
163
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
164
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
164
is($seq, 'X: Spring');
165
is( $seq, 'X: Spring' );
165
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
166
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
166
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
167
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
167
is($seq, 'X: Fall');
168
is( $seq, 'X: Fall' );
168
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
169
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
169
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
170
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
170
is($seq, 'X: Winter');
171
is( $seq, 'X: Winter' );
171
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
172
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
172
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
173
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
173
is($seq, 'X: Spring');
174
is( $seq, 'X: Spring' );
174
175
175
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
176
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
176
$subscription = {
177
$subscription = {
177
    periodicity => $id,
178
    periodicity        => $id,
178
    firstacquidate => '1970-01-01',
179
    firstacquidate     => '1970-01-01',
179
    lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
180
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
180
    innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
181
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
181
    skip_serialseq => 1,
182
    skip_serialseq     => 1,
182
    irregularity => '3;4;6',
183
    irregularity       => '3;4;6',
183
    countissuesperunit => 1,
184
    countissuesperunit => 1,
184
    locale => 'C',
185
    locale             => 'C',
185
};
186
};
186
$pattern = {
187
$pattern = {
187
             add1 =>  1,          add2 =>  1,          add3 =>  0,
188
    add1            => 1, add2          => 1,  add3          => 0,
188
           every1 =>  1,        every2 =>  4,        every3 =>  0,
189
    every1          => 1, every2        => 4,  every3        => 0,
189
    whenmorethan1 =>  4, whenmorethan2 => 12, whenmorethan3 =>  0,
190
    whenmorethan1   => 4, whenmorethan2 => 12, whenmorethan3 => 0,
190
           setto1 =>  1,        setto2 =>  1,        setto3 =>  0,
191
    setto1          => 1, setto2        => 1,  setto3        => 0,
191
    numberingmethod => 'Y: {Y}, X: {X}',
192
    numberingmethod => 'Y: {Y}, X: {X}',
192
    numbering1 => '',
193
    numbering1      => '',
193
    numbering2 => '',
194
    numbering2      => '',
194
    numbering3 => '',
195
    numbering3      => '',
195
};
196
};
196
197
197
$publisheddate = $subscription->{firstacquidate};
198
$publisheddate = $subscription->{firstacquidate};
198
199
199
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
200
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
200
is($seq, 'Y: 1, X: 2');
201
is( $seq, 'Y: 1, X: 2' );
201
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
202
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
202
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
203
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
203
is($seq, 'Y: 2, X: 1');
204
is( $seq, 'Y: 2, X: 1' );
204
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
205
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
205
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
206
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
206
is($seq, 'Y: 2, X: 3');
207
is( $seq, 'Y: 2, X: 3' );
207
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
208
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
208
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
209
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
209
is($seq, 'Y: 2, X: 4');
210
is( $seq, 'Y: 2, X: 4' );
210
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
211
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
211
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
212
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
212
is($seq, 'Y: 3, X: 1');
213
is( $seq, 'Y: 3, X: 1' );
213
214
214
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
215
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
215
$subscription = {
216
$subscription = {
216
    periodicity => $id,
217
    periodicity        => $id,
217
    firstacquidate => '1970-01-01',
218
    firstacquidate     => '1970-01-01',
218
    lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
219
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
219
    innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
220
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
220
    skip_serialseq => 1,
221
    skip_serialseq     => 1,
221
    irregularity => '3;4;6;110',
222
    irregularity       => '3;4;6;110',
222
    countissuesperunit => 1,
223
    countissuesperunit => 1,
223
    locale => 'C',
224
    locale             => 'C',
224
};
225
};
225
$pattern = {
226
$pattern = {
226
             add1 =>  1,          add2 =>  1,          add3 =>  1,
227
    add1            => 1, add2          => 1, add3          => 1,
227
           every1 =>  1,        every2 =>  4,        every3 => 32,
228
    every1          => 1, every2        => 4, every3        => 32,
228
    whenmorethan1 =>  4, whenmorethan2 =>  8, whenmorethan3 => 12,
229
    whenmorethan1   => 4, whenmorethan2 => 8, whenmorethan3 => 12,
229
           setto1 =>  1,        setto2 =>  1,        setto3 =>  1,
230
    setto1          => 1, setto2        => 1, setto3        => 1,
230
    numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}',
231
    numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}',
231
    numbering1 => '',
232
    numbering1      => '',
232
    numbering2 => '',
233
    numbering2      => '',
233
    numbering3 => '',
234
    numbering3      => '',
234
};
235
};
235
236
236
$publisheddate = $subscription->{firstacquidate};
237
$publisheddate = $subscription->{firstacquidate};
237
238
238
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
239
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
239
is($seq, 'Z: 1, Y: 1, X: 2');
240
is( $seq, 'Z: 1, Y: 1, X: 2' );
240
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
241
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
241
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
242
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
242
is($seq, 'Z: 1, Y: 2, X: 1');
243
is( $seq, 'Z: 1, Y: 2, X: 1' );
243
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
244
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
244
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
245
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
245
is($seq, 'Z: 1, Y: 2, X: 3');
246
is( $seq, 'Z: 1, Y: 2, X: 3' );
246
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
247
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
247
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
248
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
248
is($seq, 'Z: 1, Y: 2, X: 4');
249
is( $seq, 'Z: 1, Y: 2, X: 4' );
249
for (1..100) {
250
250
    $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
251
for ( 1 .. 100 ) {
251
    $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
252
    $publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
253
    $seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
252
}
254
}
253
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
255
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
254
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
256
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
255
is($seq, 'Z: 4, Y: 4, X: 1');
257
is( $seq, 'Z: 4, Y: 4, X: 1' );
258
256
# 110th is here
259
# 110th is here
257
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
260
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
258
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
261
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
259
is($seq, 'Z: 4, Y: 4, X: 3');
262
is( $seq, 'Z: 4, Y: 4, X: 3' );
260
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
263
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
261
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
264
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
262
is($seq, 'Z: 4, Y: 4, X: 4');
265
is( $seq, 'Z: 4, Y: 4, X: 4' );
263
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
266
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
264
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
267
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
265
is($seq, 'Z: 4, Y: 5, X: 1');
268
is( $seq, 'Z: 4, Y: 5, X: 1' );
266
269
267
sub _next_seq {
270
sub _next_seq {
268
    my ($subscription, $pattern, $frequency, $publisheddate) = @_;
271
    my ( $subscription, $pattern, $frequency, $publisheddate ) = @_;
269
    my $seq;
272
    my $seq;
270
    ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
273
    (
274
        $seq,                        $subscription->{lastvalue1}, $subscription->{lastvalue2},
271
        $subscription->{lastvalue3}, $subscription->{innerloop1},
275
        $subscription->{lastvalue3}, $subscription->{innerloop1},
272
        $subscription->{innerloop2}, $subscription->{innerloop3}) =
276
        $subscription->{innerloop2}, $subscription->{innerloop3}
273
            GetNextSeq($subscription, $pattern, $frequency, $publisheddate);
277
    ) = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate );
274
    return $seq;
278
    return $seq;
275
}
279
}
(-)a/t/db_dependent/Serials/GetNextSeq.t.tdy (-1 / +279 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use C4::Context;
4
use Test::More tests => 32;
5
use Modern::Perl;
6
use Koha::Database;
7
8
my $schema = Koha::Database->new->schema;
9
$schema->storage->txn_begin;
10
11
use C4::Serials::Frequency;
12
use C4::Serials qw( GetNextDate GetNextSeq );
13
14
my $frequency = {
15
    description   => "One issue per day",
16
    unit          => 'day',
17
    issuesperunit => 1,
18
    unitsperissue => 1,
19
};
20
my $id = AddSubscriptionFrequency($frequency);
21
22
# TEST CASE 1 - 1 variable, from 1 to 4
23
my $pattern = {
24
    add1            => 1, add2          => 0, add3          => 0,
25
    every1          => 1, every2        => 0, every3        => 0,
26
    whenmorethan1   => 4, whenmorethan2 => 0, whenmorethan3 => 0,
27
    setto1          => 1, setto2        => 0, setto3        => 0,
28
    numberingmethod => 'X: {X}',
29
    numbering1      => '',
30
    numbering2      => '',
31
    numbering3      => '',
32
};
33
34
my $subscription = {
35
    periodicity        => $id,
36
    firstacquidate     => '1970-01-01',
37
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
38
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
39
    skip_serialseq     => 1,
40
    irregularity       => '3;5',
41
    countissuesperunit => 1,
42
    locale             => 'en',
43
};
44
my $publisheddate = $subscription->{firstacquidate};
45
46
my $seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
47
is( $seq, 'X: 2' );
48
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
49
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
50
is( $seq, 'X: 4' );
51
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
52
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
53
is( $seq, 'X: 2' );
54
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
55
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
56
is( $seq, 'X: 3' );
57
58
# TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
59
$subscription = {
60
    periodicity        => $id,
61
    firstacquidate     => '1970-01-01',
62
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
63
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
64
    skip_serialseq     => 1,
65
    irregularity       => '3;4;6',
66
    countissuesperunit => 1,
67
    locale             => 'C',
68
};
69
$pattern = {
70
    add1            => 1, add2          => 0, add3          => 0,
71
    every1          => 1, every2        => 0, every3        => 0,
72
    whenmorethan1   => 7, whenmorethan2 => 0, whenmorethan3 => 0,
73
    setto1          => 1, setto2        => 0, setto3        => 0,
74
    numberingmethod => 'X: {X}',
75
    numbering1      => 'dayname',
76
    numbering2      => '',
77
    numbering3      => '',
78
};
79
80
$publisheddate = $subscription->{firstacquidate};
81
82
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
83
is( $seq, 'X: Tuesday' );
84
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
85
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
86
is( $seq, 'X: Friday' );
87
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
88
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
89
is( $seq, 'X: Sunday' );
90
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
91
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
92
is( $seq, 'X: Monday' );
93
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
94
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
95
is( $seq, 'X: Tuesday' );
96
97
# TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
98
$subscription = {
99
    periodicity        => $id,
100
    firstacquidate     => '1970-01-01',
101
    lastvalue1         => 0, lastvalue2 => 1, lastvalue3 => 1,
102
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
103
    skip_serialseq     => 1,
104
    irregularity       => '3;4;6',
105
    countissuesperunit => 1,
106
    locale             => 'C',
107
};
108
$pattern = {
109
    add1            => 2,  add2          => 0, add3          => 0,
110
    every1          => 1,  every2        => 0, every3        => 0,
111
    whenmorethan1   => 11, whenmorethan2 => 0, whenmorethan3 => 0,
112
    setto1          => 0,  setto2        => 0, setto3        => 0,
113
    numberingmethod => 'X: {X}',
114
    numbering1      => 'monthname',
115
    numbering2      => '',
116
    numbering3      => '',
117
};
118
119
$publisheddate = $subscription->{firstacquidate};
120
121
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
122
is( $seq, 'X: March' );
123
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
124
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
125
is( $seq, 'X: September' );
126
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
127
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
128
is( $seq, 'X: January' );
129
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
130
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
131
is( $seq, 'X: March' );
132
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
133
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
134
is( $seq, 'X: May' );
135
136
# TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
137
$subscription = {
138
    periodicity        => $id,
139
    firstacquidate     => '1970-01-01',
140
    lastvalue1         => 0, lastvalue2 => 1, lastvalue3 => 1,
141
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
142
    skip_serialseq     => 1,
143
    irregularity       => '3;4;6',
144
    countissuesperunit => 1,
145
    locale             => 'C',
146
    translations       => { seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ] },
147
};
148
$pattern = {
149
    add1            => 1, add2          => 0, add3          => 0,
150
    every1          => 1, every2        => 0, every3        => 0,
151
    whenmorethan1   => 3, whenmorethan2 => 0, whenmorethan3 => 0,
152
    setto1          => 0, setto2        => 0, setto3        => 0,
153
    numberingmethod => 'X: {X}',
154
    numbering1      => 'season',
155
    numbering2      => '',
156
    numbering3      => '',
157
};
158
159
$publisheddate = $subscription->{firstacquidate};
160
161
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
162
is( $seq, 'X: Summer' );
163
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
164
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
165
is( $seq, 'X: Spring' );
166
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
167
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
168
is( $seq, 'X: Fall' );
169
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
170
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
171
is( $seq, 'X: Winter' );
172
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
173
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
174
is( $seq, 'X: Spring' );
175
176
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
177
$subscription = {
178
    periodicity        => $id,
179
    firstacquidate     => '1970-01-01',
180
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
181
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
182
    skip_serialseq     => 1,
183
    irregularity       => '3;4;6',
184
    countissuesperunit => 1,
185
    locale             => 'C',
186
};
187
$pattern = {
188
    add1            => 1, add2          => 1,  add3          => 0,
189
    every1          => 1, every2        => 4,  every3        => 0,
190
    whenmorethan1   => 4, whenmorethan2 => 12, whenmorethan3 => 0,
191
    setto1          => 1, setto2        => 1,  setto3        => 0,
192
    numberingmethod => 'Y: {Y}, X: {X}',
193
    numbering1      => '',
194
    numbering2      => '',
195
    numbering3      => '',
196
};
197
198
$publisheddate = $subscription->{firstacquidate};
199
200
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
201
is( $seq, 'Y: 1, X: 2' );
202
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
203
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
204
is( $seq, 'Y: 2, X: 1' );
205
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
206
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
207
is( $seq, 'Y: 2, X: 3' );
208
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
209
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
210
is( $seq, 'Y: 2, X: 4' );
211
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
212
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
213
is( $seq, 'Y: 3, X: 1' );
214
215
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
216
$subscription = {
217
    periodicity        => $id,
218
    firstacquidate     => '1970-01-01',
219
    lastvalue1         => 1, lastvalue2 => 1, lastvalue3 => 1,
220
    innerloop1         => 0, innerloop2 => 0, innerloop3 => 0,
221
    skip_serialseq     => 1,
222
    irregularity       => '3;4;6;110',
223
    countissuesperunit => 1,
224
    locale             => 'C',
225
};
226
$pattern = {
227
    add1            => 1, add2          => 1, add3          => 1,
228
    every1          => 1, every2        => 4, every3        => 32,
229
    whenmorethan1   => 4, whenmorethan2 => 8, whenmorethan3 => 12,
230
    setto1          => 1, setto2        => 1, setto3        => 1,
231
    numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}',
232
    numbering1      => '',
233
    numbering2      => '',
234
    numbering3      => '',
235
};
236
237
$publisheddate = $subscription->{firstacquidate};
238
239
$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
240
is( $seq, 'Z: 1, Y: 1, X: 2' );
241
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
242
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
243
is( $seq, 'Z: 1, Y: 2, X: 1' );
244
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
245
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
246
is( $seq, 'Z: 1, Y: 2, X: 3' );
247
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
248
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
249
is( $seq, 'Z: 1, Y: 2, X: 4' );
250
251
for ( 1 .. 100 ) {
252
    $publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
253
    $seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
254
}
255
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
256
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
257
is( $seq, 'Z: 4, Y: 4, X: 1' );
258
259
# 110th is here
260
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
261
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
262
is( $seq, 'Z: 4, Y: 4, X: 3' );
263
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
264
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
265
is( $seq, 'Z: 4, Y: 4, X: 4' );
266
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
267
$seq           = _next_seq( $subscription, $pattern, $frequency, $publisheddate );
268
is( $seq, 'Z: 4, Y: 5, X: 1' );
269
270
sub _next_seq {
271
    my ( $subscription, $pattern, $frequency, $publisheddate ) = @_;
272
    my $seq;
273
    (
274
        $seq,                        $subscription->{lastvalue1}, $subscription->{lastvalue2},
275
        $subscription->{lastvalue3}, $subscription->{innerloop1},
276
        $subscription->{innerloop2}, $subscription->{innerloop3}
277
    ) = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate );
278
    return $seq;
279
}

Return to bug 35590