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

(-)a/C4/Serials.pm (-19 / +20 lines)
Lines 871-889 sub GetDistributedTo { Link Here
871
    my (
871
    my (
872
        $nextseq,       $newlastvalue1, $newlastvalue2, $newlastvalue3,
872
        $nextseq,       $newlastvalue1, $newlastvalue2, $newlastvalue3,
873
        $newinnerloop1, $newinnerloop2, $newinnerloop3
873
        $newinnerloop1, $newinnerloop2, $newinnerloop3
874
    ) = GetNextSeq( $subscription, $pattern, $planneddate );
874
    ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate );
875
875
876
$subscription is a hashref containing all the attributes of the table
876
$subscription is a hashref containing all the attributes of the table
877
'subscription'.
877
'subscription'.
878
$pattern is a hashref containing all the attributes of the table
878
$pattern is a hashref containing all the attributes of the table
879
'subscription_numberpatterns'.
879
'subscription_numberpatterns'.
880
$frequency is a hashref containing all the attributes of the table 'subscription_frequencies'
880
$planneddate is a date string in iso format.
881
$planneddate is a date string in iso format.
881
This function get the next issue for the subscription given on input arg
882
This function get the next issue for the subscription given on input arg
882
883
883
=cut
884
=cut
884
885
885
sub GetNextSeq {
886
sub GetNextSeq {
886
    my ($subscription, $pattern, $planneddate) = @_;
887
    my ($subscription, $pattern, $frequency, $planneddate) = @_;
887
888
888
    return unless ($subscription and $pattern);
889
    return unless ($subscription and $pattern);
889
890
Lines 896-902 sub GetNextSeq { Link Here
896
        if(@irreg > 0) {
897
        if(@irreg > 0) {
897
            my $irregularities = {};
898
            my $irregularities = {};
898
            $irregularities->{$_} = 1 foreach(@irreg);
899
            $irregularities->{$_} = 1 foreach(@irreg);
899
            my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1;
900
            my $issueno = GetFictiveIssueNumber($subscription, $planneddate, $frequency) + 1;
900
            while($irregularities->{$issueno}) {
901
            while($irregularities->{$issueno}) {
901
                $count++;
902
                $count++;
902
                $issueno++;
903
                $issueno++;
Lines 1039-1045 sub GetExpirationDate { Link Here
1039
1040
1040
            #calculate the date of the last issue.
1041
            #calculate the date of the last issue.
1041
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
1042
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
1042
                $enddate = GetNextDate( $subscription, $enddate );
1043
                $enddate = GetNextDate( $subscription, $enddate, $frequency );
1043
            }
1044
            }
1044
        } elsif ( $subscription->{monthlength} ) {
1045
        } elsif ( $subscription->{monthlength} ) {
1045
            if ( $$subscription{startdate} ) {
1046
            if ( $$subscription{startdate} ) {
Lines 1191-1206 sub ModSerialStatus { Link Here
1191
    if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) {
1192
    if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) {
1192
        my $subscription = GetSubscription($subscriptionid);
1193
        my $subscription = GetSubscription($subscriptionid);
1193
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1194
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1195
        my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
1194
1196
1195
        # next issue number
1197
        # next issue number
1196
        my (
1198
        my (
1197
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1199
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1198
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1200
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1199
          )
1201
          )
1200
          = GetNextSeq( $subscription, $pattern, $publisheddate );
1202
          = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate );
1201
1203
1202
        # next date (calculated from actual date & frequency parameters)
1204
        # next date (calculated from actual date & frequency parameters)
1203
        my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1);
1205
        my $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency, 1);
1204
        my $nextpubdate = $nextpublisheddate;
1206
        my $nextpubdate = $nextpublisheddate;
1205
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1207
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1206
                    WHERE  subscriptionid = ?";
1208
                    WHERE  subscriptionid = ?";
Lines 1409-1415 sub NewSubscription { Link Here
1409
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1411
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1410
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1412
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1411
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1413
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1412
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype
1414
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1413
    ) = @_;
1415
    ) = @_;
1414
    my $dbh = C4::Context->dbh;
1416
    my $dbh = C4::Context->dbh;
1415
1417
Lines 1423-1430 sub NewSubscription { Link Here
1423
            irregularity, numberpattern, locale, callnumber,
1425
            irregularity, numberpattern, locale, callnumber,
1424
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1426
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1425
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1427
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1426
            itemtype, previousitemtype)
1428
            itemtype, previousitemtype, mana_id)
1427
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1429
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?)
1428
        |;
1430
        |;
1429
    my $sth = $dbh->prepare($query);
1431
    my $sth = $dbh->prepare($query);
1430
    $sth->execute(
1432
    $sth->execute(
Lines 1435-1441 sub NewSubscription { Link Here
1435
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1437
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1436
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1438
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1437
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1439
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1438
        $itemtype, $previousitemtype
1440
        $itemtype, $previousitemtype, $mana_id
1439
    );
1441
    );
1440
1442
1441
    my $subscriptionid = $dbh->{'mysql_insertid'};
1443
    my $subscriptionid = $dbh->{'mysql_insertid'};
Lines 2193-2199 sub abouttoexpire { Link Here
2193
        my $expirationdate = GetExpirationDate($subscriptionid);
2195
        my $expirationdate = GetExpirationDate($subscriptionid);
2194
2196
2195
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2197
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2196
        my $nextdate = GetNextDate($subscription, $res);
2198
        my $nextdate = GetNextDate($subscription, $res, $frequency);
2197
2199
2198
        # only compare dates if both dates exist.
2200
        # only compare dates if both dates exist.
2199
        if ($nextdate and $expirationdate) {
2201
        if ($nextdate and $expirationdate) {
Lines 2259-2265 sub GetSubscriptionsFromBorrower { Link Here
2259
2261
2260
=head2 GetFictiveIssueNumber
2262
=head2 GetFictiveIssueNumber
2261
2263
2262
$issueno = GetFictiveIssueNumber($subscription, $publishedate);
2264
$issueno = GetFictiveIssueNumber($subscription, $publishedate, $frequency);
2263
2265
2264
Get the position of the issue published at $publisheddate, considering the
2266
Get the position of the issue published at $publisheddate, considering the
2265
first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
2267
first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
Lines 2278-2286 date (in GetNextDate) or the next issue number (in GetNextSeq). Link Here
2278
=cut
2280
=cut
2279
2281
2280
sub GetFictiveIssueNumber {
2282
sub GetFictiveIssueNumber {
2281
    my ($subscription, $publisheddate) = @_;
2283
    my ($subscription, $publisheddate, $frequency) = @_;
2282
2284
2283
    my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'});
2284
    my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
2285
    my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
2285
    return if !$unit;
2286
    return if !$unit;
2286
    my $issueno;
2287
    my $issueno;
Lines 2424-2435 sub _get_next_date_year { Link Here
2424
2425
2425
=head2 GetNextDate
2426
=head2 GetNextDate
2426
2427
2427
$resultdate = GetNextDate($publisheddate,$subscription)
2428
$resultdate = GetNextDate($publisheddate,$subscription,$freqdata,$updatecount)
2428
2429
2429
this function it takes the publisheddate and will return the next issue's date
2430
this function it takes the publisheddate and will return the next issue's date
2430
and will skip dates if there exists an irregularity.
2431
and will skip dates if there exists an irregularity.
2431
$publisheddate has to be an ISO date
2432
$publisheddate has to be an ISO date
2432
$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit'
2433
$subscription is a hashref containing at least 'firstacquidate', 'irregularity', and 'countissuesperunit'
2434
$frequency is a hashref containing frequency informations
2433
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2435
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2434
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2436
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2435
skipped then the returned date will be 2007-05-10
2437
skipped then the returned date will be 2007-05-10
Lines 2442-2452 Return undef if subscription is irregular Link Here
2442
=cut
2444
=cut
2443
2445
2444
sub GetNextDate {
2446
sub GetNextDate {
2445
    my ( $subscription, $publisheddate, $updatecount ) = @_;
2447
    my ( $subscription, $publisheddate, $freqdata, $updatecount ) = @_;
2446
2448
2447
    return unless $subscription and $publisheddate;
2449
    return unless $subscription and $publisheddate;
2448
2450
2449
    my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'});
2450
2451
2451
    if ($freqdata->{'unit'}) {
2452
    if ($freqdata->{'unit'}) {
2452
        my ( $year, $month, $day ) = split /-/, $publisheddate;
2453
        my ( $year, $month, $day ) = split /-/, $publisheddate;
Lines 2466-2472 sub GetNextDate { Link Here
2466
2467
2467
        # Get the 'fictive' next issue number
2468
        # Get the 'fictive' next issue number
2468
        # It is used to check if next issue is an irregular issue.
2469
        # It is used to check if next issue is an irregular issue.
2469
        my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1;
2470
        my $issueno = GetFictiveIssueNumber($subscription, $publisheddate, $freqdata) + 1;
2470
2471
2471
        # Then get the next date
2472
        # Then get the next date
2472
        my $unit = lc $freqdata->{'unit'};
2473
        my $unit = lc $freqdata->{'unit'};
(-)a/Koha/Subscription.pm (+66 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Biblios;
26
use Koha::Biblioitems;
27
use Koha::Subscriptions;
28
use Koha::Subscription::Frequencies;
29
use Koha::Subscription::Numberpatterns;
30
use JSON;
25
31
26
use base qw(Koha::Object);
32
use base qw(Koha::Object);
27
33
Lines 39-44 Koha::Subscription - Koha Subscription Object class Link Here
39
45
40
=cut
46
=cut
41
47
48
sub get_search_info {
49
    my $searched_sub_id = shift;
50
    my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } );
51
    my $biblioitem =
52
      Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } );
53
54
    my $sub_mana_info = {
55
        'title'         => $biblio->title,
56
        'issn'          => $biblioitem->issn,
57
        'ean'           => $biblioitem->ean,
58
        'publishercode' => $biblioitem->publishercode
59
    };
60
    return $sub_mana_info;
61
}
62
63
sub get_sharable_info {
64
    my $shared_sub_id = shift;
65
    my $subscription  = Koha::Subscriptions->find($shared_sub_id);
66
    my $biblio        = Koha::Biblios->find( $subscription->biblionumber );
67
    my $biblioitem    = Koha::Biblioitems->find(
68
        { 'biblionumber' => $subscription->biblionumber } );
69
    my $sub_frequency =
70
      Koha::Subscription::Frequencies->find( $subscription->periodicity );
71
    my $sub_numberpatteern =
72
      Koha::Subscription::Numberpatterns->find( $subscription->numberpattern );
73
74
    my $sub_mana_info = {
75
        'title'           => $biblio->title,
76
        'sfdescription'   => $sub_frequency->description,
77
        'unit'            => $sub_frequency->unit,
78
        'unitsperissue'   => $sub_frequency->unitsperissue,
79
        'issuesperunit'   => $sub_frequency->issuesperunit,
80
        'label'           => $sub_numberpatteern->label,
81
        'sndescription'   => $sub_numberpatteern->description,
82
        'numberingmethod' => $sub_numberpatteern->numberingmethod,
83
        'label1'          => $sub_numberpatteern->label1,
84
        'add1'            => $sub_numberpatteern->add1,
85
        'every1'          => $sub_numberpatteern->every1,
86
        'whenmorethan1'   => $sub_numberpatteern->whenmorethan1,
87
        'setto1'          => $sub_numberpatteern->setto1,
88
        'numbering1'      => $sub_numberpatteern->numbering1,
89
        'label2'          => $sub_numberpatteern->label2,
90
        'add2'            => $sub_numberpatteern->add2,
91
        'every2'          => $sub_numberpatteern->every2,
92
        'whenmorethan2'   => $sub_numberpatteern->whenmorethan2,
93
        'setto2'          => $sub_numberpatteern->setto2,
94
        'numbering2'      => $sub_numberpatteern->numbering2,
95
        'label3'          => $sub_numberpatteern->label3,
96
        'add3'            => $sub_numberpatteern->add3,
97
        'every3'          => $sub_numberpatteern->every3,
98
        'whenmorethan3'   => $sub_numberpatteern->whenmorethan3,
99
        'setto3'          => $sub_numberpatteern->setto3,
100
        'numbering3'      => $sub_numberpatteern->numbering3,
101
        'issn'            => $biblioitem->issn,
102
        'ean'             => $biblioitem->ean,
103
        'publishercode'   => $biblioitem->publishercode
104
    };
105
    return $sub_mana_info;
106
}
107
42
sub _type {
108
sub _type {
43
    return 'Subscription';
109
    return 'Subscription';
44
}
110
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc (+3 lines)
Lines 31-34 Link Here
31
        </a>
31
        </a>
32
    </li>
32
    </li>
33
    <li><a href="/cgi-bin/koha/serials/add_fields.pl">Add subscription fields</a></li>
33
    <li><a href="/cgi-bin/koha/serials/add_fields.pl">Add subscription fields</a></li>
34
    [% IF Koha.Preference('Mana') %]
35
        <li><a href="/cgi-bin/koha/serials/serials-search.pl?mana=1">Search on Mana</a></li>
36
    [% END %]
34
</ul>
37
</ul>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc (+108 lines)
Lines 13-18 Link Here
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
14
        }
14
        }
15
    }
15
    }
16
    function share() {
17
        window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=share";
18
    }
16
19
17
	 $(document).ready(function() {
20
	 $(document).ready(function() {
18
        $("#deletesub").click(function(){
21
        $("#deletesub").click(function(){
Lines 43-48 Link Here
43
            [% ELSE %]
46
            [% ELSE %]
44
                <div class="btn-group"><a id="newsubscription" class="btn btn-default btn-sm" href="/cgi-bin/koha/serials/subscription-add.pl"><i class="fa fa-plus"></i> New subscription</a></div>
47
                <div class="btn-group"><a id="newsubscription" class="btn btn-default btn-sm" href="/cgi-bin/koha/serials/subscription-add.pl"><i class="fa fa-plus"></i> New subscription</a></div>
45
            [% END %]
48
            [% END %]
49
            [% IF Koha.Preference('Mana') %]
50
                [% IF one_language_enabled==0 or mana_id %]
51
                    <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-small"><i class="fa fa-share-alt"></i> Share</a></div>
52
                [% ELSE %]
53
                    <div class="btn-group" data-toggle="tooltip" title="Your email address will be associated to your sharing."><a class="btn btn-small" onclick="share()"><i class="fa fa-share-alt"></i> Share</a></div>
54
                [% END %]
55
            [% END %]
46
        [% END %]
56
        [% END %]
47
57
48
        [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %]
58
        [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %]
Lines 99-101 Link Here
99
        [% END %]
109
        [% END %]
100
    </div>
110
    </div>
101
[% END %]
111
[% END %]
112
113
<div id="mana_share_modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mana_share_modal_label" style="display: none;">
114
    <div class="modal-dialog">
115
        <div class="modal-content">
116
            <div class="modal-header">
117
                <h3 id="mana_share_modal_label">Share [% bibliotitle %] to Mana</h3>
118
            </div>
119
            <div class="modal-body">
120
                [% IF (mana_id) %]
121
                    <div class="alert">
122
                        <p>Your subscription is already linked with a Mana subscription model. Share it if you have made modifications, otherwide it will do nothing.</p>
123
                    </div>
124
                [% END %]
125
                [% IF ( languages_loop ) %]
126
                    [% UNLESS ( one_language_enabled ) %]
127
                        <div class="rows">
128
                            <p>The frequency and the numberpattern of [% bibliotitle %] are :</p>
129
                            <ol>
130
                                <li><span class="label">Frequency : </span>
131
                                        [% frequency.description %]
132
                                </li>
133
                                <li><span class="label">Number pattern : </span>
134
                                    [% numberpattern.label %]
135
                                </li>
136
                            </ol>
137
                        </div>
138
                        <div class="rows">
139
                            <form method="get" id="mana_share_form" action="/cgi-bin/koha/serials/subscription-detail.pl" class="validated" >
140
                                <fieldset>
141
                                    <label for="mana_language">Language of your sharing :</label>
142
                                    <select id="mana_language" name="mana_language">
143
                                        [% FOREACH languages_loo IN languages_loop %]
144
                                            [% IF ( languages_loo.group_enabled ) %]
145
                                                [% IF ( languages_loo.plural ) %]
146
                                                    [% FOREACH sublanguages_loo IN languages_loo.sublanguages_loop %]
147
                                                        [% IF ( sublanguages_loo.enabled ) %]
148
                                                            [% IF ( sublanguages_loo.sublanguage_current ) %]
149
                                                                <option value="[% languages_loo.rfc4646_subtag %]" selected>
150
                                                                    [% sublanguages_loo.native_description %]
151
                                                                    [% sublanguages_loo.script_description %]
152
                                                                    [% sublanguages_loo.region_description %]
153
                                                                    [% sublanguages_loo.variant_description %]
154
                                                                    ([% sublanguages_loo.rfc4646_subtag %])
155
                                                                </option>
156
                                                            [% ELSE %]
157
                                                                <option value="[% languages_loo.rfc4646_subtag %]">
158
                                                                    [% sublanguages_loo.native_description %]
159
                                                                    [% sublanguages_loo.script_description %]
160
                                                                    [% sublanguages_loo.region_description %]
161
                                                                    [% sublanguages_loo.variant_description %]
162
                                                                    ([% sublanguages_loo.rfc4646_subtag %])
163
                                                                </option>
164
                                                            [% END %]
165
                                                        [% END %]
166
                                                    [% END %]
167
                                                [% ELSE %]
168
                                                    [% IF ( languages_loo.group_enabled ) %]
169
                                                        [% IF ( languages_loo.current ) %]
170
                                                            <option value="[% languages_loo.rfc4646_subtag %]" selected>
171
                                                                [% IF ( languages_loo.native_description ) %]
172
                                                                    [% languages_loo.native_description %]
173
                                                                [% ELSE %]
174
                                                                    [% languages_loo.rfc4646_subtag %]
175
                                                                [% END %]
176
                                                            </option>
177
                                                        [% ELSE %]
178
                                                            <option value="[% languages_loo.rfc4646_subtag %]">
179
                                                                [% IF ( languages_loo.native_description ) %]
180
                                                                    [% languages_loo.native_description %]
181
                                                                [% ELSE %]
182
                                                                    [% languages_loo.rfc4646_subtag %]
183
                                                                [% END %]
184
                                                            </option>
185
                                                        [% END %]
186
                                                    [% END %]
187
                                                [% END %]
188
                                            [% END %]
189
                                        [% END %]
190
                                    </select>
191
                                    <input type="hidden" id="op" name="op" value="share"/>
192
                                    <input type="hidden" id="subscriptionid" name="subscriptionid" value="[% subscriptionid %]"/>
193
                                </fieldset>
194
                            </form>
195
                        </div>
196
                    [% END %]
197
                [% END %]
198
            </div>
199
            <div class="modal-footer">
200
                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
201
                [% IF one_language_enabled==0 %]
202
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
203
                [% ELSE %]
204
                    <div class="btn-group"><a class="btn btn-primary" onclick="share()">Share</a></div>
205
                [% END %]
206
            </div>
207
        </div>
208
    </div>
209
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt (+1 lines)
Lines 1-5 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE Koha %]
3
<title>Koha &rsaquo; Serials [% biblionumber %]</title>
4
<title>Koha &rsaquo; Serials [% biblionumber %]</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
5
</head>
6
</head>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt (-7 / +42 lines)
Lines 1-6 Link Here
1
[% USE Branches %]
1
[% USE Branches %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% USE KohaDates %]
3
[% USE KohaDates %]
4
[% USE Koha %]
4
[% USE AuthorisedValues %]
5
[% USE AuthorisedValues %]
5
<title>Koha &rsaquo; Serials [% biblionumber %]</title>
6
<title>Koha &rsaquo; Serials [% biblionumber %]</title>
6
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'doc-head-close.inc' %]
Lines 10-15 Link Here
10
<script type="text/javascript">
11
<script type="text/javascript">
11
//<![CDATA[
12
//<![CDATA[
12
 $(document).ready(function() {
13
 $(document).ready(function() {
14
    var manarlt = $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
15
        "sPaginationType": "four_button",
16
        "aoColumnDefs": [
17
            { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
18
            { "sType": "title-string", "aTargets" : [ "title-string" ] },
19
            { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
20
        ]
21
    } ) );
13
    var osrlt = $("#osrlt").dataTable($.extend(true, {}, dataTablesDefaults, {
22
    var osrlt = $("#osrlt").dataTable($.extend(true, {}, dataTablesDefaults, {
14
        "sPaginationType": "four_button",
23
        "sPaginationType": "four_button",
15
        "aoColumnDefs": [
24
        "aoColumnDefs": [
Lines 28-33 Link Here
28
        ]
37
        ]
29
    } ) );
38
    } ) );
30
39
40
    manarlt.fnAddFilters("dt-filter", 750);
31
    osrlt.fnAddFilters("dt-filter", 750);
41
    osrlt.fnAddFilters("dt-filter", 750);
32
    csrlt.fnAddFilters("dt-filter", 750);
42
    csrlt.fnAddFilters("dt-filter", 750);
33
43
Lines 35-40 Link Here
35
    $("#reopensub").click(function(){
45
    $("#reopensub").click(function(){
36
      return confirm(_("Are you sure you want to reopen this subscription?"));
46
      return confirm(_("Are you sure you want to reopen this subscription?"));
37
    });
47
    });
48
    [% IF ( mana ) %]
49
        $("label[for=callnumber], input#callnumber").hide();
50
        $("label[for=bookseller], input#bookseller").hide();
51
        $("label[for=branch], select#branch").hide();
52
        $("label[for=to], input#to").hide();
53
        $(".ui-datepicker-trigger").hide();
54
        $("label[for=location], select#location_filter").hide();
55
        [% FOR field IN additional_fields_for_subscription %]
56
              $("label[for=additional_field_[% field.id %]], input#additional_field_[% field.id %]").hide();
57
        [% END %]
58
    [% END %]
38
 });
59
 });
39
 //]]>
60
 //]]>
40
</script>
61
</script>
Lines 123-128 Link Here
123
                [% END %]
144
                [% END %]
124
              </ol>
145
              </ol>
125
              <input type="hidden" name="searched" value="1" />
146
              <input type="hidden" name="searched" value="1" />
147
              [% IF ( mana ) %]<input type="hidden" name="mana" value="1" />[% END %]
126
              <fieldset class="action">
148
              <fieldset class="action">
127
                <input type="submit" value="Search" />
149
                <input type="submit" value="Search" />
128
              </fieldset>
150
              </fieldset>
Lines 130-142 Link Here
130
        </form>
152
        </form>
131
      </div>
153
      </div>
132
      [% END %]
154
      [% END %]
133
      [% IF ( done_searched ) %]
155
            [% IF ( done_searched ) %]
134
        [% IF ( total ) %]
156
                [% IF ( total ) %]
135
          <div id="serialstabs" class="toptabs" style="clear:both;">
157
                    <div id="serialstabs" class="toptabs" style="clear:both;">
136
            <ul class="ui-tabs-nav">
158
                        <ul class="ui-tabs-nav">
137
              <li><a href="#opened">Open ([% openedsubscriptions.size || 0 %])</a></li>
159
                            [% IF mana %]
138
              <li><a href="#closed">Closed ([% closedsubscriptions.size || 0 %])</a></li>
160
                                <li><a href="#mana">Mana ([% total || 0 %])</a></li>
139
            </ul>
161
                            [% ELSE %]
162
                                <li><a href="#opened">Open ([% openedsubscriptions.size || 0 %])</a></li>
163
                                <li><a href="#closed">Closed ([% closedsubscriptions.size || 0 %])</a></li>
164
                            [% END %]
165
                        </ul>
166
                        [% IF mana %]
167
                            <div id="mana">
168
                                [% INCLUDE 'mana-subscription-search-result.inc' %]
169
                            </div>
170
                        [% ELSE %]
140
            <div id="opened">
171
            <div id="opened">
141
              [% IF openedsubscriptions %]
172
              [% IF openedsubscriptions %]
142
                <table id="osrlt">
173
                <table id="osrlt">
Lines 354-359 Link Here
354
                </div>
385
                </div>
355
              [% END %]
386
              [% END %]
356
            </div>
387
            </div>
388
            [% END %]
357
          </div>
389
          </div>
358
        [% ELSE %]
390
        [% ELSE %]
359
            <div class="dialog message">
391
            <div class="dialog message">
Lines 367-372 Link Here
367
  <div class="yui-b">
399
  <div class="yui-b">
368
    [% INCLUDE 'serials-menu.inc' %]
400
    [% INCLUDE 'serials-menu.inc' %]
369
    [% IF ( done_searched ) %]
401
    [% IF ( done_searched ) %]
402
    [% UNLESS ( mana ) %]
370
    <div id="advsearch">
403
    <div id="advsearch">
371
        <form action="/cgi-bin/koha/serials/serials-search.pl" method="get">
404
        <form action="/cgi-bin/koha/serials/serials-search.pl" method="get">
372
          <fieldset class="brief">
405
          <fieldset class="brief">
Lines 439-448 Link Here
439
              <fieldset class="action">
472
              <fieldset class="action">
440
                <input type="submit" value="Search" />
473
                <input type="submit" value="Search" />
441
              </fieldset>
474
              </fieldset>
475
442
            </div>
476
            </div>
443
          </fieldset>
477
          </fieldset>
444
        </form>
478
        </form>
445
      [% END %]
479
      [% END %]
480
    [% END %]
446
  </div>
481
  </div>
447
</div>
482
</div>
448
[% INCLUDE 'intranet-bottom.inc' %]
483
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-24 / +193 lines)
Lines 1-5 Link Here
1
[% USE KohaDates %]
1
[% USE KohaDates %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE Koha %]
3
4
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
6
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
Lines 11-21 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ Link Here
11
    width: 300px;  /* not enough for IE7 apparently */
12
    width: 300px;  /* not enough for IE7 apparently */
12
}
13
}
13
</style>
14
</style>
15
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
16
[% INCLUDE 'datatables.inc' %]
14
<script type="text/javascript">
17
<script type="text/javascript">
15
//<![CDATA[
18
//<![CDATA[
16
19
17
var globalnumpatterndata;
20
var globalnumpatterndata;
18
var globalfreqdata;
21
var globalfreqdata;
22
var mananumpatterndata;
23
var manafreqdata;
24
var manaid;
19
var advancedpatternlocked;
25
var advancedpatternlocked;
20
var patternneedtobetested = 0;
26
var patternneedtobetested = 0;
21
[% IF ( irregularity ) %]patternneedtobetested = 1;[% END %]
27
[% IF ( irregularity ) %]patternneedtobetested = 1;[% END %]
Lines 98-128 function Check_page2(){ Link Here
98
}
104
}
99
105
100
function frequencyload(){
106
function frequencyload(){
101
    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
107
    if ($("#frequency option:selected").val() === "mana"){
102
        function(freqdata){
108
        globalfreqdata=manafreqdata;
103
            globalfreqdata=freqdata;
109
        $("input[name='sfdescription']").val(manafreqdata.description);
104
            if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
110
        $("input[name='unit']").val(manafreqdata.unit);
105
                var option = $("#subtype option[value='issues']");
111
        $("input[name='unitsperissue']").val(manafreqdata.unitsperissue);
106
                $(option).attr('selected', 'selected');
112
        $("input[name='issuesperunit']").val(manafreqdata.issuesperunit);
107
                $("#subtype option[value!='issues']").prop('disabled', true)
113
        if ($( "#numberpattern option:selected" ).val() === "mana" ) {
108
            } else {
114
            $("input[name='mana_id']").val(manaid);
109
                $("#subtype option").prop('disabled', false)
110
            }
111
        }
115
        }
112
    )
116
    } else {
117
        $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
118
            function(freqdata){
119
                globalfreqdata=freqdata;
120
                if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
121
                    var option = $("#subtype option[value='issues']");
122
                    $(option).attr('selected', 'selected');
123
                    $("#subtype option[value!='issues']").prop('disabled', true);
124
                } else {
125
                    $("#subtype option").prop('disabled', false);
126
                }
127
            }
128
        );
129
        $("input[name='mana_id']").val("");
130
    }
113
}
131
}
114
132
115
function numberpatternload(){
133
function numberpatternload(){
116
    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
134
    if($("#numberpattern option:selected" ).val() === "mana"){
117
        function(numpatterndata){
135
        globalnumpatterndata=mananumpatterndata;
118
            globalnumpatterndata=numpatterndata;
136
        $("input[name='sndescription']").val(mananumpatterndata.description);
119
            if (globalnumpatterndata==undefined){
137
        if($("#frequency option:selected" ).val() === "mana"){
120
                return false;
138
            $("input[name='mana_id']").val(manaid);
121
            }
139
        }
122
            displaymoreoptions();
140
        if (globalnumpatterndata==undefined){
123
            restoreAdvancedPattern();
141
            return false;
124
        }
142
        }
125
    );
143
        displaymoreoptions();
144
        restoreAdvancedPattern();
145
    } else {
146
        $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
147
            function(numpatterndata){
148
                globalnumpatterndata=numpatterndata;
149
                if (globalnumpatterndata==undefined){
150
                    return false;
151
                }
152
                displaymoreoptions();
153
                restoreAdvancedPattern();
154
            }
155
        );
156
        $("input[name='mana_id']").val("");
157
    }
126
}
158
}
127
159
128
function displaymoreoptions() {
160
function displaymoreoptions() {
Lines 285-291 function testPredictionPattern() { Link Here
285
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
317
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
286
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
318
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
287
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
319
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
288
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
320
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale', 'sfdescription',
321
        'unitsperissue', 'issuesperunit', 'unit'
289
    ];
322
    ];
290
    for(i in ajaxParams) {
323
    for(i in ajaxParams) {
291
        var param = ajaxParams[i];
324
        var param = ajaxParams[i];
Lines 298-304 function testPredictionPattern() { Link Here
298
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
331
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
299
        data: ajaxData,
332
        data: ajaxData,
300
        success: function(data) {
333
        success: function(data) {
301
            $("#displayexample").html(data);
334
            $("#displayexample").html(data).show();
302
            patternneedtobetested = 0;
335
            patternneedtobetested = 0;
303
        }
336
        }
304
    });
337
    });
Lines 372-379 function show_page_2() { Link Here
372
    displaymoreoptions();
405
    displaymoreoptions();
373
}
406
}
374
407
408
function mana_search() {
409
    $.ajax({
410
        type: "POST",
411
        url: "/cgi-bin/koha/svc/mana/search",
412
        data: {biblionumber : $("#biblionumber").val()},
413
        dataType: "html",
414
    })
415
    .done( function( result ) {
416
    $("#mana_search_result .modal-body").html(result);
417
        $("#mana_search_result_label").text("Results from Mana");
418
        $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
419
            "sPaginationType": "four_button",
420
            "aoColumnDefs": [
421
                { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
422
                { "sType": "title-string", "aTargets" : [ "title-string" ] },
423
                { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
424
            ]
425
        }));
426
        if($("td.dataTables_empty").length == 0){
427
            $("#mana_search").show();
428
        }
429
    }).fail(function(result){
430
    });
431
}
432
433
function mana_use(mana_id){
434
    $("tr").removeClass("selected");
435
    $("#row"+mana_id).addClass("selected");
436
    $.ajax( {
437
        type: "POST",
438
        url: "/cgi-bin/koha/svc/mana/use",
439
        data: {id : mana_id},
440
        dataType: "json",
441
    })
442
    .done(function(result){
443
        var select = document.getElementById('numberpattern');
444
        for(i = 0; i < select.length; i++){
445
            if(select[i].value === "mana"){
446
                select.remove(i);
447
            }
448
        }
449
        var optionnumpattern = document.createElement("option");
450
        optionnumpattern.text = result.label + " (mana)";
451
        optionnumpattern.selected = true;
452
        optionnumpattern.value="mana";
453
        select.add(optionnumpattern);
454
455
        mananumpatterndata = {
456
            id:"mana",
457
            add1:result.add1,
458
            add2:result.add2,
459
            add3:result.add3,
460
            description:result.sndescription,
461
            displayorder:result.displayorder,
462
            every1:result.every1,
463
            every2:result.every2,
464
            every3:result.every3,
465
            label:result.label,
466
            label1:result.label1,
467
            label2:result.label2,
468
            label3:result.label3,
469
            numbering1:result.numbering1,
470
            numbering2:result.numbering2,
471
            numbering3:result.numbering3,
472
            numberingmethod:result.numberingmethod,
473
            setto1:result.setto1,
474
            setto2:result.setto2,
475
            setto3:result.setto3,
476
            whenmorethan1:result.whenmorethan1,
477
            whenmorethan2:result.whenmorethan2,
478
            whenmorethan3:result.whenmorethan3,
479
        };
480
        select = document.getElementById("frequency");
481
        for(i = 0; i < select.length; i++){
482
            if(select[i].value === "mana"){
483
                select.remove(i);
484
            }
485
        }
486
        var optionfreq = document.createElement("option");
487
        optionfreq.text = result.sfdescription + " (mana)";
488
        optionfreq.selected = true;
489
        optionfreq.value="mana";
490
        select.add(optionfreq);
491
        manafreqdata = {
492
            id:"mana",
493
            description:result.sfdescription,
494
            displayorder:result.displayorder,
495
            issuesperunit:result.issuesperunit,
496
            unit:result.unit,
497
            unitsperissue:result.unitsperissue,
498
        };
499
        manaid = result.id;
500
        $("input[name='mana_id']").val(manaid);
501
        $("#mana_search_result").modal("hide");
502
        frequencyload();
503
        numberpatternload();
504
    }).fail( function( result ){
505
    });
506
}
507
508
function removeDisabledAttr() {
509
    $('select:disabled').removeAttr('disabled');
510
}
511
375
512
376
$(document).ready(function() {
513
$(document).ready(function() {
514
    $("#displayexample").hide();
515
    $("#mana_search_result").modal("hide");
377
    $("#aqbooksellerid").on('keypress', function(e) {
516
    $("#aqbooksellerid").on('keypress', function(e) {
378
        if (e.keyCode == 13) {
517
        if (e.keyCode == 13) {
379
            e.preventDefault();
518
            e.preventDefault();
Lines 456-461 $(document).ready(function() { Link Here
456
        }
595
        }
457
    [% END %]
596
    [% END %]
458
597
598
    $("#mana_search").hide();
599
459
    show_page_1();
600
    show_page_1();
460
    $("#subscription_add_form").on("submit",function(){
601
    $("#subscription_add_form").on("submit",function(){
461
        return Check_page2();
602
        return Check_page2();
Lines 477-483 $(document).ready(function() { Link Here
477
        }
618
        }
478
    });
619
    });
479
    $("#subscription_add_next").on("click",function(){
620
    $("#subscription_add_next").on("click",function(){
480
        if ( Check_page1() ){
621
        if ( Check_page1() ) {
622
            [% IF Koha.Preference('Mana') %]
623
                mana_search();
624
            [% END %]
481
            show_page_2();
625
            show_page_2();
482
        }
626
        }
483
    });
627
    });
Lines 701-706 $(document).ready(function() { Link Here
701
845
702
                <div id="page_2">
846
                <div id="page_2">
703
                    <div class="yui-u first">
847
                    <div class="yui-u first">
848
                        <div id="mana_search" class="dialog message">
849
                            <p>Frequency and Numbering pattern have been already proposed for this subscription on Mana. To show results, click <a style="cursor:pointer" data-toggle="modal" data-target="#mana_search_result">Here</a></p>
850
                        </div>
704
                        <div id="subscription_form_planning">
851
                        <div id="subscription_form_planning">
705
                            <fieldset class="rows">
852
                            <fieldset class="rows">
706
                                <legend>Serials planning</legend>
853
                                <legend>Serials planning</legend>
Lines 965-974 $(document).ready(function() { Link Here
965
                              </div>
1112
                              </div>
966
                            [% END %]
1113
                            [% END %]
967
1114
1115
                            <input type="hidden" id="mana_id"  name="mana_id" value=""/>
1116
                            <input type="hidden" id="sndescription"  name="sndescription" value=""/>
1117
                            <input type="hidden" id="sfdescription"  name="sfdescription" value=""/>
1118
                            <input type="hidden" id="unit"  name="unit" value=""/>
1119
                            <input type="hidden" id="unitsperissue"  name="unitsperissue" value=""/>
1120
                            <input type="hidden" id="issuesperunit"  name="issuesperunit" value=""/>
968
                            <fieldset class="action">
1121
                            <fieldset class="action">
969
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
1122
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
970
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
1123
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
971
                                <input type="submit" value="Save subscription" style="float:right;" accesskey="w" />
1124
                                <input type="submit" onclick="removeDisabledAttr()" value="Save subscription" style="float:right;" accesskey="w"/>
972
                            </fieldset>
1125
                            </fieldset>
973
                        </div>
1126
                        </div>
974
                    </div>
1127
                    </div>
Lines 981-984 $(document).ready(function() { Link Here
981
    </div>
1134
    </div>
982
</div>
1135
</div>
983
1136
1137
<div id="mana_search_result" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="width: 90%; left:5%; margin-left: auto; display: none;">
1138
    <div class="modal-dialog modal-lg">
1139
        <div class="modal-content">
1140
            <div class="modal-header">
1141
                <h3 id="mana_search_result_label"></h3>
1142
            </div>
1143
            <div class="modal-body">
1144
            </div>
1145
            <div class="modal-footer">
1146
                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
1147
            </div>
1148
        </div>
1149
    </div>
1150
</div>
1151
1152
984
[% INCLUDE 'intranet-bottom.inc' %]
1153
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-2 / +14 lines)
Lines 1-6 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE Koha %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Serials &rsaquo; Details for subscription #[% subscriptionid %]</title>
6
<title>Koha &rsaquo; Serials &rsaquo; Details for subscription #[% subscriptionid %]</title>
6
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'doc-head-close.inc' %]
Lines 41-47 $(document).ready(function() { Link Here
41
   <div id="bd">
42
   <div id="bd">
42
	<div id="yui-main">
43
	<div id="yui-main">
43
	<div class="yui-b">
44
	<div class="yui-b">
44
	[% INCLUDE 'serials-toolbar.inc' %]
45
    [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]
45
46
46
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
47
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
47
    [% IF ( abouttoexpire ) %]
48
    [% IF ( abouttoexpire ) %]
Lines 70-76 $(document).ready(function() { Link Here
70
			</form>
71
			</form>
71
72
72
	</div>
73
	</div>
73
	[% END %] <!-- NEEDSCONFIRMATION -->
74
    [% END %] <!-- NEEDSCONFIRMATION -->
75
    [% IF mana_code.defined %]
76
        <div id="alert-community" class="dialog message">
77
            <p>
78
                [% IF (mana_code == 201) %]
79
                    The export is done, thank you for your contribution.
80
                [% ELSIF (mana_code == 200) %]
81
                    The model already exists on Mana, thank you for your contribution.
82
                [% END %]
83
            </p>
84
        </div>
85
    [% END %]
74
86
75
<div id="subscription_description" class="toptabs">
87
<div id="subscription_description" class="toptabs">
76
<ul class="ui-tabs-nav">
88
<ul class="ui-tabs-nav">
(-)a/misc/cronjobs/serialsUpdate.pl (-1 / +3 lines)
Lines 33-38 use C4::Debug; Link Here
33
use C4::Serials;
33
use C4::Serials;
34
use C4::Log;
34
use C4::Log;
35
use Koha::DateUtils;
35
use Koha::DateUtils;
36
use C4::Serials::Frequency;
36
37
37
use Date::Calc qw/Date_to_Days check_date/;
38
use Date::Calc qw/Date_to_Days check_date/;
38
use Getopt::Long;
39
use Getopt::Long;
Lines 118-124 while ( my $issue = $sth->fetchrow_hashref ) { Link Here
118
    my $publisheddate  = $issue->{publisheddate};
119
    my $publisheddate  = $issue->{publisheddate};
119
120
120
    if ( $subscription && $publisheddate && $publisheddate ne "0000-00-00" ) {
121
    if ( $subscription && $publisheddate && $publisheddate ne "0000-00-00" ) {
121
        my $nextpublisheddate = GetNextDate( $subscription, $publisheddate );
122
        my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'});
123
        my $nextpublisheddate = GetNextDate( $subscription, $publisheddate, $freqdata );
122
        my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
124
        my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
123
125
124
        if ( $nextpublisheddate && $today ) {
126
        if ( $nextpublisheddate && $today ) {
(-)a/serials/serials-collection.pl (-2 / +4 lines)
Lines 74-87 if($op eq 'gennext' && @subscriptionid){ Link Here
74
            require C4::Serials::Numberpattern;
74
            require C4::Serials::Numberpattern;
75
            my $subscription = GetSubscription($subscriptionid);
75
            my $subscription = GetSubscription($subscriptionid);
76
            my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
76
            my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
77
            my $frequency = C4::Serials::Frequency::GetSubscriptionFrequencies($subscription->{periodicity});
77
            my $expected = GetNextExpected($subscriptionid);
78
            my $expected = GetNextExpected($subscriptionid);
78
            my (
79
            my (
79
                 $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
80
                 $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
80
                 $newinnerloop1, $newinnerloop2, $newinnerloop3
81
                 $newinnerloop1, $newinnerloop2, $newinnerloop3
81
            ) = GetNextSeq($subscription, $pattern, $expected->{publisheddate});
82
            ) = GetNextSeq($subscription, $pattern, $frequency, $expected->{publisheddate});
82
83
83
             ## We generate the next publication date
84
             ## We generate the next publication date
84
             my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1);
85
             my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
86
             my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, $frequency, 1);
85
             ## Creating the new issue
87
             ## Creating the new issue
86
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
88
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
87
                     1, $nextpublisheddate, $nextpublisheddate );
89
                     1, $nextpublisheddate, $nextpublisheddate );
(-)a/serials/serials-search.pl (-36 / +86 lines)
Lines 38-43 use C4::Serials; Link Here
38
use Koha::AdditionalField;
38
use Koha::AdditionalField;
39
39
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::SharedContent;
41
42
42
my $query         = new CGI;
43
my $query         = new CGI;
43
my $title         = $query->param('title_filter') || '';
44
my $title         = $query->param('title_filter') || '';
Lines 52-57 my $location = $query->param('location_filter') || ''; Link Here
52
my $expiration_date = $query->param('expiration_date_filter') || '';
53
my $expiration_date = $query->param('expiration_date_filter') || '';
53
my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
54
my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
54
my $searched      = $query->param('searched') || 0;
55
my $searched      = $query->param('searched') || 0;
56
my $mana      = $query->param('mana') || 0;
55
my @subscriptionids = $query->multi_param('subscriptionid');
57
my @subscriptionids = $query->multi_param('subscriptionid');
56
my $op            = $query->param('op');
58
my $op            = $query->param('op');
57
59
Lines 95-101 for my $field ( @$additional_fields ) { Link Here
95
my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
97
my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
96
my @subscriptions;
98
my @subscriptions;
97
if ($searched){
99
if ($searched){
98
    @subscriptions = SearchSubscriptions(
100
    if ($mana) {
101
        my $result = Koha::SharedContent::manaGetRequest("subscription",{
102
            title        => $title,
103
            issn         => $ISSN,
104
            ean          => $EAN,
105
            publisher    => $publisher
106
        });
107
        @subscriptions = @{ $result->{data} };
108
    }
109
    else {
110
        @subscriptions = SearchSubscriptions(
99
        {
111
        {
100
            biblionumber => $biblionumber,
112
            biblionumber => $biblionumber,
101
            title        => $title,
113
            title        => $title,
Lines 108-153 if ($searched){ Link Here
108
            additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}{value}, authorised_value_category => $additional_field_filters->{$_}{authorised_value_category} } } keys %$additional_field_filters ],
120
            additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}{value}, authorised_value_category => $additional_field_filters->{$_}{authorised_value_category} } } keys %$additional_field_filters ],
109
            location     => $location,
121
            location     => $location,
110
            expiration_date => $expiration_date_dt,
122
            expiration_date => $expiration_date_dt,
111
        }
123
        });
112
    );
124
    }
113
}
125
}
114
126
115
# to toggle between create or edit routing list options
127
if ($mana) {
116
if ($routing) {
128
    $template->param(
117
    for my $subscription ( @subscriptions) {
129
        subscriptions => \@subscriptions,
118
        $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
130
        total         => scalar @subscriptions,
119
    }
131
        title_filter  => $title,
132
        ISSN_filter   => $ISSN,
133
        EAN_filter    => $EAN,
134
        callnumber_filter => $callnumber,
135
        publisher_filter => $publisher,
136
        bookseller_filter  => $bookseller,
137
        branch_filter => $branch,
138
        location_filter => $location,
139
        expiration_date_filter => $expiration_date_dt,
140
        done_searched => $searched,
141
        routing       => $routing,
142
        additional_field_filters => $additional_field_filters,
143
        additional_fields_for_subscription => $additional_fields,
144
        marcflavour   => (uc(C4::Context->preference("marcflavour"))),
145
        mana => $mana,
146
        search_only => 1
147
    );
120
}
148
}
149
else
150
{
151
    # to toggle between create or edit routing list options
152
    if ($routing) {
153
        for my $subscription ( @subscriptions) {
154
            $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
155
        }
156
    }
121
157
122
my (@openedsubscriptions, @closedsubscriptions);
158
    my (@openedsubscriptions, @closedsubscriptions);
123
for my $sub ( @subscriptions ) {
159
    for my $sub ( @subscriptions ) {
124
    unless ( $sub->{closed} ) {
160
        unless ( $sub->{closed} ) {
125
        push @openedsubscriptions, $sub
161
            push @openedsubscriptions, $sub
126
            unless $sub->{cannotdisplay};
162
                unless $sub->{cannotdisplay};
127
    } else {
163
        } else {
128
        push @closedsubscriptions, $sub
164
            push @closedsubscriptions, $sub
129
            unless $sub->{cannotdisplay};
165
                unless $sub->{cannotdisplay};
166
        }
130
    }
167
    }
131
}
132
168
133
$template->param(
169
    my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } );
134
    openedsubscriptions => \@openedsubscriptions,
170
    my @branches_loop;
135
    closedsubscriptions => \@closedsubscriptions,
171
    foreach my $b ( @branches ) {
136
    total         => @openedsubscriptions + @closedsubscriptions,
172
        my $selected = 0;
137
    title_filter  => $title,
173
        $selected = 1 if( defined $branch and $branch eq $b->branchcode );
138
    ISSN_filter   => $ISSN,
174
        push @branches_loop, {
139
    EAN_filter    => $EAN,
175
            branchcode  => $b->branchcode,
140
    callnumber_filter => $callnumber,
176
            branchname  => $b->branchname,
141
    publisher_filter => $publisher,
177
            selected    => $selected,
142
    bookseller_filter  => $bookseller,
178
        };
143
    branch_filter => $branch,
179
    }
144
    location_filter => $location,
145
    expiration_date_filter => $expiration_date_dt,
146
    done_searched => $searched,
147
    routing       => $routing,
148
    additional_field_filters => $additional_field_filters,
149
    additional_fields_for_subscription => $additional_fields,
150
    marcflavour   => (uc(C4::Context->preference("marcflavour")))
151
);
152
180
181
    $template->param(
182
        openedsubscriptions => \@openedsubscriptions,
183
        closedsubscriptions => \@closedsubscriptions,
184
        total         => @openedsubscriptions + @closedsubscriptions,
185
        title_filter  => $title,
186
        ISSN_filter   => $ISSN,
187
        EAN_filter    => $EAN,
188
        callnumber_filter => $callnumber,
189
        publisher_filter => $publisher,
190
        bookseller_filter  => $bookseller,
191
        branch_filter => $branch,
192
        location_filter => $location,
193
        expiration_date_filter => $expiration_date_dt,
194
        branches_loop => \@branches_loop,
195
        done_searched => $searched,
196
        routing       => $routing,
197
        additional_field_filters => $additional_field_filters,
198
        additional_fields_for_subscription => $additional_fields,
199
        marcflavour   => (uc(C4::Context->preference("marcflavour"))),
200
        mana => $mana
201
    );
202
}
153
output_html_with_http_headers $query, $cookie, $template->output;
203
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/serials/showpredictionpattern.pl (-5 / +18 lines)
Lines 56-62 my $subtype = $input->param('subtype'); Link Here
56
my $sublength = $input->param('sublength');
56
my $sublength = $input->param('sublength');
57
my $custompattern = $input->param('custompattern');
57
my $custompattern = $input->param('custompattern');
58
58
59
my $frequency = GetSubscriptionFrequency($frequencyid);
59
60
my $frequency;
61
if ( $frequencyid eq 'mana' ) {
62
    $frequency = {
63
        'id'            => undef,
64
        'displayorder'  => undef,
65
        'description'   => scalar $input->param('sfdescription') // '',
66
        'unitsperissue' => scalar $input->param('unitsperissue') // '',
67
        'issuesperunit' => scalar $input->param('issuesperunit') // '',
68
        'unit'          => scalar $input->param('unit') // ''
69
    };
70
}
71
else {
72
    $frequency = GetSubscriptionFrequency($frequencyid);
73
}
60
74
61
my %pattern = (
75
my %pattern = (
62
    numberingmethod => scalar $input->param('numberingmethod') // '',
76
    numberingmethod => scalar $input->param('numberingmethod') // '',
Lines 98-111 my %subscription = ( Link Here
98
    innerloop2      => scalar $input->param('innerloop2') // '',
112
    innerloop2      => scalar $input->param('innerloop2') // '',
99
    innerloop3      => scalar $input->param('innerloop3') // '',
113
    innerloop3      => scalar $input->param('innerloop3') // '',
100
    irregularity    => '',
114
    irregularity    => '',
101
    periodicity     => $frequencyid,
102
    countissuesperunit  => 1,
115
    countissuesperunit  => 1,
103
    firstacquidate  => $firstacquidate,
116
    firstacquidate  => $firstacquidate,
104
);
117
);
105
118
106
my $issuenumber;
119
my $issuenumber;
107
if(defined $subscriptionid) {
120
if(defined $subscriptionid) {
108
    ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date);
121
    ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date, $frequency);
109
} else {
122
} else {
110
    $issuenumber = 1;
123
    $issuenumber = 1;
111
}
124
}
Lines 135-141 while( $i < 1000 ) { Link Here
135
    my %line;
148
    my %line;
136
149
137
    if(defined $date){
150
    if(defined $date){
138
        $date = GetNextDate(\%subscription, $date);
151
        $date = GetNextDate(\%subscription, $date, $frequency);
139
    }
152
    }
140
    if(defined $date){
153
    if(defined $date){
141
        $line{'publicationdate'} = $date;
154
        $line{'publicationdate'} = $date;
Lines 156-162 while( $i < 1000 ) { Link Here
156
        last;
169
        last;
157
    }
170
    }
158
171
159
    ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern);
172
    ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern, $frequency);
160
    $issuenumber++;
173
    $issuenumber++;
161
    $line{'number'} = $calculated;
174
    $line{'number'} = $calculated;
162
    $line{'issuenumber'} = $issuenumber;
175
    $line{'issuenumber'} = $issuenumber;
(-)a/serials/subscription-add.pl (-7 / +74 lines)
Lines 35-40 use Koha::DateUtils; Link Here
35
use Koha::ItemTypes;
35
use Koha::ItemTypes;
36
use Carp;
36
use Carp;
37
37
38
use Koha::Subscription::Numberpattern;
39
use Koha::Subscription::Frequency;
40
use Koha::SharedContent;
41
38
#use Smart::Comments;
42
#use Smart::Comments;
39
43
40
our $query = CGI->new;
44
our $query = CGI->new;
Lines 284-298 sub _guess_enddate { Link Here
284
    return $enddate;
288
    return $enddate;
285
}
289
}
286
290
291
sub manage_subscription_numbering_pattern_id {
292
    my $params;
293
    if ( $query->param('numbering_pattern') eq 'mana' ) {
294
        foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
295
                   numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
296
                   label3 add3 every3 whenmorethan3 setto3 numbering3/) {
297
            $params->{$_} = $query->param($_) if $query->param($_);
298
        }
299
300
        my $existing = Koha::Subscription::Numberpatterns->search($params)->next();
301
302
        if ($existing) {
303
            return $existing->id;
304
        }
305
306
        $params->{label} = Koha::Subscription::Numberpattern->uniqueLabel($query->param('patternname'));
307
        $params->{description} = $query->param('sndescription');
308
309
310
        my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params)->store();
311
        return $subscription_np->id;
312
    }
313
314
    return $query->param('numbering_pattern');
315
}
316
317
sub manage_subscription_frequencies_id {
318
    my $periodicity;
319
    if ( $query->param('frequency') eq 'mana' ) {
320
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
321
            {
322
                description   => $query->param('sfdescription'),
323
                unit          => $query->param('unit'),
324
                unitsperissue => $query->param('unitsperissue'),
325
                issuesperunit => $query->param('issuesperunit'),
326
            }
327
        )->store();
328
        $periodicity = $subscription_freq->id;
329
    }
330
    else {
331
        $periodicity = $query->param('frequency');
332
    }
333
    return $periodicity;
334
}
335
287
sub redirect_add_subscription {
336
sub redirect_add_subscription {
337
    my $periodicity = manage_subscription_frequencies_id();
338
    my $numberpattern = manage_subscription_numbering_pattern_id();
339
288
    my $auser          = $query->param('user');
340
    my $auser          = $query->param('user');
289
    my $branchcode     = $query->param('branchcode');
341
    my $branchcode     = $query->param('branchcode');
290
    my $aqbooksellerid = $query->param('aqbooksellerid');
342
    my $aqbooksellerid = $query->param('aqbooksellerid');
291
    my $cost           = $query->param('cost');
343
    my $cost           = $query->param('cost');
292
    my $aqbudgetid     = $query->param('aqbudgetid');
344
    my $aqbudgetid     = $query->param('aqbudgetid');
293
    my $periodicity    = $query->param('frequency');
294
    my @irregularity   = $query->multi_param('irregularity');
345
    my @irregularity   = $query->multi_param('irregularity');
295
    my $numberpattern  = $query->param('numbering_pattern');
296
    my $locale         = $query->param('locale');
346
    my $locale         = $query->param('locale');
297
    my $graceperiod    = $query->param('graceperiod') || 0;
347
    my $graceperiod    = $query->param('graceperiod') || 0;
298
348
Lines 322-327 sub redirect_add_subscription { Link Here
322
    my $previousitemtype  = $query->param('previousitemtype');
372
    my $previousitemtype  = $query->param('previousitemtype');
323
    my $skip_serialseq    = $query->param('skip_serialseq');
373
    my $skip_serialseq    = $query->param('skip_serialseq');
324
374
375
    my $mana_id;
376
    if ( $query->param('mana_id') ne "" ) {
377
        $mana_id = $query->param('mana_id');
378
        Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id);
379
    }
380
    else {
381
        $mana_id = undef;
382
    }
383
325
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
384
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
326
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
385
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
327
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
386
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
Lines 333-339 sub redirect_add_subscription { Link Here
333
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
392
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
334
        }
393
        }
335
    }
394
    }
336
337
    my $subscriptionid = NewSubscription(
395
    my $subscriptionid = NewSubscription(
338
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
396
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
339
        $startdate, $periodicity, $numberlength, $weeklength,
397
        $startdate, $periodicity, $numberlength, $weeklength,
Lines 342-348 sub redirect_add_subscription { Link Here
342
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
400
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
343
        $manualhistory, $internalnotes, $serialsadditems,
401
        $manualhistory, $internalnotes, $serialsadditems,
344
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
402
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
345
        $skip_serialseq
403
        $skip_serialseq, $mana_id
346
    );
404
    );
347
405
348
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
406
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
Lines 372-384 sub redirect_mod_subscription { Link Here
372
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
430
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
373
        : $firstacquidate;
431
        : $firstacquidate;
374
432
375
    my $periodicity = $query->param('frequency');
433
    my $periodicity = manage_subscription_frequencies_id();
434
    my $numberpattern = manage_subscription_numbering_pattern_id();
376
435
377
    my $subtype = $query->param('subtype');
436
    my $subtype = $query->param('subtype');
378
    my $sublength = $query->param('sublength');
437
    my $sublength = $query->param('sublength');
379
    my ($numberlength, $weeklength, $monthlength)
438
    my ($numberlength, $weeklength, $monthlength)
380
        = _get_sub_length( $subtype, $sublength );
439
        = _get_sub_length( $subtype, $sublength );
381
    my $numberpattern = $query->param('numbering_pattern');
382
    my $locale = $query->param('locale');
440
    my $locale = $query->param('locale');
383
    my $lastvalue1 = $query->param('lastvalue1');
441
    my $lastvalue1 = $query->param('lastvalue1');
384
    my $innerloop1 = $query->param('innerloop1');
442
    my $innerloop1 = $query->param('innerloop1');
Lines 401-406 sub redirect_mod_subscription { Link Here
401
    my $previousitemtype  = $query->param('previousitemtype');
459
    my $previousitemtype  = $query->param('previousitemtype');
402
    my $skip_serialseq    = $query->param('skip_serialseq');
460
    my $skip_serialseq    = $query->param('skip_serialseq');
403
461
462
    my $mana_id;
463
    if ( defined( $query->param('mana_id') ) ) {
464
        $mana_id = $query->param('mana_id');
465
        Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id);
466
    }
467
    else {
468
        $mana_id = undef;
469
    }
470
404
    # Guess end date
471
    # Guess end date
405
    if(!defined $enddate || $enddate eq '') {
472
    if(!defined $enddate || $enddate eq '') {
406
        if($subtype eq "issues") {
473
        if($subtype eq "issues") {
Lines 426-432 sub redirect_mod_subscription { Link Here
426
        $status, $biblionumber, $callnumber, $notes, $letter,
493
        $status, $biblionumber, $callnumber, $notes, $letter,
427
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
494
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
428
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
495
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
429
        $skip_serialseq, $itemtype, $previousitemtype
496
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
430
    );
497
    );
431
498
432
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
499
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
(-)a/serials/subscription-detail.pl (-12 / +59 lines)
Lines 33-38 use Koha::Acquisition::Bookseller; Link Here
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
34
use Carp;
34
use Carp;
35
35
36
use LWP::UserAgent;
37
use Koha::SharedContent;
38
use Koha::Patrons;
39
use Koha::Subscriptions;
40
use Koha::Libraries;
41
36
my $query = new CGI;
42
my $query = new CGI;
37
my $op = $query->param('op') || q{};
43
my $op = $query->param('op') || q{};
38
my $issueconfirmed = $query->param('issueconfirmed');
44
my $issueconfirmed = $query->param('issueconfirmed');
Lines 68-98 my ($totalissues,@serialslist) = GetSerials($subscriptionid); Link Here
68
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
74
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
69
75
70
if ($op eq 'del') {
76
if ($op eq 'del') {
71
	if ($$subs{'cannotedit'}){
77
    if ($$subs{'cannotedit'}){
72
		carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
78
        carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
73
		print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
79
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
74
		exit;
80
        exit;
75
	}
81
    }
76
	
82
77
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
83
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
78
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
84
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
79
    my $linkedissues = CountIssues($subscriptionid);
85
    my $linkedissues = CountIssues($subscriptionid);
80
    my $countitems   = HasItems($subscriptionid);
86
    my $countitems   = HasItems($subscriptionid);
81
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
87
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
82
		$template->param(NEEDSCONFIRMATION => 1);
88
        $template->param(NEEDSCONFIRMATION => 1);
83
		if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
89
        if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
84
		if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
90
        if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
85
		if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
91
        if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
86
    } else {
92
    } else {
87
		$issueconfirmed = "1";
93
        $issueconfirmed = "1";
88
    }
94
    }
89
    # If it's ok to delete the subscription, we do so
95
    # If it's ok to delete the subscription, we do so
90
    if ($issueconfirmed eq "1") {
96
    if ($issueconfirmed eq "1") {
91
		&DelSubscription($subscriptionid);
97
        &DelSubscription($subscriptionid);
92
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
98
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
93
        exit;
99
        exit;
94
    }
100
    }
95
}
101
}
102
elsif ( $op and $op eq "share" ) {
103
    my $mana_language;
104
    if ( $query->param('mana_language') ) {
105
        $mana_language = $query->param('mana_language');
106
    }
107
    else {
108
        $mana_language = C4::Context->preference('language');
109
    }
110
111
    my $mana_email;
112
    if ( $loggedinuser ne 0 ) {
113
        my $borrower = Koha::Patrons->find($loggedinuser);
114
        $mana_email = $borrower->email
115
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
116
        $mana_email = $borrower->emailpro
117
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
118
        $mana_email =
119
          Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
120
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
121
    }
122
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
123
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
124
    my %versions = C4::Context::get_versions();
125
126
    my $mana_info = {
127
        language    => $mana_language,
128
        kohaversion => $versions{'kohaVersion'},
129
        exportemail => $mana_email
130
    };
131
    my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid);
132
    $sub_mana_info = { %$sub_mana_info, %$mana_info };
133
    my $result = Koha::SharedContent::manaPostRequest( "subscription",
134
        $sub_mana_info );
135
    if ( $result->{code} eq "200" and $result->{code} eq "201" ) {
136
        my $subscription = Koha::Subscriptions->find($subscriptionid);
137
        $subscription->set( { mana_id => $result->{id} } )->store;
138
        $subs->{mana_id} = $result->{id};
139
    }
140
    $template->param( mana_code => $result->{code} );
141
}
142
96
my $hasRouting = check_routing($subscriptionid);
143
my $hasRouting = check_routing($subscriptionid);
97
144
98
(undef, $cookie, undef, undef)
145
(undef, $cookie, undef, undef)
(-)a/t/db_dependent/Serials.t (-1 / +2 lines)
Lines 290-296 my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscrip Link Here
290
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
290
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
291
my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
291
my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
292
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
292
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
293
my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, 1);
293
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
294
my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, $frequency, 1);
294
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
295
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
295
# Add 14 serials
296
# Add 14 serials
296
my $counter = 0;
297
my $counter = 0;
(-)a/t/db_dependent/Serials/GetFictiveIssueNumber.t (-206 / +113 lines)
Lines 1-220 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This test deals with GetFictiveIssueNumber (from C4::Serials)
4
3
4
use C4::Context;
5
use Test::More tests => 18;
5
use Modern::Perl;
6
use Modern::Perl;
6
use Test::More tests => 5;
7
7
8
use Koha::Database;
9
use C4::Serials;
10
use C4::Serials::Frequency;
11
12
my $schema  = Koha::Database->new->schema;
13
$schema->storage->txn_begin;
14
my $dbh = C4::Context->dbh;
8
my $dbh = C4::Context->dbh;
9
$dbh->{RaiseError} = 1;
10
$dbh->{AutoCommit} = 0;
15
11
16
subtest 'Tests for irregular frequency' => sub {
12
use C4::Serials::Frequency;
17
    plan tests => 2;
13
use C4::Serials;
18
19
    # Add a frequency
20
    my $freq_irr = AddSubscriptionFrequency({
21
        description => "Irregular",
22
        unit => undef,
23
    });
24
14
25
    # Test it
15
# TEST CASE - 1 issue per day, no irregularities
26
    my $subscription = {
16
my $frequency = {
27
        periodicity => $freq_irr,
17
    description   => "One issue per day",
28
        firstacquidate => '1972-02-07',
18
    unit          => 'day',
29
    };
19
    issuesperunit => 1,
30
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' );
20
    unitsperissue => 1,
31
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' );
32
};
21
};
33
22
34
subtest 'Tests for yearly frequencies' => sub {
23
my $subscription = {
35
    plan tests => 10;
24
    firstacquidate     => '1970-01-01',
36
25
    irregularity       => '',
37
    # First add a few frequencies
26
    countissuesperunit => 1,
38
    my $freq_1i_1y = AddSubscriptionFrequency({
39
        description => "1 issue per year",
40
        unit => 'year',
41
        issuesperunit => 1,
42
        unitsperissue => 1,
43
    });
44
    my $freq_1i_3y = AddSubscriptionFrequency({
45
        description => "1 issue per 3 years",
46
        unit => 'year',
47
        issuesperunit => 1,
48
        unitsperissue => 3,
49
    });
50
    my $freq_5i_1y = AddSubscriptionFrequency({
51
        description => "5 issues per year",
52
        unit => 'year',
53
        issuesperunit => 5,
54
        unitsperissue => 1,
55
    });
56
    my $freq_366i_1y = AddSubscriptionFrequency({
57
        description => "366 issue per year",
58
        unit => 'year',
59
        issuesperunit => 366,
60
        unitsperissue => 1,
61
    });
62
63
    # TEST CASE - 1 issue per year
64
    my $subscription = {
65
        periodicity => $freq_1i_1y,
66
        firstacquidate => '1972-02-10',
67
        countissuesperunit => 1,
68
    };
69
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09'), 1, 'Feb 9 still 1' );
70
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10'), 2, 'Feb 10 goes to 2' );
71
72
    # TEST CASE - 1 issue per 3 years
73
    $subscription->{periodicity} = $freq_1i_3y;
74
    $subscription->{firstacquidate} = '1972-02-20';
75
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19'), 1, 'Feb 19, 1975 still 1' );
76
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20'), 2, 'Feb 20, 1975 goes to 2' );
77
78
    # TEST CASE - 5 issues per year
79
    $subscription->{periodicity} = $freq_5i_1y;
80
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
81
    $subscription->{countissuesperunit} = 1;
82
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11'), 1, 'May 11 still 1' );
83
    $subscription->{countissuesperunit} = 2;
84
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12'), 2, 'May 12 goes to 2' );
85
    $subscription->{countissuesperunit} = 5;
86
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27'), 5, 'Feb 27 should still be 5' );
87
    $subscription->{countissuesperunit} = 1;
88
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 6, 'Feb 28 goes to 6' );
89
90
    # TEST CASE - 366 issues per year (hypothetical example)
91
    # Testing prevention of divide by zero
92
    $subscription->{periodicity} = $freq_366i_1y;
93
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
94
    $subscription->{countissuesperunit} = 366;
95
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27'), 366, 'Feb 27 still at 366' );
96
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 732, 'Feb 28 goes to 732' );
97
98
};
27
};
99
28
my $issueNumber;
100
subtest 'Tests for monthly frequencies' => sub {
29
101
    plan tests => 8;
30
$issueNumber =
102
31
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
103
    # First add a few frequencies
32
is( $issueNumber, '1' );
104
    my $freq_1i_5m = AddSubscriptionFrequency({
33
105
        description => "1 issue per 5 months",
34
$issueNumber =
106
        unit => 'month',
35
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
107
        issuesperunit => 1,
36
is( $issueNumber, '2' );
108
        unitsperissue => 5,
37
$issueNumber =
109
    });
38
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
110
    my $freq_4i_1m = AddSubscriptionFrequency({
39
is( $issueNumber, '3' );
111
        description => "4 issue per month",
40
112
        unit => 'month',
41
# TEST CASE - 2 issues per day, no irregularity
113
        issuesperunit => 4,
42
$frequency = {
114
        unitsperissue => 1,
43
    description   => "Two issues per day",
115
    });
44
    unit          => 'day',
116
45
    issuesperunit => 2,
117
    # TEST CASE - 1 issue per 5 months
46
    unitsperissue => 1,
118
    my $subscription = {
119
        periodicity => $freq_1i_5m,
120
        firstacquidate => '1972-02-10',
121
        countissuesperunit => 1,
122
    };
123
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09'), 1, 'Jul 9 still 1' );
124
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10'), 2, 'Jul 10 goes to 2' );
125
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09'), 3, 'May 9 still 3' );
126
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10'), 4, 'May 10 goes to 4' );
127
128
    # TEST CASE - 4 issue per 1 months
129
    $subscription = {
130
        periodicity => $freq_4i_1m,
131
        firstacquidate => '1972-02-22',
132
        countissuesperunit => 1,
133
    };
134
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28'), 1, 'Feb 28 still 1' );
135
    $subscription->{countissuesperunit} = 2;
136
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29'), 2, 'Feb 29 goes to 2' );
137
    $subscription->{countissuesperunit} = 4;
138
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21'), 4, 'Mar 21 still 4' );
139
    $subscription->{countissuesperunit} = 1;
140
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22'), 5, 'Mar 22 goes to 5' );
141
142
};
47
};
143
48
$subscription = {
144
subtest 'Tests for weekly frequencies' => sub {
49
    firstacquidate     => '1970-01-01',
145
    plan tests => 4;
50
    irregularity       => '',
146
51
    countissuesperunit => 1,
147
    # First add a few frequencies
148
    my $freq_1i_7w = AddSubscriptionFrequency({
149
        description => "1 issue per 7 weeks",
150
        unit => 'week',
151
        issuesperunit => 1,
152
        unitsperissue => 7,
153
    });
154
    my $freq_3i_1w = AddSubscriptionFrequency({
155
        description => "3 issues per week",
156
        unit => 'week',
157
        issuesperunit => 3,
158
        unitsperissue => 1,
159
    });
160
161
    # TEST CASE - 1 issue per 7 weeks
162
    my $subscription = {
163
        periodicity => $freq_1i_7w,
164
        firstacquidate => '1972-02-10',
165
        countissuesperunit => 1,
166
    };
167
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29'), 1, 'Mar 29 still 1' );
168
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30'), 2, 'Mar 30 goes to 2' );
169
170
    # TEST CASE - 3 issue per 1 week
171
    $subscription = {
172
        periodicity => $freq_3i_1w,
173
        firstacquidate => '1972-02-03',
174
        countissuesperunit => 1,
175
    };
176
    $subscription->{countissuesperunit} = 3;
177
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09'), 3, 'Feb 9 still 3' );
178
    $subscription->{countissuesperunit} = 1;
179
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10'), 4, 'Feb 10 goes to 4' );
180
};
52
};
181
53
$issueNumber =
182
subtest 'Tests for dayly frequencies' => sub {
54
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
183
    plan tests => 4;
55
is( $issueNumber, '1' );
184
56
$issueNumber =
185
    # First add a few frequencies
57
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
186
    my $freq_1i_12d = AddSubscriptionFrequency({
58
is( $issueNumber, '3' );
187
        description => "1 issue per 12 days",
59
$issueNumber =
188
        unit => 'day',
60
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
189
        issuesperunit => 1,
61
is( $issueNumber, '5' );
190
        unitsperissue => 12,
62
191
    });
63
$subscription->{countissuesperunit} = 2;
192
    my $freq_3i_1d = AddSubscriptionFrequency({
64
$issueNumber =
193
        description => "3 issues per day",
65
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
194
        unit => 'day',
66
is( $issueNumber, '2' );
195
        issuesperunit => 3,
67
$issueNumber =
196
        unitsperissue => 1,
68
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
197
    });
69
is( $issueNumber, '4' );
198
70
$issueNumber =
199
    # TEST CASE - 1 issue per 12 days
71
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
200
    my $subscription = {
72
is( $issueNumber, '6' );
201
        periodicity => $freq_1i_12d,
73
202
        firstacquidate => '1972-03-16',
74
# TEST CASE - 1 issue every 2 days, no irregularity
203
        countissuesperunit => 1,
75
$frequency = {
204
    };
76
    description   => "one issue every two days",
205
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27'), 1, 'Mar 27 still 1' );
77
    unit          => 'day',
206
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28'), 2, 'Mar 28 goes to 2' );
78
    issuesperunit => 1,
207
79
    unitsperissue => 2,
208
    # TEST CASE - 3 issue per day
209
    $subscription = {
210
        periodicity => $freq_3i_1d,
211
        firstacquidate => '1972-04-23',
212
        countissuesperunit => 1,
213
    };
214
    $subscription->{countissuesperunit} = 3;
215
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01'), 27, 'May 1 still 27' );
216
    $subscription->{countissuesperunit} = 1;
217
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02'), 28, 'May 2 goes to 28' );
218
};
80
};
219
81
$subscription = {
220
$schema->storage->txn_rollback;
82
    firstacquidate     => '1970-01-01',
83
    irregularity       => '',
84
    countissuesperunit => 1,
85
};
86
$issueNumber =
87
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
88
is( $issueNumber, 1 );
89
$issueNumber =
90
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
91
is( $issueNumber, 1 );
92
$issueNumber =
93
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
94
is( $issueNumber, 2 );
95
$issueNumber =
96
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-04', $frequency );
97
is( $issueNumber, 2 );
98
$issueNumber =
99
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-05', $frequency );
100
is( $issueNumber, 3 );
101
102
# TEST CASE - 1 issue per week, no irregularity
103
$frequency = {
104
    description   => "one issue per week",
105
    unit          => 'week',
106
    issuesperunit => 1,
107
    unitsperissue => 1,
108
};
109
$subscription = {
110
    firstacquidate     => '1970-01-01',
111
    irregularity       => '',
112
    countissuesperunit => 1,
113
};
114
$issueNumber =
115
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
116
is( $issueNumber, 1 );
117
$issueNumber =
118
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
119
is( $issueNumber, 1 );
120
$issueNumber =
121
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-08', $frequency );
122
is( $issueNumber, 2 );
123
$issueNumber =
124
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-15', $frequency );
125
is( $issueNumber, 3 );
126
127
$dbh->rollback;
(-)a/t/db_dependent/Serials/GetNextDate.t (-167 / +141 lines)
Lines 19-570 my $frequency = { Link Here
19
    issuesperunit => 1,
19
    issuesperunit => 1,
20
    unitsperissue => 1,
20
    unitsperissue => 1,
21
};
21
};
22
my $id = AddSubscriptionFrequency($frequency);
23
22
24
my $subscription = {
23
my $subscription = {
25
    periodicity => $id,
26
    firstacquidate => '1970-01-01',
24
    firstacquidate => '1970-01-01',
27
    irregularity => '',
25
    irregularity => '',
28
    countissuesperunit => 1,
26
    countissuesperunit => 1,
29
};
27
};
30
my $publisheddate = $subscription->{firstacquidate};
28
my $publisheddate = $subscription->{firstacquidate};
31
29
32
$publisheddate = GetNextDate($subscription, $publisheddate);
30
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
33
is($publisheddate, '1970-01-02');
31
is($publisheddate, '1970-01-02');
34
$publisheddate = GetNextDate($subscription, $publisheddate);
32
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
35
is($publisheddate, '1970-01-03');
33
is($publisheddate, '1970-01-03');
36
$publisheddate = GetNextDate($subscription, $publisheddate);
34
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
37
is($publisheddate, '1970-01-04');
35
is($publisheddate, '1970-01-04');
38
36
39
# TEST CASE - 1 issue per day, irregularities
37
# TEST CASE - 1 issue per day, irregularities
40
$subscription = {
38
$subscription = {
41
    periodicity => $id,
42
    firstacquidate => '1970-01-01',
39
    firstacquidate => '1970-01-01',
43
    irregularity => '2;4',  # Skip the second and fourth issues
40
    irregularity => '2;4',  # Skip the second and fourth issues
44
    countissuesperunit => 1,
41
    countissuesperunit => 1,
45
};
42
};
46
$publisheddate = $subscription->{firstacquidate};
43
$publisheddate = $subscription->{firstacquidate};
47
$publisheddate = GetNextDate($subscription, $publisheddate);
44
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
48
is($publisheddate, '1970-01-03');
45
is($publisheddate, '1970-01-03');
49
$publisheddate = GetNextDate($subscription, $publisheddate);
46
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
50
is($publisheddate, '1970-01-05');
47
is($publisheddate, '1970-01-05');
51
$publisheddate = GetNextDate($subscription, $publisheddate);
48
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
52
is($publisheddate, '1970-01-06');
49
is($publisheddate, '1970-01-06');
53
50
54
# TEST CASE - 2 issues per day, no irregularity
51
# TEST CASE - 2 issues per day, no irregularity
55
$id = AddSubscriptionFrequency({
52
$frequency = {
56
    description => "Two issues per day",
53
    description => "Two issues per day",
57
    unit => 'day',
54
    unit => 'day',
58
    issuesperunit => 2,
55
    issuesperunit => 2,
59
    unitsperissue => 1,
56
    unitsperissue => 1,
60
});
57
};
61
$subscription = {
58
$subscription = {
62
    periodicity => $id,
63
    firstacquidate => '1970-01-01',
59
    firstacquidate => '1970-01-01',
64
    irregularity => '',
60
    irregularity => '',
65
    countissuesperunit => 1,
61
    countissuesperunit => 1,
66
};
62
};
67
$publisheddate = $subscription->{firstacquidate};
63
$publisheddate = $subscription->{firstacquidate};
68
$publisheddate = GetNextDate($subscription, $publisheddate);
64
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
69
is($publisheddate, '1970-01-01');
65
is($publisheddate, '1970-01-01');
70
$publisheddate = GetNextDate($subscription, $publisheddate);
66
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
71
is($publisheddate, '1970-01-02');
67
is($publisheddate, '1970-01-02');
72
$publisheddate = GetNextDate($subscription, $publisheddate);
68
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
73
is($publisheddate, '1970-01-02');
69
is($publisheddate, '1970-01-02');
74
$publisheddate = GetNextDate($subscription, $publisheddate);
70
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
75
is($publisheddate, '1970-01-03');
71
is($publisheddate, '1970-01-03');
76
72
77
# TEST CASE - 2 issues per day, irregularities
73
# TEST CASE - 2 issues per day, irregularities
78
$subscription = {
74
$subscription = {
79
    periodicity => $id,
80
    firstacquidate => '1970-01-01',
75
    firstacquidate => '1970-01-01',
81
    irregularity => '3;5;6',
76
    irregularity => '3;5;6',
82
    countissuesperunit => 1,
77
    countissuesperunit => 1,
83
};
78
};
84
$publisheddate = $subscription->{firstacquidate};
79
$publisheddate = $subscription->{firstacquidate};
85
$publisheddate = GetNextDate($subscription, $publisheddate);
80
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
86
is($publisheddate, '1970-01-01');
81
is($publisheddate, '1970-01-01');
87
$publisheddate = GetNextDate($subscription, $publisheddate);
82
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
88
is($publisheddate, '1970-01-02');
83
is($publisheddate, '1970-01-02');
89
$publisheddate = GetNextDate($subscription, $publisheddate);
84
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
90
is($publisheddate, '1970-01-04');
85
is($publisheddate, '1970-01-04');
91
$publisheddate = GetNextDate($subscription, $publisheddate);
86
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
92
is($publisheddate, '1970-01-04');
87
is($publisheddate, '1970-01-04');
93
$publisheddate = GetNextDate($subscription, $publisheddate);
88
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
94
is($publisheddate, '1970-01-05');
89
is($publisheddate, '1970-01-05');
95
90
96
# TEST CASE - 1 issue every 2 days, no irregularity
91
# TEST CASE - 1 issue every 2 days, no irregularity
97
$id = AddSubscriptionFrequency({
92
$frequency = {
98
    description => "one issue every two days",
93
    description => "one issue every two days",
99
    unit => 'day',
94
    unit => 'day',
100
    issuesperunit => 1,
95
    issuesperunit => 1,
101
    unitsperissue => 2,
96
    unitsperissue => 2,
102
});
97
};
103
$subscription = {
98
$subscription = {
104
    periodicity => $id,
105
    firstacquidate => '1970-01-01',
99
    firstacquidate => '1970-01-01',
106
    irregularity => '',
100
    irregularity => '',
107
    countissuesperunit => 1,
101
    countissuesperunit => 1,
108
};
102
};
109
$publisheddate = $subscription->{firstacquidate};
103
$publisheddate = $subscription->{firstacquidate};
110
$publisheddate = GetNextDate($subscription, $publisheddate);
104
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
111
is($publisheddate, '1970-01-03');
105
is($publisheddate, '1970-01-03');
112
$publisheddate = GetNextDate($subscription, $publisheddate);
106
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
113
is($publisheddate, '1970-01-05');
107
is($publisheddate, '1970-01-05');
114
108
115
# TEST CASE - 1 issue every 2 days, irregularities
109
# TEST CASE - 1 issue every 2 days, irregularities
116
$subscription = {
110
$subscription = {
117
    periodicity => $id,
118
    firstacquidate => '1970-01-01',
111
    firstacquidate => '1970-01-01',
119
    irregularity => '3',
112
    irregularity => '3',
120
    countissuesperunit => 1,
113
    countissuesperunit => 1,
121
};
114
};
122
$publisheddate = $subscription->{firstacquidate};
115
$publisheddate = $subscription->{firstacquidate};
123
$publisheddate = GetNextDate($subscription, $publisheddate);
116
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
124
is($publisheddate, '1970-01-03');
117
is($publisheddate, '1970-01-03');
125
$publisheddate = GetNextDate($subscription, $publisheddate);
118
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
126
is($publisheddate, '1970-01-07');
119
is($publisheddate, '1970-01-07');
127
$publisheddate = GetNextDate($subscription, $publisheddate);
120
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
128
is($publisheddate, '1970-01-09');
121
is($publisheddate, '1970-01-09');
129
122
130
# TEST CASE - 1 issue per week, no irregularity
123
# TEST CASE - 1 issue per week, no irregularity
131
$id = AddSubscriptionFrequency({
124
$frequency = {
132
    description => "one issue per week",
125
    description => "one issue per week",
133
    unit => 'week',
126
    unit => 'week',
134
    issuesperunit => 1,
127
    issuesperunit => 1,
135
    unitsperissue => 1,
128
    unitsperissue => 1,
136
});
129
};
137
$subscription = {
130
$subscription = {
138
    periodicity => $id,
139
    firstacquidate => '1970-01-01',
131
    firstacquidate => '1970-01-01',
140
    irregularity => '',
132
    irregularity => '',
141
    countissuesperunit => 1,
133
    countissuesperunit => 1,
142
};
134
};
143
$publisheddate = $subscription->{firstacquidate};
135
$publisheddate = $subscription->{firstacquidate};
144
$publisheddate = GetNextDate($subscription, $publisheddate);
136
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
145
is($publisheddate, '1970-01-08');
137
is($publisheddate, '1970-01-08');
146
$publisheddate = GetNextDate($subscription, $publisheddate);
138
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
147
is($publisheddate, '1970-01-15');
139
is($publisheddate, '1970-01-15');
148
140
149
# TEST CASE - 1 issue per week, irregularities
141
# TEST CASE - 1 issue per week, irregularities
150
$subscription = {
142
$subscription = {
151
    periodicity => $id,
152
    firstacquidate => '1970-01-01',
143
    firstacquidate => '1970-01-01',
153
    irregularity => '3',
144
    irregularity => '3',
154
    countissuesperunit => 1,
145
    countissuesperunit => 1,
155
};
146
};
156
$publisheddate = $subscription->{firstacquidate};
147
$publisheddate = $subscription->{firstacquidate};
157
$publisheddate = GetNextDate($subscription, $publisheddate);
148
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
158
is($publisheddate, '1970-01-08');
149
is($publisheddate, '1970-01-08');
159
$publisheddate = GetNextDate($subscription, $publisheddate);
150
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
160
is($publisheddate, '1970-01-22');
151
is($publisheddate, '1970-01-22');
161
$publisheddate = GetNextDate($subscription, $publisheddate);
152
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
162
is($publisheddate, '1970-01-29');
153
is($publisheddate, '1970-01-29');
163
154
164
# TEST CASE - 1 issue every 2 weeks, no irregularity
155
# TEST CASE - 1 issue every 2 weeks, no irregularity
165
$id = AddSubscriptionFrequency({
156
$frequency = {
166
    description => "one issue every 2 weeks",
157
    description => "one issue every 2 weeks",
167
    unit => 'week',
158
    unit => 'week',
168
    issuesperunit => 1,
159
    issuesperunit => 1,
169
    unitsperissue => 2,
160
    unitsperissue => 2,
170
});
161
};
171
$subscription = {
162
$subscription = {
172
    periodicity => $id,
173
    firstacquidate => '1970-01-01',
163
    firstacquidate => '1970-01-01',
174
    irregularity => '',
164
    irregularity => '',
175
    countissuesperunit => 1,
165
    countissuesperunit => 1,
176
};
166
};
177
$publisheddate = $subscription->{firstacquidate};
167
$publisheddate = $subscription->{firstacquidate};
178
$publisheddate = GetNextDate($subscription, $publisheddate);
168
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
179
is($publisheddate, '1970-01-15');
169
is($publisheddate, '1970-01-15');
180
$publisheddate = GetNextDate($subscription, $publisheddate);
170
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
181
is($publisheddate, '1970-01-29');
171
is($publisheddate, '1970-01-29');
182
$publisheddate = GetNextDate($subscription, $publisheddate);
172
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
183
is($publisheddate, '1970-02-12');
173
is($publisheddate, '1970-02-12');
184
174
185
# TEST CASE - 1 issue every 2 weeks, irregularities
175
# TEST CASE - 1 issue every 2 weeks, irregularities
186
$subscription = {
176
$subscription = {
187
    periodicity => $id,
188
    firstacquidate => '1970-01-01',
177
    firstacquidate => '1970-01-01',
189
    irregularity => '3',
178
    irregularity => '3',
190
    countissuesperunit => 1,
179
    countissuesperunit => 1,
191
};
180
};
192
$publisheddate = $subscription->{firstacquidate};
181
$publisheddate = $subscription->{firstacquidate};
193
$publisheddate = GetNextDate($subscription, $publisheddate);
182
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
194
is($publisheddate, '1970-01-15');
183
is($publisheddate, '1970-01-15');
195
$publisheddate = GetNextDate($subscription, $publisheddate);
184
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
196
is($publisheddate, '1970-02-12');
185
is($publisheddate, '1970-02-12');
197
$publisheddate = GetNextDate($subscription, $publisheddate);
186
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
198
is($publisheddate, '1970-02-26');
187
is($publisheddate, '1970-02-26');
199
188
200
# TEST CASE - 2 issues per week, no irregularity
189
# TEST CASE - 2 issues per week, no irregularity
201
$id = AddSubscriptionFrequency({
190
$frequency = {
202
    description => "two issues per week",
191
    description => "two issues per week",
203
    unit => 'week',
192
    unit => 'week',
204
    issuesperunit => 2,
193
    issuesperunit => 2,
205
    unitsperissue => 1,
194
    unitsperissue => 1,
206
});
195
};
207
$subscription = {
196
$subscription = {
208
    periodicity => $id,
209
    firstacquidate => '1970-01-01',
197
    firstacquidate => '1970-01-01',
210
    irregularity => '',
198
    irregularity => '',
211
    countissuesperunit => 1,
199
    countissuesperunit => 1,
212
};
200
};
213
$publisheddate = $subscription->{firstacquidate};
201
$publisheddate = $subscription->{firstacquidate};
214
$publisheddate = GetNextDate($subscription, $publisheddate);
202
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
215
is($publisheddate, '1970-01-04');
203
is($publisheddate, '1970-01-04');
216
$publisheddate = GetNextDate($subscription, $publisheddate);
204
# when more than 1 issue per week, date is automatically set to the same day of
205
# week as firstacquidate
206
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
217
is($publisheddate, '1970-01-08');
207
is($publisheddate, '1970-01-08');
218
$publisheddate = GetNextDate($subscription, $publisheddate);
208
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
219
is($publisheddate, '1970-01-11');
209
is($publisheddate, '1970-01-11');
220
$publisheddate = GetNextDate($subscription, $publisheddate);
210
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
221
is($publisheddate, '1970-01-15');
211
is($publisheddate, '1970-01-15');
222
212
223
# TEST CASE - 2 issues per week, irregularities
213
# TEST CASE - 2 issues per week, irregularities
224
$subscription = {
214
$subscription = {
225
    periodicity => $id,
226
    firstacquidate => '1970-01-01',
215
    firstacquidate => '1970-01-01',
227
    irregularity => '3;5;6',
216
    irregularity => '3;5;6',
228
    countissuesperunit => 1,
217
    countissuesperunit => 1,
229
};
218
};
230
$publisheddate = $subscription->{firstacquidate};
219
$publisheddate = $subscription->{firstacquidate};
231
$publisheddate = GetNextDate($subscription, $publisheddate);
220
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
232
is($publisheddate, '1970-01-04');
221
is($publisheddate, '1970-01-04');
233
$publisheddate = GetNextDate($subscription, $publisheddate);
222
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
234
is($publisheddate, '1970-01-11');
223
is($publisheddate, '1970-01-11');
235
$publisheddate = GetNextDate($subscription, $publisheddate);
224
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
236
is($publisheddate, '1970-01-22');
225
is($publisheddate, '1970-01-22');
237
$publisheddate = GetNextDate($subscription, $publisheddate);
226
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
238
is($publisheddate, '1970-01-25');
227
is($publisheddate, '1970-01-25');
239
$publisheddate = GetNextDate($subscription, $publisheddate);
228
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
240
is($publisheddate, '1970-01-29');
229
is($publisheddate, '1970-01-29');
241
230
242
# TEST CASE - 6 issues per week, no irregularity
231
# TEST CASE - 6 issues per week, no irregularity
243
$id = AddSubscriptionFrequency({
232
$frequency = {
244
    description => "six issues per week",
233
    description => "six issues per week",
245
    unit => 'week',
234
    unit => 'week',
246
    issuesperunit => 6,
235
    issuesperunit => 6,
247
    unitsperissue => 1,
236
    unitsperissue => 1,
248
});
237
};
249
$subscription = {
238
$subscription = {
250
    periodicity => $id,
251
    firstacquidate => '1970-01-06',
239
    firstacquidate => '1970-01-06',
252
    irregularity => '',
240
    irregularity => '',
253
    countissuesperunit => 1,
241
    countissuesperunit => 1,
254
};
242
};
255
$publisheddate = $subscription->{firstacquidate};
243
$publisheddate = $subscription->{firstacquidate};
256
$publisheddate = GetNextDate($subscription, $publisheddate);
244
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
257
is($publisheddate, '1970-01-07');
245
is($publisheddate, '1970-01-07');
258
$publisheddate = GetNextDate($subscription, $publisheddate);
246
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
259
is($publisheddate, '1970-01-08');
247
is($publisheddate, '1970-01-08');
260
$publisheddate = GetNextDate($subscription, $publisheddate);
248
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
261
is($publisheddate, '1970-01-09');
249
is($publisheddate, '1970-01-09');
262
$publisheddate = GetNextDate($subscription, $publisheddate);
250
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
263
is($publisheddate, '1970-01-10');
251
is($publisheddate, '1970-01-10');
264
$publisheddate = GetNextDate($subscription, $publisheddate);
252
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
265
is($publisheddate, '1970-01-11');
253
is($publisheddate, '1970-01-11');
266
$publisheddate = GetNextDate($subscription, $publisheddate);
254
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
267
is($publisheddate, '1970-01-13');
255
is($publisheddate, '1970-01-13');
268
256
269
# TEST CASE - 6 issues per week, irregularities
257
# TEST CASE - 6 issues per week, irregularities
270
$subscription = {
258
$subscription = {
271
    periodicity => $id,
272
    firstacquidate => '1970-01-06',
259
    firstacquidate => '1970-01-06',
273
    irregularity => '3;5;6',
260
    irregularity => '3;5;6',
274
    countissuesperunit => 1,
261
    countissuesperunit => 1,
275
};
262
};
276
$publisheddate = $subscription->{firstacquidate};
263
$publisheddate = $subscription->{firstacquidate};
277
$publisheddate = GetNextDate($subscription, $publisheddate);
264
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
278
is($publisheddate, '1970-01-07');
265
is($publisheddate, '1970-01-07');
279
$publisheddate = GetNextDate($subscription, $publisheddate);
266
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
280
is($publisheddate, '1970-01-09');
267
is($publisheddate, '1970-01-09');
281
$publisheddate = GetNextDate($subscription, $publisheddate);
268
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
282
is($publisheddate, '1970-01-13');
269
is($publisheddate, '1970-01-13');
283
$publisheddate = GetNextDate($subscription, $publisheddate);
270
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
284
is($publisheddate, '1970-01-14');
271
is($publisheddate, '1970-01-14');
285
272
286
# TEST CASE - 1 issue per month, no irregularity
273
# TEST CASE - 1 issue per month, no irregularity
287
$id = AddSubscriptionFrequency({
274
$frequency = {
288
    description => "1 issue per month",
275
    description => "1 issue per month",
289
    unit => 'month',
276
    unit => 'month',
290
    issuesperunit => 1,
277
    issuesperunit => 1,
291
    unitsperissue => 1,
278
    unitsperissue => 1,
292
});
279
};
293
$subscription = {
280
$subscription = {
294
    periodicity => $id,
295
    firstacquidate => '1970-01-01',
281
    firstacquidate => '1970-01-01',
296
    irregularity => '',
282
    irregularity => '',
297
    countissuesperunit => 1,
283
    countissuesperunit => 1,
298
};
284
};
299
$publisheddate = $subscription->{firstacquidate};
285
$publisheddate = $subscription->{firstacquidate};
300
$publisheddate = GetNextDate($subscription, $publisheddate);
286
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
301
is($publisheddate, '1970-02-01');
287
is($publisheddate, '1970-02-01');
302
$publisheddate = GetNextDate($subscription, $publisheddate);
288
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
303
is($publisheddate, '1970-03-01');
289
is($publisheddate, '1970-03-01');
304
$publisheddate = GetNextDate($subscription, $publisheddate);
290
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
305
is($publisheddate, '1970-04-01');
291
is($publisheddate, '1970-04-01');
306
292
307
# TEST CASE - 1 issue per month, irregularities
293
# TEST CASE - 1 issue per month, irregularities
308
$subscription = {
294
$subscription = {
309
    periodicity => $id,
310
    firstacquidate => '1970-01-01',
295
    firstacquidate => '1970-01-01',
311
    irregularity => '2;4',
296
    irregularity => '2;4',
312
    countissuesperunit => 1,
297
    countissuesperunit => 1,
313
};
298
};
314
$publisheddate = $subscription->{firstacquidate};
299
$publisheddate = $subscription->{firstacquidate};
315
$publisheddate = GetNextDate($subscription, $publisheddate);
300
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
316
is($publisheddate, '1970-03-01');
301
is($publisheddate, '1970-03-01');
317
$publisheddate = GetNextDate($subscription, $publisheddate);
302
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
318
is($publisheddate, '1970-05-01');
303
is($publisheddate, '1970-05-01');
319
$publisheddate = GetNextDate($subscription, $publisheddate);
304
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
320
is($publisheddate, '1970-06-01');
305
is($publisheddate, '1970-06-01');
321
306
322
# TEST CASE - 1 issue every 2 months, no irregularity
307
# TEST CASE - 1 issue every 2 months, no irregularity
323
$id = AddSubscriptionFrequency({
308
$frequency = {
324
    description => "1 issue every 2 months",
309
    description => "1 issue every 2 months",
325
    unit => 'month',
310
    unit => 'month',
326
    issuesperunit => 1,
311
    issuesperunit => 1,
327
    unitsperissue => 2,
312
    unitsperissue => 2,
328
});
313
};
329
$subscription = {
314
$subscription = {
330
    periodicity => $id,
331
    firstacquidate => '1970-01-01',
315
    firstacquidate => '1970-01-01',
332
    irregularity => '',
316
    irregularity => '',
333
    countissuesperunit => 1,
317
    countissuesperunit => 1,
334
};
318
};
335
$publisheddate = $subscription->{firstacquidate};
319
$publisheddate = $subscription->{firstacquidate};
336
$publisheddate = GetNextDate($subscription, $publisheddate);
320
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
337
is($publisheddate, '1970-03-01');
321
is($publisheddate, '1970-03-01');
338
$publisheddate = GetNextDate($subscription, $publisheddate);
322
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
339
is($publisheddate, '1970-05-01');
323
is($publisheddate, '1970-05-01');
340
$publisheddate = GetNextDate($subscription, $publisheddate);
324
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
341
is($publisheddate, '1970-07-01');
325
is($publisheddate, '1970-07-01');
342
326
343
# TEST CASE - 1 issue every 2 months, irregularities
327
# TEST CASE - 1 issue every 2 months, irregularities
344
$subscription = {
328
$subscription = {
345
    periodicity => $id,
346
    firstacquidate => '1970-01-01',
329
    firstacquidate => '1970-01-01',
347
    irregularity => '2;3',
330
    irregularity => '2;3',
348
    countissuesperunit => 1,
331
    countissuesperunit => 1,
349
};
332
};
350
$publisheddate = $subscription->{firstacquidate};
333
$publisheddate = $subscription->{firstacquidate};
351
$publisheddate = GetNextDate($subscription, $publisheddate);
334
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
352
is($publisheddate, '1970-07-01');
335
is($publisheddate, '1970-07-01');
353
$publisheddate = GetNextDate($subscription, $publisheddate);
336
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
354
is($publisheddate, '1970-09-01');
337
is($publisheddate, '1970-09-01');
355
$publisheddate = GetNextDate($subscription, $publisheddate);
338
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
356
is($publisheddate, '1970-11-01');
339
is($publisheddate, '1970-11-01');
357
340
358
# TEST CASE - 2 issues per month, no irregularity
341
# TEST CASE - 2 issues per month, no irregularity
359
$id = AddSubscriptionFrequency({
342
$frequency = {
360
    description => "2 issues per month",
343
    description => "2 issues per month",
361
    unit => 'month',
344
    unit => 'month',
362
    issuesperunit => 2,
345
    issuesperunit => 2,
363
    unitsperissue => 1,
346
    unitsperissue => 1,
364
});
347
};
365
$subscription = {
348
$subscription = {
366
    periodicity => $id,
367
    firstacquidate => '1970-01-01',
349
    firstacquidate => '1970-01-01',
368
    irregularity => '',
350
    irregularity => '',
369
    countissuesperunit => 1,
351
    countissuesperunit => 1,
370
};
352
};
371
$publisheddate = $subscription->{firstacquidate};
353
$publisheddate = $subscription->{firstacquidate};
372
$publisheddate = GetNextDate($subscription, $publisheddate);
354
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
373
is($publisheddate, '1970-01-16', 'Jan 16');
355
is($publisheddate, '1970-01-16', 'January has 31 days');
374
$publisheddate = GetNextDate($subscription, $publisheddate);
356
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
375
is($publisheddate, '1970-02-01', 'Feb 1');
357
is($publisheddate, '1970-02-01');
376
$publisheddate = GetNextDate($subscription, $publisheddate);
358
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
377
is($publisheddate, '1970-02-16', 'Feb 16');
359
is($publisheddate, '1970-02-16', 'February has only 28 days');
378
$publisheddate = GetNextDate($subscription, $publisheddate);
360
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
379
is($publisheddate, '1970-03-01', 'Mar 1' );
361
is($publisheddate, '1970-03-01');
380
362
381
# TEST CASE - 2 issues per month, irregularities
363
# TEST CASE - 2 issues per month, irregularities
382
$subscription = {
364
$subscription = {
383
    periodicity => $id,
384
    firstacquidate => '1970-01-01',
365
    firstacquidate => '1970-01-01',
385
    irregularity => '3;5;6',
366
    irregularity => '3;5;6',
386
    countissuesperunit => 1,
367
    countissuesperunit => 1,
387
};
368
};
388
$publisheddate = $subscription->{firstacquidate};
369
$publisheddate = $subscription->{firstacquidate};
389
$publisheddate = GetNextDate($subscription, $publisheddate);
370
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
390
is($publisheddate, '1970-01-16', 'Jan 16' );
371
is($publisheddate, '1970-01-16', 'January has 31 days');
391
$publisheddate = GetNextDate($subscription, $publisheddate);
372
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
392
is($publisheddate, '1970-02-16', 'Feb 16 (skipping Feb 1)' );
373
is($publisheddate, '1970-02-16', 'February has only 28 days');
393
$publisheddate = GetNextDate($subscription, $publisheddate);
374
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
394
is($publisheddate, '1970-04-01', 'Apr 1 (skipping Mar 1 and 16)' );
375
is($publisheddate, '1970-04-01');
395
$publisheddate = GetNextDate($subscription, $publisheddate);
376
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
396
is($publisheddate, '1970-04-16', 'Apr 16' );
377
is($publisheddate, '1970-04-16', 'April has 30 days');
397
$publisheddate = GetNextDate($subscription, $publisheddate);
378
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
398
is($publisheddate, '1970-05-01', 'May 1' );
379
is($publisheddate, '1970-05-01');
399
380
400
# TEST CASE - 1 issue per year, no irregularity
381
# TEST CASE - 1 issue per year, no irregularity
401
$id = AddSubscriptionFrequency({
382
$frequency = {
402
    description => "1 issue per year",
383
    description => "1 issue per year",
403
    unit => 'year',
384
    unit => 'year',
404
    issuesperunit => 1,
385
    issuesperunit => 1,
405
    unitsperissue => 1,
386
    unitsperissue => 1,
406
});
387
};
407
$subscription = {
388
$subscription = {
408
    periodicity => $id,
409
    firstacquidate => '1970-01-01',
389
    firstacquidate => '1970-01-01',
410
    irregularity => '',
390
    irregularity => '',
411
    countissuesperunit => 1,
391
    countissuesperunit => 1,
412
};
392
};
413
$publisheddate = $subscription->{firstacquidate};
393
$publisheddate = $subscription->{firstacquidate};
414
$publisheddate = GetNextDate($subscription, $publisheddate);
394
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
415
is($publisheddate, '1971-01-01');
395
is($publisheddate, '1971-01-01');
416
$publisheddate = GetNextDate($subscription, $publisheddate);
396
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
417
is($publisheddate, '1972-01-01');
397
is($publisheddate, '1972-01-01');
418
$publisheddate = GetNextDate($subscription, $publisheddate);
398
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
419
is($publisheddate, '1973-01-01');
399
is($publisheddate, '1973-01-01');
420
400
421
# TEST CASE - 1 issue per year, irregularities
401
# TEST CASE - 1 issue per year, irregularities
422
$subscription = {
402
$subscription = {
423
    periodicity => $id,
424
    firstacquidate => '1970-01-01',
403
    firstacquidate => '1970-01-01',
425
    irregularity => '2;4',
404
    irregularity => '2;4',
426
    countissuesperunit => 1,
405
    countissuesperunit => 1,
427
};
406
};
428
$publisheddate = $subscription->{firstacquidate};
407
$publisheddate = $subscription->{firstacquidate};
429
$publisheddate = GetNextDate($subscription, $publisheddate);
408
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
430
is($publisheddate, '1972-01-01');
409
is($publisheddate, '1972-01-01');
431
$publisheddate = GetNextDate($subscription, $publisheddate);
410
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
432
is($publisheddate, '1974-01-01');
411
is($publisheddate, '1974-01-01');
433
$publisheddate = GetNextDate($subscription, $publisheddate);
412
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
434
is($publisheddate, '1975-01-01');
413
is($publisheddate, '1975-01-01');
435
414
436
# TEST CASE - 1 issue every 2 years, no irregularity
415
# TEST CASE - 1 issue every 2 years, no irregularity
437
$id = AddSubscriptionFrequency({
416
$frequency = {
438
    description => "1 issue every 2 years",
417
    description => "1 issue every 2 years",
439
    unit => 'year',
418
    unit => 'year',
440
    issuesperunit => 1,
419
    issuesperunit => 1,
441
    unitsperissue => 2,
420
    unitsperissue => 2,
442
});
421
};
443
$subscription = {
422
$subscription = {
444
    periodicity => $id,
445
    firstacquidate => '1970-01-01',
423
    firstacquidate => '1970-01-01',
446
    irregularity => '',
424
    irregularity => '',
447
    countissuesperunit => 1,
425
    countissuesperunit => 1,
448
};
426
};
449
$publisheddate = $subscription->{firstacquidate};
427
$publisheddate = $subscription->{firstacquidate};
450
$publisheddate = GetNextDate($subscription, $publisheddate);
428
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
451
is($publisheddate, '1972-01-01');
429
is($publisheddate, '1972-01-01');
452
$publisheddate = GetNextDate($subscription, $publisheddate);
430
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
453
is($publisheddate, '1974-01-01');
431
is($publisheddate, '1974-01-01');
454
$publisheddate = GetNextDate($subscription, $publisheddate);
432
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
455
is($publisheddate, '1976-01-01');
433
is($publisheddate, '1976-01-01');
456
434
457
# TEST CASE - 1 issue every 2 years, irregularities
435
# TEST CASE - 1 issue every 2 years, irregularities
458
$subscription = {
436
$subscription = {
459
    periodicity => $id,
460
    firstacquidate => '1970-01-01',
437
    firstacquidate => '1970-01-01',
461
    irregularity => '2;4',
438
    irregularity => '2;4',
462
    countissuesperunit => 1,
439
    countissuesperunit => 1,
463
};
440
};
464
$publisheddate = $subscription->{firstacquidate};
441
$publisheddate = $subscription->{firstacquidate};
465
$publisheddate = GetNextDate($subscription, $publisheddate);
442
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
466
is($publisheddate, '1974-01-01');
443
is($publisheddate, '1974-01-01');
467
$publisheddate = GetNextDate($subscription, $publisheddate);
444
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
468
is($publisheddate, '1978-01-01');
445
is($publisheddate, '1978-01-01');
469
$publisheddate = GetNextDate($subscription, $publisheddate);
446
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
470
is($publisheddate, '1980-01-01');
447
is($publisheddate, '1980-01-01');
471
# Move publisheddate to Feb 29 (leap year 1980)
448
# Move publisheddate to Feb 29 (leap year 1980)
472
$publisheddate = '1980-02-29';
449
$publisheddate = '1980-02-29';
473
$publisheddate = GetNextDate( $subscription, $publisheddate );
450
$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency );
474
is( $publisheddate, '1982-02-28', 'Test +2 year from Feb 29' );
451
is( $publisheddate, '1982-02-28', 'Test +2 year from Feb 29' );
475
452
476
# TEST CASE - 2 issues per year, no irregularity
453
# TEST CASE - 2 issues per year, no irregularity
477
$id = AddSubscriptionFrequency({
454
$frequency = {
478
    description => "2 issues per year",
455
    description => "1 issue every 2 years",
479
    unit => 'year',
456
    unit => 'year',
480
    issuesperunit => 2,
457
    issuesperunit => 2,
481
    unitsperissue => 1,
458
    unitsperissue => 1,
482
});
459
};
483
$subscription = {
460
$subscription = {
484
    periodicity => $id,
485
    firstacquidate => '1970-01-01',
461
    firstacquidate => '1970-01-01',
486
    irregularity => '',
462
    irregularity => '',
487
    countissuesperunit => 1,
463
    countissuesperunit => 1,
488
};
464
};
489
$publisheddate = $subscription->{firstacquidate};
465
$publisheddate = $subscription->{firstacquidate};
490
$publisheddate = GetNextDate($subscription, $publisheddate);
466
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
491
is($publisheddate, '1970-07-02');
467
is($publisheddate, '1970-07-02');
492
$publisheddate = GetNextDate($subscription, $publisheddate);
468
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
493
is($publisheddate, '1971-01-01');
469
is($publisheddate, '1971-01-01');
494
$publisheddate = GetNextDate($subscription, $publisheddate);
470
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
495
is($publisheddate, '1971-07-02');
471
is($publisheddate, '1971-07-02');
496
$publisheddate = GetNextDate($subscription, $publisheddate);
472
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
497
is($publisheddate, '1972-01-01');
473
is($publisheddate, '1972-01-01');
498
474
499
# TEST CASE - 2 issues per year, irregularities
475
# TEST CASE - 2 issues per year, irregularities
500
$subscription = {
476
$subscription = {
501
    periodicity => $id,
502
    firstacquidate => '1970-01-01',
477
    firstacquidate => '1970-01-01',
503
    irregularity => '3;5;6',
478
    irregularity => '3;5;6',
504
    countissuesperunit => 1,
479
    countissuesperunit => 1,
505
};
480
};
506
$publisheddate = $subscription->{firstacquidate};
481
$publisheddate = $subscription->{firstacquidate};
507
$publisheddate = GetNextDate($subscription, $publisheddate);
482
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
508
is($publisheddate, '1970-07-02');
483
is($publisheddate, '1970-07-02');
509
$publisheddate = GetNextDate($subscription, $publisheddate);
484
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
510
is($publisheddate, '1971-07-02');
485
is($publisheddate, '1971-07-02');
511
$publisheddate = GetNextDate($subscription, $publisheddate);
486
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
512
is($publisheddate, '1973-01-01');
487
is($publisheddate, '1973-01-01');
513
$publisheddate = GetNextDate($subscription, $publisheddate);
488
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
514
is($publisheddate, '1973-07-02');
489
is($publisheddate, '1973-07-02');
515
$publisheddate = GetNextDate($subscription, $publisheddate);
490
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
516
is($publisheddate, '1974-01-01');
491
is($publisheddate, '1974-01-01');
517
492
518
# TEST CASE - 9 issues per year, dates spread throughout month
493
# TEST CASE - 9 issues per year, dates spread throughout month
519
$id = AddSubscriptionFrequency({
494
$frequency = {
520
    description => "9 issues per year",
495
    description => "9 issues per year",
521
    unit => 'year',
496
    unit => 'year',
522
    issuesperunit => 9,
497
    issuesperunit => 9,
523
    unitsperissue => 1,
498
    unitsperissue => 1,
524
});
499
};
500
525
$subscription = {
501
$subscription = {
526
    periodicity => $id,
527
    firstacquidate => '1970-08-10',
502
    firstacquidate => '1970-08-10',
528
    irregularity => '',
503
    irregularity => '',
529
    countissuesperunit => 1,
504
    countissuesperunit => 1,
530
};
505
};
531
my @dates = ( $subscription->{firstacquidate} );
506
my @dates = ( $subscription->{firstacquidate} );
532
foreach(1..27) {
507
foreach(1..27) {
533
    push @dates, GetNextDate( $subscription, $dates[-1] );
508
    push @dates, GetNextDate( $subscription, $dates[-1], $frequency );
534
}
509
}
535
is( $dates[9],  '1971-08-10', 'Freq 9/yr, 1 year passed' );
510
is( $dates[9],  '1971-08-10', 'Freq 9/yr, 1 year passed' );
536
is( $dates[18], '1972-08-10', 'Freq 9/yr, 2 years passed (leap year)' );
511
is( $dates[18], '1972-08-10', 'Freq 9/yr, 2 years passed (leap year)' );
537
is( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' );
512
is( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' );
538
# Keep (first) position in cycle, but shift back 9 days
513
# Keep (first) position in cycle, but shift back 9 days
539
is( GetNextDate( $subscription, '1973-08-01' ), '1973-09-10', 'Back 9 days, without annual correction' );
514
is( GetNextDate( $subscription, '1973-08-01', $frequency ), '1973-09-10', 'Back 9 days, without annual correction' );
540
# Set position to last in cycle, and shift back 9 days; annual correction
515
# Set position to last in cycle, and shift back 9 days; annual correction
541
$subscription->{countissuesperunit} = 9;
516
$subscription->{countissuesperunit} = 9;
542
is( GetNextDate( $subscription, '1973-08-01' ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' );
517
is( GetNextDate( $subscription, '1973-08-01', $frequency ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' );
543
518
544
# TEST CASE - Irregular
519
# TEST CASE - Irregular
545
$id = AddSubscriptionFrequency({
520
$frequency = {
546
    description => "Irregular",
521
    description => "Irregular",
547
    unit => undef,
522
    unit => undef,
548
    issuesperunit => 1,
523
    issuesperunit => 1,
549
    unitsperissue => 1,
524
    unitsperissue => 1,
550
});
525
};
551
$subscription = {
526
$subscription = {
552
    periodicity => $id,
553
    firstacquidate => '1970-01-01',
527
    firstacquidate => '1970-01-01',
554
    irregularity => '',
528
    irregularity => '',
555
    countissuesperunit => 1,
529
    countissuesperunit => 1,
556
};
530
};
557
$publisheddate = $subscription->{firstacquidate};
531
$publisheddate = $subscription->{firstacquidate};
558
# GetNextDate always return undef if subscription is irregular
532
# GetNextDate always return undef if subscription is irregular
559
$publisheddate = GetNextDate($subscription, $publisheddate);
533
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
560
is($publisheddate, undef);
534
is($publisheddate, undef);
561
535
562
# GetNextDate returns undef if one of two first parameters is undef
536
# GetNextDate returns undef if one of two first parameters is undef
563
$publisheddate = GetNextDate($subscription, undef);
537
$publisheddate = GetNextDate($subscription, undef, $frequency);
564
is($publisheddate, undef);
538
is($publisheddate, undef);
565
$publisheddate = GetNextDate(undef, $subscription->{firstacquidate});
539
$publisheddate = GetNextDate(undef, $subscription->{firstacquidate}, $frequency);
566
is($publisheddate, undef);
540
is($publisheddate, undef);
567
$publisheddate = GetNextDate(undef, undef);
541
$publisheddate = GetNextDate(undef, undef, $frequency);
568
is($publisheddate, undef);
542
is($publisheddate, undef);
569
543
570
$schema->storage->txn_rollback;
544
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials/GetNextSeq.t (-63 / +62 lines)
Lines 43-58 my $subscription = { Link Here
43
};
43
};
44
my $publisheddate = $subscription->{firstacquidate};
44
my $publisheddate = $subscription->{firstacquidate};
45
45
46
my $seq = _next_seq($subscription, $pattern, $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);
48
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
49
$seq = _next_seq($subscription, $pattern, $publisheddate);
49
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
50
is($seq, 'X: 4');
50
is($seq, 'X: 4');
51
$publisheddate = GetNextDate($subscription, $publisheddate);
51
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
52
$seq = _next_seq($subscription, $pattern, $publisheddate);
52
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
53
is($seq, 'X: 2');
53
is($seq, 'X: 2');
54
$publisheddate = GetNextDate($subscription, $publisheddate);
54
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
55
$seq = _next_seq($subscription, $pattern, $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
Lines 79-97 $pattern = { Link Here
79
79
80
$publisheddate = $subscription->{firstacquidate};
80
$publisheddate = $subscription->{firstacquidate};
81
81
82
$seq = _next_seq($subscription, $pattern, $publisheddate);
82
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
83
is($seq, 'X: Tuesday');
83
is($seq, 'X: Tuesday');
84
$publisheddate = GetNextDate($subscription, $publisheddate);
84
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
85
$seq = _next_seq($subscription, $pattern, $publisheddate);
85
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
86
is($seq, 'X: Friday');
86
is($seq, 'X: Friday');
87
$publisheddate = GetNextDate($subscription, $publisheddate);
87
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
88
$seq = _next_seq($subscription, $pattern, $publisheddate);
88
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
89
is($seq, 'X: Sunday');
89
is($seq, 'X: Sunday');
90
$publisheddate = GetNextDate($subscription, $publisheddate);
90
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
91
$seq = _next_seq($subscription, $pattern, $publisheddate);
91
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
92
is($seq, 'X: Monday');
92
is($seq, 'X: Monday');
93
$publisheddate = GetNextDate($subscription, $publisheddate);
93
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
94
$seq = _next_seq($subscription, $pattern, $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
Lines 118-136 $pattern = { Link Here
118
118
119
$publisheddate = $subscription->{firstacquidate};
119
$publisheddate = $subscription->{firstacquidate};
120
120
121
$seq = _next_seq($subscription, $pattern, $publisheddate);
121
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
122
is($seq, 'X: March');
122
is($seq, 'X: March');
123
$publisheddate = GetNextDate($subscription, $publisheddate);
123
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
124
$seq = _next_seq($subscription, $pattern, $publisheddate);
124
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
125
is($seq, 'X: September');
125
is($seq, 'X: September');
126
$publisheddate = GetNextDate($subscription, $publisheddate);
126
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
127
$seq = _next_seq($subscription, $pattern, $publisheddate);
127
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
128
is($seq, 'X: January');
128
is($seq, 'X: January');
129
$publisheddate = GetNextDate($subscription, $publisheddate);
129
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
130
$seq = _next_seq($subscription, $pattern, $publisheddate);
130
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
131
is($seq, 'X: March');
131
is($seq, 'X: March');
132
$publisheddate = GetNextDate($subscription, $publisheddate);
132
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
133
$seq = _next_seq($subscription, $pattern, $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
Lines 157-175 $pattern = { Link Here
157
157
158
$publisheddate = $subscription->{firstacquidate};
158
$publisheddate = $subscription->{firstacquidate};
159
159
160
$seq = _next_seq($subscription, $pattern, $publisheddate);
160
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
161
is($seq, 'X: Summer');
161
is($seq, 'X: Summer');
162
$publisheddate = GetNextDate($subscription, $publisheddate);
162
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
163
$seq = _next_seq($subscription, $pattern, $publisheddate);
163
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
164
is($seq, 'X: Spring');
164
is($seq, 'X: Spring');
165
$publisheddate = GetNextDate($subscription, $publisheddate);
165
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
166
$seq = _next_seq($subscription, $pattern, $publisheddate);
166
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
167
is($seq, 'X: Fall');
167
is($seq, 'X: Fall');
168
$publisheddate = GetNextDate($subscription, $publisheddate);
168
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
169
$seq = _next_seq($subscription, $pattern, $publisheddate);
169
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
170
is($seq, 'X: Winter');
170
is($seq, 'X: Winter');
171
$publisheddate = GetNextDate($subscription, $publisheddate);
171
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
172
$seq = _next_seq($subscription, $pattern, $publisheddate);
172
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
173
is($seq, 'X: Spring');
173
is($seq, 'X: Spring');
174
174
175
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
175
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
Lines 196-214 $pattern = { Link Here
196
196
197
$publisheddate = $subscription->{firstacquidate};
197
$publisheddate = $subscription->{firstacquidate};
198
198
199
$seq = _next_seq($subscription, $pattern, $publisheddate);
199
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
200
is($seq, 'Y: 1, X: 2');
200
is($seq, 'Y: 1, X: 2');
201
$publisheddate = GetNextDate($subscription, $publisheddate);
201
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
202
$seq = _next_seq($subscription, $pattern, $publisheddate);
202
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
203
is($seq, 'Y: 2, X: 1');
203
is($seq, 'Y: 2, X: 1');
204
$publisheddate = GetNextDate($subscription, $publisheddate);
204
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
205
$seq = _next_seq($subscription, $pattern, $publisheddate);
205
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
206
is($seq, 'Y: 2, X: 3');
206
is($seq, 'Y: 2, X: 3');
207
$publisheddate = GetNextDate($subscription, $publisheddate);
207
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
208
$seq = _next_seq($subscription, $pattern, $publisheddate);
208
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
209
is($seq, 'Y: 2, X: 4');
209
is($seq, 'Y: 2, X: 4');
210
$publisheddate = GetNextDate($subscription, $publisheddate);
210
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
211
$seq = _next_seq($subscription, $pattern, $publisheddate);
211
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
212
is($seq, 'Y: 3, X: 1');
212
is($seq, 'Y: 3, X: 1');
213
213
214
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
214
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
Lines 235-278 $pattern = { Link Here
235
235
236
$publisheddate = $subscription->{firstacquidate};
236
$publisheddate = $subscription->{firstacquidate};
237
237
238
$seq = _next_seq($subscription, $pattern, $publisheddate);
238
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
239
is($seq, 'Z: 1, Y: 1, X: 2');
239
is($seq, 'Z: 1, Y: 1, X: 2');
240
$publisheddate = GetNextDate($subscription, $publisheddate);
240
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
241
$seq = _next_seq($subscription, $pattern, $publisheddate);
241
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
242
is($seq, 'Z: 1, Y: 2, X: 1');
242
is($seq, 'Z: 1, Y: 2, X: 1');
243
$publisheddate = GetNextDate($subscription, $publisheddate);
243
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
244
$seq = _next_seq($subscription, $pattern, $publisheddate);
244
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
245
is($seq, 'Z: 1, Y: 2, X: 3');
245
is($seq, 'Z: 1, Y: 2, X: 3');
246
$publisheddate = GetNextDate($subscription, $publisheddate);
246
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
247
$seq = _next_seq($subscription, $pattern, $publisheddate);
247
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
248
is($seq, 'Z: 1, Y: 2, X: 4');
248
is($seq, 'Z: 1, Y: 2, X: 4');
249
for (1..100) {
249
for (1..100) {
250
    $publisheddate = GetNextDate($subscription, $publisheddate);
250
    $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
251
    $seq = _next_seq($subscription, $pattern, $publisheddate);
251
    $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
252
}
252
}
253
$publisheddate = GetNextDate($subscription, $publisheddate);
253
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
254
$seq = _next_seq($subscription, $pattern, $publisheddate);
254
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
255
is($seq, 'Z: 4, Y: 4, X: 1');
255
is($seq, 'Z: 4, Y: 4, X: 1');
256
# 110th is here
256
# 110th is here
257
$publisheddate = GetNextDate($subscription, $publisheddate);
257
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
258
$seq = _next_seq($subscription, $pattern, $publisheddate);
258
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
259
is($seq, 'Z: 4, Y: 4, X: 3');
259
is($seq, 'Z: 4, Y: 4, X: 3');
260
$publisheddate = GetNextDate($subscription, $publisheddate);
260
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
261
$seq = _next_seq($subscription, $pattern, $publisheddate);
261
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
262
is($seq, 'Z: 4, Y: 4, X: 4');
262
is($seq, 'Z: 4, Y: 4, X: 4');
263
$publisheddate = GetNextDate($subscription, $publisheddate);
263
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
264
$seq = _next_seq($subscription, $pattern, $publisheddate);
264
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
265
is($seq, 'Z: 4, Y: 5, X: 1');
265
is($seq, 'Z: 4, Y: 5, X: 1');
266
266
267
267
268
$dbh->rollback;
268
$dbh->rollback;
269
269
270
sub _next_seq {
270
sub _next_seq {
271
    my ($subscription, $pattern, $publisheddate) = @_;
271
    my ($subscription, $pattern, $frequency, $publisheddate) = @_;
272
    my $seq;
272
    my $seq;
273
    ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
273
    ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
274
        $subscription->{lastvalue3}, $subscription->{innerloop1},
274
        $subscription->{lastvalue3}, $subscription->{innerloop1},
275
        $subscription->{innerloop2}, $subscription->{innerloop3}) =
275
        $subscription->{innerloop2}, $subscription->{innerloop3}) =
276
            GetNextSeq($subscription, $pattern, $publisheddate);
276
            GetNextSeq($subscription, $pattern, $frequency, $publisheddate);
277
    return $seq;
277
    return $seq;
278
}
278
}
279
- 

Return to bug 17047