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

(-)a/C4/Serials.pm (-19 / +20 lines)
Lines 829-847 sub GetPreviousSerialid { Link Here
829
    my (
829
    my (
830
        $nextseq,       $newlastvalue1, $newlastvalue2, $newlastvalue3,
830
        $nextseq,       $newlastvalue1, $newlastvalue2, $newlastvalue3,
831
        $newinnerloop1, $newinnerloop2, $newinnerloop3
831
        $newinnerloop1, $newinnerloop2, $newinnerloop3
832
    ) = GetNextSeq( $subscription, $pattern, $planneddate );
832
    ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate );
833
833
834
$subscription is a hashref containing all the attributes of the table
834
$subscription is a hashref containing all the attributes of the table
835
'subscription'.
835
'subscription'.
836
$pattern is a hashref containing all the attributes of the table
836
$pattern is a hashref containing all the attributes of the table
837
'subscription_numberpatterns'.
837
'subscription_numberpatterns'.
838
$frequency is a hashref containing all the attributes of the table 'subscription_frequencies'
838
$planneddate is a date string in iso format.
839
$planneddate is a date string in iso format.
839
This function get the next issue for the subscription given on input arg
840
This function get the next issue for the subscription given on input arg
840
841
841
=cut
842
=cut
842
843
843
sub GetNextSeq {
844
sub GetNextSeq {
844
    my ($subscription, $pattern, $planneddate) = @_;
845
    my ($subscription, $pattern, $frequency, $planneddate) = @_;
845
846
846
    return unless ($subscription and $pattern);
847
    return unless ($subscription and $pattern);
847
848
Lines 854-860 sub GetNextSeq { Link Here
854
        if(@irreg > 0) {
855
        if(@irreg > 0) {
855
            my $irregularities = {};
856
            my $irregularities = {};
856
            $irregularities->{$_} = 1 foreach(@irreg);
857
            $irregularities->{$_} = 1 foreach(@irreg);
857
            my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1;
858
            my $issueno = GetFictiveIssueNumber($subscription, $planneddate, $frequency) + 1;
858
            while($irregularities->{$issueno}) {
859
            while($irregularities->{$issueno}) {
859
                $count++;
860
                $count++;
860
                $issueno++;
861
                $issueno++;
Lines 997-1003 sub GetExpirationDate { Link Here
997
998
998
            #calculate the date of the last issue.
999
            #calculate the date of the last issue.
999
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
1000
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
1000
                $enddate = GetNextDate( $subscription, $enddate );
1001
                $enddate = GetNextDate( $subscription, $enddate, $frequency );
1001
            }
1002
            }
1002
        } elsif ( $subscription->{monthlength} ) {
1003
        } elsif ( $subscription->{monthlength} ) {
1003
            if ( $$subscription{startdate} ) {
1004
            if ( $$subscription{startdate} ) {
Lines 1149-1164 sub ModSerialStatus { Link Here
1149
    if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) {
1150
    if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) {
1150
        my $subscription = GetSubscription($subscriptionid);
1151
        my $subscription = GetSubscription($subscriptionid);
1151
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1152
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1153
        my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
1152
1154
1153
        # next issue number
1155
        # next issue number
1154
        my (
1156
        my (
1155
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1157
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1156
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1158
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1157
          )
1159
          )
1158
          = GetNextSeq( $subscription, $pattern, $publisheddate );
1160
          = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate );
1159
1161
1160
        # next date (calculated from actual date & frequency parameters)
1162
        # next date (calculated from actual date & frequency parameters)
1161
        my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1);
1163
        my $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency, 1);
1162
        my $nextpubdate = $nextpublisheddate;
1164
        my $nextpubdate = $nextpublisheddate;
1163
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1165
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1164
                    WHERE  subscriptionid = ?";
1166
                    WHERE  subscriptionid = ?";
Lines 1367-1373 sub NewSubscription { Link Here
1367
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1369
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1368
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1370
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1369
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1371
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1370
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype
1372
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1371
    ) = @_;
1373
    ) = @_;
1372
    my $dbh = C4::Context->dbh;
1374
    my $dbh = C4::Context->dbh;
1373
1375
Lines 1381-1388 sub NewSubscription { Link Here
1381
            irregularity, numberpattern, locale, callnumber,
1383
            irregularity, numberpattern, locale, callnumber,
1382
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1384
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1383
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1385
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1384
            itemtype, previousitemtype)
1386
            itemtype, previousitemtype, mana_id)
1385
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1387
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?)
1386
        |;
1388
        |;
1387
    my $sth = $dbh->prepare($query);
1389
    my $sth = $dbh->prepare($query);
1388
    $sth->execute(
1390
    $sth->execute(
Lines 1393-1399 sub NewSubscription { Link Here
1393
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1395
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1394
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1396
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1395
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1397
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1396
        $itemtype, $previousitemtype
1398
        $itemtype, $previousitemtype, $mana_id
1397
    );
1399
    );
1398
1400
1399
    my $subscriptionid = $dbh->{'mysql_insertid'};
1401
    my $subscriptionid = $dbh->{'mysql_insertid'};
Lines 2107-2113 sub abouttoexpire { Link Here
2107
        my $expirationdate = GetExpirationDate($subscriptionid);
2109
        my $expirationdate = GetExpirationDate($subscriptionid);
2108
2110
2109
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2111
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2110
        my $nextdate = GetNextDate($subscription, $res);
2112
        my $nextdate = GetNextDate($subscription, $res, $frequency);
2111
2113
2112
        # only compare dates if both dates exist.
2114
        # only compare dates if both dates exist.
2113
        if ($nextdate and $expirationdate) {
2115
        if ($nextdate and $expirationdate) {
Lines 2128-2134 sub abouttoexpire { Link Here
2128
2130
2129
=head2 GetFictiveIssueNumber
2131
=head2 GetFictiveIssueNumber
2130
2132
2131
$issueno = GetFictiveIssueNumber($subscription, $publishedate);
2133
$issueno = GetFictiveIssueNumber($subscription, $publishedate, $frequency);
2132
2134
2133
Get the position of the issue published at $publisheddate, considering the
2135
Get the position of the issue published at $publisheddate, considering the
2134
first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
2136
first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
Lines 2147-2155 date (in GetNextDate) or the next issue number (in GetNextSeq). Link Here
2147
=cut
2149
=cut
2148
2150
2149
sub GetFictiveIssueNumber {
2151
sub GetFictiveIssueNumber {
2150
    my ($subscription, $publisheddate) = @_;
2152
    my ($subscription, $publisheddate, $frequency) = @_;
2151
2153
2152
    my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'});
2153
    my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
2154
    my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
2154
    return if !$unit;
2155
    return if !$unit;
2155
    my $issueno;
2156
    my $issueno;
Lines 2293-2304 sub _get_next_date_year { Link Here
2293
2294
2294
=head2 GetNextDate
2295
=head2 GetNextDate
2295
2296
2296
$resultdate = GetNextDate($publisheddate,$subscription)
2297
$resultdate = GetNextDate($publisheddate,$subscription,$freqdata,$updatecount)
2297
2298
2298
this function it takes the publisheddate and will return the next issue's date
2299
this function it takes the publisheddate and will return the next issue's date
2299
and will skip dates if there exists an irregularity.
2300
and will skip dates if there exists an irregularity.
2300
$publisheddate has to be an ISO date
2301
$publisheddate has to be an ISO date
2301
$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit'
2302
$subscription is a hashref containing at least 'firstacquidate', 'irregularity', and 'countissuesperunit'
2303
$frequency is a hashref containing frequency informations
2302
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2304
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2303
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2305
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2304
skipped then the returned date will be 2007-05-10
2306
skipped then the returned date will be 2007-05-10
Lines 2311-2321 Return undef if subscription is irregular Link Here
2311
=cut
2313
=cut
2312
2314
2313
sub GetNextDate {
2315
sub GetNextDate {
2314
    my ( $subscription, $publisheddate, $updatecount ) = @_;
2316
    my ( $subscription, $publisheddate, $freqdata, $updatecount ) = @_;
2315
2317
2316
    return unless $subscription and $publisheddate;
2318
    return unless $subscription and $publisheddate;
2317
2319
2318
    my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'});
2319
2320
2320
    if ($freqdata->{'unit'}) {
2321
    if ($freqdata->{'unit'}) {
2321
        my ( $year, $month, $day ) = split /-/, $publisheddate;
2322
        my ( $year, $month, $day ) = split /-/, $publisheddate;
Lines 2335-2341 sub GetNextDate { Link Here
2335
2336
2336
        # Get the 'fictive' next issue number
2337
        # Get the 'fictive' next issue number
2337
        # It is used to check if next issue is an irregular issue.
2338
        # It is used to check if next issue is an irregular issue.
2338
        my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1;
2339
        my $issueno = GetFictiveIssueNumber($subscription, $publisheddate, $freqdata) + 1;
2339
2340
2340
        # Then get the next date
2341
        # Then get the next date
2341
        my $unit = lc $freqdata->{'unit'};
2342
        my $unit = lc $freqdata->{'unit'};
(-)a/Koha/SharedContent.pm (+90 lines)
Line 0 Link Here
1
package Koha::SharedContent;
2
3
# Copyright 2016 BibLibre Morgane Alonso
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use JSON;
22
use HTTP::Request;
23
use LWP::UserAgent;
24
25
our $MANA_IP = "http://10.25.159.107:5000";
26
27
sub manaRequest {
28
    my $mana_request = shift;
29
    my $result;
30
31
    $mana_request->content_type('application/json');
32
    my $userAgent = LWP::UserAgent->new;
33
    my $response  = $userAgent->request($mana_request);
34
35
    if ( $response->code ne "204" ) {
36
        $result = from_json( $response->decoded_content );
37
    }
38
    $result->{code} = $response->code;
39
40
    return $result if ( $response->code =~ /^2..$/ );
41
}
42
43
sub manaNewUserPatchRequest {
44
    my $resource = shift;
45
    my $id       = shift;
46
47
    my $url = "$MANA_IP/$resource/$id.json/newUser";
48
    my $request = HTTP::Request->new( PATCH => $url );
49
50
    return manaRequest($request);
51
}
52
53
sub manaPostRequest {
54
    my $resource = shift;
55
    my $content  = shift;
56
57
    my $url = "$MANA_IP/$resource.json";
58
    my $request = HTTP::Request->new( POST => $url );
59
60
    $content->{bulk_import} = 0;
61
    my $json = to_json( $content, { utf8 => 1 } );
62
    $request->content($json);
63
64
    return manaRequest($request);
65
}
66
67
sub manaGetRequestWithId {
68
    my $resource = shift;
69
    my $id       = shift;
70
71
    my $url = "$MANA_IP/$resource/$id.json";
72
    my $request = HTTP::Request->new( GET => $url );
73
74
    return manaRequest($request);
75
}
76
77
sub manaGetRequest {
78
    my $resource   = shift;
79
    my $parameters = shift;
80
81
    $parameters = join '&',
82
      map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () }
83
      keys %$parameters;
84
    my $url = "$MANA_IP/$resource.json?$parameters";
85
    my $request = HTTP::Request->new( GET => $url );
86
87
    return manaRequest($request);
88
}
89
90
1;
(-)a/Koha/Subscription.pm (+64 lines)
Lines 24-30 use Carp; Link Here
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Biblios;
25
use Koha::Biblios;
26
use Koha::Acquisition::Booksellers;
26
use Koha::Acquisition::Booksellers;
27
use Koha::Biblioitems;
28
use Koha::Subscriptions;
27
use Koha::Subscription::Frequencies;
29
use Koha::Subscription::Frequencies;
30
use Koha::Subscription::Numberpatterns;
31
use JSON;
28
32
29
use base qw(Koha::Object);
33
use base qw(Koha::Object);
30
34
Lines 125-130 sub frequency { Link Here
125
129
126
=cut
130
=cut
127
131
132
sub get_search_info {
133
    my $searched_sub_id = shift;
134
    my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } );
135
    my $biblioitem =
136
      Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } );
137
138
    my $sub_mana_info = {
139
        'title'         => $biblio->title,
140
        'issn'          => $biblioitem->issn,
141
        'ean'           => $biblioitem->ean,
142
        'publishercode' => $biblioitem->publishercode
143
    };
144
    return $sub_mana_info;
145
}
146
147
sub get_sharable_info {
148
    my $shared_sub_id = shift;
149
    my $subscription  = Koha::Subscriptions->find($shared_sub_id);
150
    my $biblio        = Koha::Biblios->find( $subscription->biblionumber );
151
    my $biblioitem    = Koha::Biblioitems->find(
152
        { 'biblionumber' => $subscription->biblionumber } );
153
    my $sub_frequency =
154
      Koha::Subscription::Frequencies->find( $subscription->periodicity );
155
    my $sub_numberpatteern =
156
      Koha::Subscription::Numberpatterns->find( $subscription->numberpattern );
157
158
    my $sub_mana_info = {
159
        'title'           => $biblio->title,
160
        'sfdescription'   => $sub_frequency->description,
161
        'unit'            => $sub_frequency->unit,
162
        'unitsperissue'   => $sub_frequency->unitsperissue,
163
        'issuesperunit'   => $sub_frequency->issuesperunit,
164
        'label'           => $sub_numberpatteern->label,
165
        'sndescription'   => $sub_numberpatteern->description,
166
        'numberingmethod' => $sub_numberpatteern->numberingmethod,
167
        'label1'          => $sub_numberpatteern->label1,
168
        'add1'            => $sub_numberpatteern->add1,
169
        'every1'          => $sub_numberpatteern->every1,
170
        'whenmorethan1'   => $sub_numberpatteern->whenmorethan1,
171
        'setto1'          => $sub_numberpatteern->setto1,
172
        'numbering1'      => $sub_numberpatteern->numbering1,
173
        'label2'          => $sub_numberpatteern->label2,
174
        'add2'            => $sub_numberpatteern->add2,
175
        'every2'          => $sub_numberpatteern->every2,
176
        'whenmorethan2'   => $sub_numberpatteern->whenmorethan2,
177
        'setto2'          => $sub_numberpatteern->setto2,
178
        'numbering2'      => $sub_numberpatteern->numbering2,
179
        'label3'          => $sub_numberpatteern->label3,
180
        'add3'            => $sub_numberpatteern->add3,
181
        'every3'          => $sub_numberpatteern->every3,
182
        'whenmorethan3'   => $sub_numberpatteern->whenmorethan3,
183
        'setto3'          => $sub_numberpatteern->setto3,
184
        'numbering3'      => $sub_numberpatteern->numbering3,
185
        'issn'            => $biblioitem->issn,
186
        'ean'             => $biblioitem->ean,
187
        'publishercode'   => $biblioitem->publishercode
188
    };
189
    return $sub_mana_info;
190
}
191
128
sub _type {
192
sub _type {
129
    return 'Subscription';
193
    return 'Subscription';
130
}
194
}
(-)a/Koha/Subscription/Frequencies.pm (+4 lines)
Lines 43-48 sub _type { Link Here
43
    return 'SubscriptionFrequency';
43
    return 'SubscriptionFrequency';
44
}
44
}
45
45
46
=head3 object_class
47
48
=cut
49
46
sub object_class {
50
sub object_class {
47
    return 'Koha::Subscription::Frequency';
51
    return 'Koha::Subscription::Frequency';
48
}
52
}
(-)a/Koha/Subscription/Frequency.pm (+4 lines)
Lines 25-31 use base qw(Koha::Object); Link Here
25
25
26
=head1 NAME
26
=head1 NAME
27
27
28
<<<<<<< b4c9007cc708d995838eae801a5a24b47435095e
28
Koha::Subscription::Frequency - Koha Subscription Frequency Object class
29
Koha::Subscription::Frequency - Koha Subscription Frequency Object class
30
=======
31
Koha::Subscription::Frequency - Koha Subscription::Frequency Object class
32
>>>>>>> Bug 17047 subscriptions management with Mana-KB
29
33
30
=head1 API
34
=head1 API
31
35
(-)a/Koha/Subscription/Numberpattern.pm (+48 lines)
Line 0 Link Here
1
package Koha::Subscription::Numberpattern;
2
3
# Copyright 2016 BibLibre Morgane Alonso
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use Koha::Database;
22
use base qw(Koha::Object);
23
24
=head1 NAME
25
26
Koha::SubscriptionNumberpattern - Koha SubscriptionNumberpattern Object class
27
28
=head1 API
29
30
=head2 Class Methods
31
32
=cut
33
34
=head3 type
35
36
=cut
37
38
sub _type {
39
    return 'SubscriptionNumberpattern';
40
}
41
42
=head1 AUTHOR
43
44
Morgane Alonso <morgane.alonso@biblibre.com>
45
46
=cut
47
48
1;
(-)a/Koha/Subscription/Numberpatterns.pm (+77 lines)
Line 0 Link Here
1
package Koha::Subscription::Numberpatterns;
2
3
# Copyright 2016 BibLibre Morgane Alonso
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use Koha::Database;
22
use Koha::Subscription::Numberpattern;
23
use base qw(Koha::Objects);
24
25
=head1 NAME
26
27
Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set class
28
29
=head1 API
30
31
=head2 Class Methods
32
33
=cut
34
35
=head3 uniqeLabel
36
37
=cut
38
39
sub uniqueLabel {
40
    my ($self, $label) = @_;
41
42
    my $samelabel = Koha::Subscription::Numberpatterns->search({label => $label})->next();
43
    if ($samelabel) {
44
        my $i = 2;
45
        my $newlabel = $samelabel->label . " ($i)";
46
        while (my $othersamelabel = $self->search({label => $newlabel})->next()) {
47
            $i++;
48
            $newlabel = $samelabel->label . " ($i)";
49
        }
50
        $label = $newlabel;
51
    }
52
    return $label;
53
}
54
55
=head3 type
56
57
=cut
58
59
sub _type {
60
    return 'SubscriptionNumberpattern';
61
}
62
63
=head3 object_class
64
65
=cut
66
67
sub object_class {
68
    return 'Koha::Subscription::Numberpattern';
69
}
70
71
=head1 AUTHOR
72
73
Morgane Alonso <morgane.alonso@biblibre.com>
74
75
=cut
76
77
1;
(-)a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE subscription ADD mana_id int(11);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc (+46 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
<table id="mana_results_datatable">
3
    <thead>
4
        <tr>
5
            <th>ISSN</th>
6
            <th class="anti-the">Title</th>
7
            <th>Frequency</th>
8
            <th>Numbering pattern</th>
9
            <th class="NoSort">Number of users</th>
10
            <th class="title-string">Last Import</th>
11
            [% UNLESS search_only %]
12
              <th class="NoSort">Actions</th>
13
            [% END %]
14
        </tr>
15
    </thead>
16
    <tfoot>
17
        <tr>
18
            <td><input type="text" class="dt-filter" data-column_num="0" placeholder="Search ISSN" /></td>
19
            <td><input type="text" class="dt-filter" data-column_num="1" placeholder="Search title" /></td>
20
            <td><input type="text" class="dt-filter" data-column_num="2" placeholder="Search frequency" /></td>
21
            <td><input type="text" class="dt-filter" data-column_num="3" placeholder="Search numbering pattern" /></td>
22
            <td></td>
23
            <td><input type="text" class="dt-filter" data-column_num="5" placeholder="Search last import" /></td>
24
            [% UNLESS search_only %]
25
              <td></td>
26
            [% END %]
27
        </tr>
28
    </tfoot>
29
    <tbody>
30
        [% FOREACH subscription IN subscriptions %]
31
            [% UNLESS subscription.cannotdisplay %]
32
                <tr id="row[% subscription.subscriptionid %]">
33
                    <td>[% IF ( subscription.issn ) %][% subscription.issn %][% END %]</td>
34
                    <td>[% subscription.title %]</a></td>
35
                    <td>[% IF ( subscription.sfdescription ) %][% subscription.sfdescription %][% END %]</td>
36
                    <td>[% IF ( subscription.numberingmethod ) %][% subscription.numberingmethod %][% END %]</td>
37
                    <td>[% IF ( subscription.nbofusers ) %][% subscription.nbofusers %][% END %]</td>
38
                    <td><span title="[% subscription.lastimport %]">[% subscription.lastimport | $KohaDates %]</span></td>
39
                    [% UNLESS search_only %]
40
                      <td><a style="cursor:pointer" onclick="mana_use([% subscription.id %])"> <i class="fa fa-inbox"></i> Use</a></td>
41
                    [% END %]
42
                </tr>
43
            [% END %]
44
        [% END %]
45
    </tbody>
46
</table>
(-)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 (+105 lines)
Lines 7-12 Link Here
7
            [% ELSE %]
7
            [% ELSE %]
8
                <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>
8
                <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>
9
            [% END %]
9
            [% END %]
10
            [% IF Koha.Preference('Mana') %]
11
                [% IF one_language_enabled==0 or mana_id %]
12
                    <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>
13
                [% ELSE %]
14
                    <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>
15
                [% END %]
16
            [% END %]
10
        [% END %]
17
        [% END %]
11
18
12
        [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %]
19
        [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %]
Lines 63-65 Link Here
63
        [% END %]
70
        [% END %]
64
    </div>
71
    </div>
65
[% END %]
72
[% END %]
73
74
<div id="mana_share_modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mana_share_modal_label" style="display: none;">
75
    <div class="modal-dialog">
76
        <div class="modal-content">
77
            <div class="modal-header">
78
                <h3 id="mana_share_modal_label">Share [% bibliotitle %] to Mana</h3>
79
            </div>
80
            <div class="modal-body">
81
                [% IF (mana_id) %]
82
                    <div class="alert">
83
                        <p>Your subscription is already linked with a Mana subscription model. Share it if you have made modifications, otherwide it will do nothing.</p>
84
                    </div>
85
                [% END %]
86
                [% IF ( languages_loop ) %]
87
                    [% UNLESS ( one_language_enabled ) %]
88
                        <div class="rows">
89
                            <p>The frequency and the numberpattern of [% bibliotitle %] are :</p>
90
                            <ol>
91
                                <li><span class="label">Frequency : </span>
92
                                        [% frequency.description %]
93
                                </li>
94
                                <li><span class="label">Number pattern : </span>
95
                                    [% numberpattern.label %]
96
                                </li>
97
                            </ol>
98
                        </div>
99
                        <div class="rows">
100
                            <form method="get" id="mana_share_form" action="/cgi-bin/koha/serials/subscription-detail.pl" class="validated" >
101
                                <fieldset>
102
                                    <label for="mana_language">Language of your sharing :</label>
103
                                    <select id="mana_language" name="mana_language">
104
                                        [% FOREACH languages_loo IN languages_loop %]
105
                                            [% IF ( languages_loo.group_enabled ) %]
106
                                                [% IF ( languages_loo.plural ) %]
107
                                                    [% FOREACH sublanguages_loo IN languages_loo.sublanguages_loop %]
108
                                                        [% IF ( sublanguages_loo.enabled ) %]
109
                                                            [% IF ( sublanguages_loo.sublanguage_current ) %]
110
                                                                <option value="[% languages_loo.rfc4646_subtag %]" selected>
111
                                                                    [% sublanguages_loo.native_description %]
112
                                                                    [% sublanguages_loo.script_description %]
113
                                                                    [% sublanguages_loo.region_description %]
114
                                                                    [% sublanguages_loo.variant_description %]
115
                                                                    ([% sublanguages_loo.rfc4646_subtag %])
116
                                                                </option>
117
                                                            [% ELSE %]
118
                                                                <option value="[% languages_loo.rfc4646_subtag %]">
119
                                                                    [% sublanguages_loo.native_description %]
120
                                                                    [% sublanguages_loo.script_description %]
121
                                                                    [% sublanguages_loo.region_description %]
122
                                                                    [% sublanguages_loo.variant_description %]
123
                                                                    ([% sublanguages_loo.rfc4646_subtag %])
124
                                                                </option>
125
                                                            [% END %]
126
                                                        [% END %]
127
                                                    [% END %]
128
                                                [% ELSE %]
129
                                                    [% IF ( languages_loo.group_enabled ) %]
130
                                                        [% IF ( languages_loo.current ) %]
131
                                                            <option value="[% languages_loo.rfc4646_subtag %]" selected>
132
                                                                [% IF ( languages_loo.native_description ) %]
133
                                                                    [% languages_loo.native_description %]
134
                                                                [% ELSE %]
135
                                                                    [% languages_loo.rfc4646_subtag %]
136
                                                                [% END %]
137
                                                            </option>
138
                                                        [% ELSE %]
139
                                                            <option value="[% languages_loo.rfc4646_subtag %]">
140
                                                                [% IF ( languages_loo.native_description ) %]
141
                                                                    [% languages_loo.native_description %]
142
                                                                [% ELSE %]
143
                                                                    [% languages_loo.rfc4646_subtag %]
144
                                                                [% END %]
145
                                                            </option>
146
                                                        [% END %]
147
                                                    [% END %]
148
                                                [% END %]
149
                                            [% END %]
150
                                        [% END %]
151
                                    </select>
152
                                    <input type="hidden" id="op" name="op" value="share"/>
153
                                    <input type="hidden" id="subscriptionid" name="subscriptionid" value="[% subscriptionid %]"/>
154
                                </fieldset>
155
                            </form>
156
                        </div>
157
                    [% END %]
158
                [% END %]
159
            </div>
160
            <div class="modal-footer">
161
                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
162
                [% IF one_language_enabled==0 %]
163
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
164
                [% ELSE %]
165
                    <div class="btn-group"><a class="btn btn-primary" onclick="share()">Share</a></div>
166
                [% END %]
167
            </div>
168
        </div>
169
    </div>
170
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt (+1 lines)
Line 0 Link Here
1
[% INCLUDE 'mana-subscription-search-result.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt (+1 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE KohaDates %]
3
[% USE KohaDates %]
4
[% USE Koha %]
4
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Serials [% biblionumber | html %]</title>
7
<title>Koha &rsaquo; Serials [% biblionumber | html %]</title>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt (-4 / +38 lines)
Lines 4-9 Link Here
4
[% USE Branches %]
4
[% USE Branches %]
5
[% USE CGI %]
5
[% USE CGI %]
6
[% USE KohaDates %]
6
[% USE KohaDates %]
7
[% USE Koha %]
7
[% SET footerjs = 1 %]
8
[% SET footerjs = 1 %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
9
<title>Koha &rsaquo; Serials [% biblionumber | html %]</title>
10
<title>Koha &rsaquo; Serials [% biblionumber | html %]</title>
Lines 275-280 Link Here
275
                [% END %]
276
                [% END %]
276
              </ol>
277
              </ol>
277
              <input type="hidden" name="searched" value="1" />
278
              <input type="hidden" name="searched" value="1" />
279
              [% IF ( mana ) %]<input type="hidden" name="mana" value="1" />[% END %]
278
              <fieldset class="action">
280
              <fieldset class="action">
279
                <input type="submit" value="Search" />
281
                <input type="submit" value="Search" />
280
              </fieldset>
282
              </fieldset>
Lines 286-294 Link Here
286
        [% IF ( total ) %]
288
        [% IF ( total ) %]
287
          <div id="serialstabs" class="toptabs" style="clear:both;">
289
          <div id="serialstabs" class="toptabs" style="clear:both;">
288
            <ul class="ui-tabs-nav">
290
            <ul class="ui-tabs-nav">
289
              <li><a href="#opened">Open ([% openedsubscriptions.size || 0 | html %])</a></li>
291
              [% IF mana %]
290
              <li><a href="#closed">Closed ([% closedsubscriptions.size || 0 | html %])</a></li>
292
                <li><a href="#mana">Mana ([% total || 0 | html %])</a></li>
293
              [% ELSE %]
294
                <li><a href="#opened">Open ([% openedsubscriptions.size || 0 | html %])</a></li>
295
                <li><a href="#closed">Closed ([% closedsubscriptions.size || 0 | html %])</a></li>
296
              [% END %]
291
            </ul>
297
            </ul>
298
            [% IF mana %]
299
                <div id="mana">
300
                    [% INCLUDE 'mana-subscription-search-result.inc' %]
301
                </div>
302
            [% ELSE %]
292
            <div id="opened">
303
            <div id="opened">
293
              [% IF openedsubscriptions %]
304
              [% IF openedsubscriptions %]
294
                  [% INCLUDE subscriptions_table subscriptions = openedsubscriptions %]
305
                  [% INCLUDE subscriptions_table subscriptions = openedsubscriptions %]
Lines 307-312 Link Here
307
                </div>
318
                </div>
308
              [% END %]
319
              [% END %]
309
            </div>
320
            </div>
321
            [% END %]
310
          </div>
322
          </div>
311
        [% ELSE %]
323
        [% ELSE %]
312
            <div class="dialog message">
324
            <div class="dialog message">
Lines 323-328 Link Here
323
335
324
    [% INCLUDE 'serials-menu.inc' %]
336
    [% INCLUDE 'serials-menu.inc' %]
325
    [% IF ( done_searched ) %]
337
    [% IF ( done_searched ) %]
338
    [% UNLESS ( mana ) %]
326
    <div id="advsearch">
339
    <div id="advsearch">
327
        <form action="/cgi-bin/koha/serials/serials-search.pl" method="get">
340
        <form action="/cgi-bin/koha/serials/serials-search.pl" method="get">
328
          <fieldset class="brief">
341
          <fieldset class="brief">
Lines 395-410 Link Here
395
              <fieldset class="action">
408
              <fieldset class="action">
396
                <input type="submit" value="Search" />
409
                <input type="submit" value="Search" />
397
              </fieldset>
410
              </fieldset>
411
398
            </div>
412
            </div>
399
          </fieldset>
413
          </fieldset>
400
        </form>
414
        </form>
401
      [% END %]
415
      [% END %]
402
416
      [% END %]
403
            </aside>
417
            </aside>
404
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
418
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
405
     </div> <!-- /.row -->
419
     </div> <!-- /.row -->
406
420
407
408
[% MACRO jsinclude BLOCK %]
421
[% MACRO jsinclude BLOCK %]
409
    [% INCLUDE 'calendar.inc' %]
422
    [% INCLUDE 'calendar.inc' %]
410
    [% INCLUDE 'datatables.inc' %]
423
    [% INCLUDE 'datatables.inc' %]
Lines 461-468 Link Here
461
                ]
474
                ]
462
            }));
475
            }));
463
476
477
            var manarlt = $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
478
                "sPaginationType": "four_button",
479
                "aoColumnDefs": [
480
                    { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
481
                    { "sType": "title-string", "aTargets" : [ "title-string" ] },
482
                    { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
483
                ]
484
            }));
485
464
            osrlt.fnAddFilters("dt-filter", 750);
486
            osrlt.fnAddFilters("dt-filter", 750);
465
            csrlt.fnAddFilters("dt-filter", 750);
487
            csrlt.fnAddFilters("dt-filter", 750);
488
            manarlt.fnAddFilters("dt-filter", 750);
466
489
467
            $('#serialstabs').tabs();
490
            $('#serialstabs').tabs();
468
            $("#reopensub").click(function(){
491
            $("#reopensub").click(function(){
Lines 484-489 Link Here
484
                itemSelectionBuildActionLinks(div);
507
                itemSelectionBuildActionLinks(div);
485
            });
508
            });
486
509
510
            [% IF ( mana ) %]
511
                $("label[for=callnumber], input#callnumber").hide();
512
                $("label[for=bookseller], input#bookseller").hide();
513
                $("label[for=branch], select#branch").hide();
514
                $("label[for=to], input#to").hide();
515
                $(".ui-datepicker-trigger").hide();
516
                $("label[for=location], select#location_filter").hide();
517
                [% FOR field IN additional_fields_for_subscription %]
518
                      $("label[for=additional_field_[% field.id %]], input#additional_field_[% field.id %]").hide();
519
                [% END %]
520
            [% END %]
487
        });
521
        });
488
    </script>
522
    </script>
489
[% END %]
523
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-1 / +25 lines)
Lines 2-7 Link Here
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE KohaDates %]
3
[% USE KohaDates %]
4
[% USE Branches %]
4
[% USE Branches %]
5
[% USE Koha %]
5
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle | html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
8
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle | html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
Lines 213-218 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ Link Here
213
214
214
                <div id="page_2">
215
                <div id="page_2">
215
                    <div class="col-md-6">
216
                    <div class="col-md-6">
217
                        <div id="mana_search" class="dialog message">
218
                            <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>
219
                        </div>
216
                        <div id="subscription_form_planning">
220
                        <div id="subscription_form_planning">
217
                            <fieldset class="rows">
221
                            <fieldset class="rows">
218
                                <legend>Serials planning</legend>
222
                                <legend>Serials planning</legend>
Lines 477-486 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ Link Here
477
                              </div>
481
                              </div>
478
                            [% END %]
482
                            [% END %]
479
483
484
                            <input type="hidden" id="mana_id"  name="mana_id" value=""/>
485
                            <input type="hidden" id="sndescription"  name="sndescription" value=""/>
486
                            <input type="hidden" id="sfdescription"  name="sfdescription" value=""/>
487
                            <input type="hidden" id="unit"  name="unit" value=""/>
488
                            <input type="hidden" id="unitsperissue"  name="unitsperissue" value=""/>
489
                            <input type="hidden" id="issuesperunit"  name="issuesperunit" value=""/>
480
                            <fieldset class="action">
490
                            <fieldset class="action">
481
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
491
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
482
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
492
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
483
                                <input type="submit" value="Save subscription" style="float:right;" accesskey="w" />
493
                                <input type="submit" onclick="removeDisabledAttr()" value="Save subscription" style="float:right;" accesskey="w"/>
484
                            </fieldset>
494
                            </fieldset>
485
                        </div>
495
                        </div>
486
                    </div>
496
                    </div>
Lines 490-495 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ Link Here
490
                </div>
500
                </div>
491
            </form>
501
            </form>
492
        </div>
502
        </div>
503
        <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;">
504
            <div class="modal-dialog modal-lg">
505
                <div class="modal-content">
506
                    <div class="modal-header">
507
                        <h3 id="mana_search_result_label"></h3>
508
                    </div>
509
                    <div class="modal-body">
510
                    </div>
511
                    <div class="modal-footer">
512
                        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
513
                    </div>
514
                </div>
515
            </div>
516
        </div>
493
517
494
[% MACRO jsinclude BLOCK %]
518
[% MACRO jsinclude BLOCK %]
495
    [% INCLUDE 'calendar.inc' %]
519
    [% INCLUDE 'calendar.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-2 / +13 lines)
Lines 29-35 Link Here
29
        <div class="col-sm-10 col-sm-push-2">
29
        <div class="col-sm-10 col-sm-push-2">
30
            <main>
30
            <main>
31
31
32
	[% INCLUDE 'serials-toolbar.inc' %]
32
    [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]
33
33
34
    <h1>Subscription for [% bibliotitle | html %] [% IF closed %](closed)[% END %]</h1>
34
    <h1>Subscription for [% bibliotitle | html %] [% IF closed %](closed)[% END %]</h1>
35
    [% IF ( abouttoexpire ) %]
35
    [% IF ( abouttoexpire ) %]
Lines 58-64 Link Here
58
			</form>
58
			</form>
59
59
60
	</div>
60
	</div>
61
	[% END %] <!-- NEEDSCONFIRMATION -->
61
    [% END %] <!-- NEEDSCONFIRMATION -->
62
    [% IF mana_code.defined %]
63
        <div id="alert-community" class="dialog message">
64
            <p>
65
                [% IF (mana_code == 201) %]
66
                    The export is done, thank you for your contribution.
67
                [% ELSIF (mana_code == 200) %]
68
                    The model already exists on Mana, thank you for your contribution.
69
                [% END %]
70
            </p>
71
        </div>
72
    [% END %]
62
73
63
<div id="subscription_description" class="toptabs">
74
<div id="subscription_description" class="toptabs">
64
<ul class="ui-tabs-nav">
75
<ul class="ui-tabs-nav">
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js (-22 / +162 lines)
Lines 2-7 Link Here
2
2
3
var globalnumpatterndata;
3
var globalnumpatterndata;
4
var globalfreqdata;
4
var globalfreqdata;
5
var mananumpatterndata;
6
var manafreqdata;
7
var manaid;
5
var advancedpatternlocked;
8
var advancedpatternlocked;
6
var patternneedtobetested = 0;
9
var patternneedtobetested = 0;
7
if ( irregularity !== "" ){
10
if ( irregularity !== "" ){
Lines 85-115 function Check_page2(){ Link Here
85
}
88
}
86
89
87
function frequencyload(){
90
function frequencyload(){
88
    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
91
    if ($("#frequency option:selected").val() === "mana"){
89
        function(freqdata){
92
        globalfreqdata=manafreqdata;
90
            globalfreqdata=freqdata;
93
        $("input[name='sfdescription']").val(manafreqdata.description);
91
            if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
94
        $("input[name='unit']").val(manafreqdata.unit);
92
                var option = $("#subtype option[value='issues']");
95
        $("input[name='unitsperissue']").val(manafreqdata.unitsperissue);
93
                $(option).attr('selected', 'selected');
96
        $("input[name='issuesperunit']").val(manafreqdata.issuesperunit);
94
                $("#subtype option[value!='issues']").prop('disabled', true)
97
        if ($( "#numberpattern option:selected" ).val() === "mana" ) {
95
            } else {
98
            $("input[name='mana_id']").val(manaid);
96
                $("#subtype option").prop('disabled', false)
97
            }
98
        }
99
        }
99
    )
100
    } else {
101
        $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
102
            function(freqdata){
103
                globalfreqdata=freqdata;
104
                if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
105
                    var option = $("#subtype option[value='issues']");
106
                    $(option).attr('selected', 'selected');
107
                    $("#subtype option[value!='issues']").prop('disabled', true);
108
                } else {
109
                    $("#subtype option").prop('disabled', false);
110
                }
111
            }
112
        );
113
        $("input[name='mana_id']").val("");
114
    }
100
}
115
}
101
116
102
function numberpatternload(){
117
function numberpatternload(){
103
    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
118
    if($("#numberpattern option:selected" ).val() === "mana"){
104
        function(numpatterndata){
119
        globalnumpatterndata=mananumpatterndata;
105
            globalnumpatterndata=numpatterndata;
120
        $("input[name='sndescription']").val(mananumpatterndata.description);
106
            if (globalnumpatterndata==undefined){
121
        if($("#frequency option:selected" ).val() === "mana"){
107
                return false;
122
            $("input[name='mana_id']").val(manaid);
108
            }
109
            displaymoreoptions();
110
            restoreAdvancedPattern();
111
        }
123
        }
112
    );
124
        if (globalnumpatterndata==undefined){
125
            return false;
126
        }
127
        displaymoreoptions();
128
        restoreAdvancedPattern();
129
    } else {
130
        $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
131
            function(numpatterndata){
132
                globalnumpatterndata=numpatterndata;
133
                if (globalnumpatterndata==undefined){
134
                    return false;
135
                }
136
                displaymoreoptions();
137
                restoreAdvancedPattern();
138
            }
139
        );
140
        $("input[name='mana_id']").val("");
141
    }
113
}
142
}
114
143
115
function displaymoreoptions() {
144
function displaymoreoptions() {
Lines 275-281 function testPredictionPattern() { Link Here
275
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
304
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
276
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
305
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
277
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
306
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
278
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
307
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale',
308
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
279
    ];
309
    ];
280
    for(i in ajaxParams) {
310
    for(i in ajaxParams) {
281
        var param = ajaxParams[i];
311
        var param = ajaxParams[i];
Lines 288-294 function testPredictionPattern() { Link Here
288
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
318
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
289
        data: ajaxData,
319
        data: ajaxData,
290
        success: function(data) {
320
        success: function(data) {
291
            $("#displayexample").html(data);
321
            $("#displayexample").html(data).show();
292
            patternneedtobetested = 0;
322
            patternneedtobetested = 0;
293
        }
323
        }
294
    });
324
    });
Lines 362-369 function show_page_2() { Link Here
362
    displaymoreoptions();
392
    displaymoreoptions();
363
}
393
}
364
394
395
function mana_search() {
396
    $.ajax({
397
        type: "POST",
398
        url: "/cgi-bin/koha/svc/mana/search",
399
        data: {biblionumber : $("#biblionumber").val()},
400
        dataType: "html",
401
    })
402
    .done( function( result ) {
403
    $("#mana_search_result .modal-body").html(result);
404
        $("#mana_search_result_label").text("Results from Mana");
405
        $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
406
            "sPaginationType": "four_button",
407
            "aoColumnDefs": [
408
                { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
409
                { "sType": "title-string", "aTargets" : [ "title-string" ] },
410
                { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
411
            ]
412
        }));
413
        if($("td.dataTables_empty").length == 0){
414
            $("#mana_search").show();
415
        }
416
    }).fail(function(result){
417
    });
418
}
419
420
function mana_use(mana_id){
421
    $("tr").removeClass("selected");
422
    $("#row"+mana_id).addClass("selected");
423
    $.ajax( {
424
        type: "POST",
425
        url: "/cgi-bin/koha/svc/mana/use",
426
        data: {id : mana_id},
427
        dataType: "json",
428
    })
429
    .done(function(result){
430
        var select = document.getElementById('numberpattern');
431
        for(i = 0; i < select.length; i++){
432
            if(select[i].value === "mana"){
433
                select.remove(i);
434
            }
435
        }
436
        var optionnumpattern = document.createElement("option");
437
        optionnumpattern.text = result.label + " (mana)";
438
        optionnumpattern.selected = true;
439
        optionnumpattern.value="mana";
440
        select.add(optionnumpattern);
441
442
        mananumpatterndata = {
443
            id:"mana",
444
            add1:result.add1,
445
            add2:result.add2,
446
            add3:result.add3,
447
            description:result.sndescription,
448
            displayorder:result.displayorder,
449
            every1:result.every1,
450
            every2:result.every2,
451
            every3:result.every3,
452
            label:result.label,
453
            label1:result.label1,
454
            label2:result.label2,
455
            label3:result.label3,
456
            numbering1:result.numbering1,
457
            numbering2:result.numbering2,
458
            numbering3:result.numbering3,
459
            numberingmethod:result.numberingmethod,
460
            setto1:result.setto1,
461
            setto2:result.setto2,
462
            setto3:result.setto3,
463
            whenmorethan1:result.whenmorethan1,
464
            whenmorethan2:result.whenmorethan2,
465
            whenmorethan3:result.whenmorethan3,
466
        };
467
        select = document.getElementById("frequency");
468
        for(i = 0; i < select.length; i++){
469
            if(select[i].value === "mana"){
470
                select.remove(i);
471
            }
472
        }
473
        var optionfreq = document.createElement("option");
474
        optionfreq.text = result.sfdescription + " (mana)";
475
        optionfreq.selected = true;
476
        optionfreq.value="mana";
477
        select.add(optionfreq);
478
        manafreqdata = {
479
            id:"mana",
480
            description:result.sfdescription,
481
            displayorder:result.displayorder,
482
            issuesperunit:result.issuesperunit,
483
            unit:result.unit,
484
            unitsperissue:result.unitsperissue,
485
        };
486
        manaid = result.id;
487
        $("input[name='mana_id']").val(manaid);
488
        $("#mana_search_result").modal("hide");
489
        frequencyload();
490
        numberpatternload();
491
    }).fail( function( result ){
492
    });
493
}
494
495
function removeDisabledAttr() {
496
    $('select:disabled').removeAttr('disabled');
497
}
365
498
366
$(document).ready(function() {
499
$(document).ready(function() {
500
    $("#displayexample").hide();
501
    $("#mana_search_result").modal("hide");
367
    $("#aqbooksellerid").on('keypress', function(e) {
502
    $("#aqbooksellerid").on('keypress', function(e) {
368
        if (e.keyCode == 13) {
503
        if (e.keyCode == 13) {
369
            e.preventDefault();
504
            e.preventDefault();
Lines 447-452 $(document).ready(function() { Link Here
447
        });
582
        });
448
    }
583
    }
449
584
585
    $("#mana_search").hide();
586
450
    show_page_1();
587
    show_page_1();
451
    $("#subscription_add_form").on("submit",function(){
588
    $("#subscription_add_form").on("submit",function(){
452
        return Check_page2();
589
        return Check_page2();
Lines 469-474 $(document).ready(function() { Link Here
469
    });
606
    });
470
    $("#subscription_add_next").on("click",function(){
607
    $("#subscription_add_next").on("click",function(){
471
        if ( Check_page1() ){
608
        if ( Check_page1() ){
609
            [% IF Koha.Preference('Mana') %]
610
                mana_search();
611
            [% END %]
472
            show_page_2();
612
            show_page_2();
473
        }
613
        }
474
    });
614
    });
(-)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 77-90 if($op eq 'gennext' && @subscriptionid){ Link Here
77
            require C4::Serials::Numberpattern;
77
            require C4::Serials::Numberpattern;
78
            my $subscription = GetSubscription($subscriptionid);
78
            my $subscription = GetSubscription($subscriptionid);
79
            my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
79
            my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
80
            my $frequency = C4::Serials::Frequency::GetSubscriptionFrequencies($subscription->{periodicity});
80
            my $expected = GetNextExpected($subscriptionid);
81
            my $expected = GetNextExpected($subscriptionid);
81
            my (
82
            my (
82
                 $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
83
                 $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
83
                 $newinnerloop1, $newinnerloop2, $newinnerloop3
84
                 $newinnerloop1, $newinnerloop2, $newinnerloop3
84
            ) = GetNextSeq($subscription, $pattern, $expected->{publisheddate});
85
            ) = GetNextSeq($subscription, $pattern, $frequency, $expected->{publisheddate});
85
86
86
             ## We generate the next publication date
87
             ## We generate the next publication date
87
             my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1);
88
             my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
89
             my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, $frequency, 1);
88
             my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate;
90
             my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate;
89
             ## Creating the new issue
91
             ## Creating the new issue
90
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
92
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
(-)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 288-302 sub _guess_enddate { Link Here
288
    return $enddate;
292
    return $enddate;
289
}
293
}
290
294
295
sub manage_subscription_numbering_pattern_id {
296
    my $params;
297
    if ( $query->param('numbering_pattern') eq 'mana' ) {
298
        foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
299
                   numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
300
                   label3 add3 every3 whenmorethan3 setto3 numbering3/) {
301
            $params->{$_} = $query->param($_) if $query->param($_);
302
        }
303
304
        my $existing = Koha::Subscription::Numberpatterns->search($params)->next();
305
306
        if ($existing) {
307
            return $existing->id;
308
        }
309
310
        $params->{label} = Koha::Subscription::Numberpattern->uniqueLabel($query->param('patternname'));
311
        $params->{description} = $query->param('sndescription');
312
313
314
        my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params)->store();
315
        return $subscription_np->id;
316
    }
317
318
    return $query->param('numbering_pattern');
319
}
320
321
sub manage_subscription_frequencies_id {
322
    my $periodicity;
323
    if ( $query->param('frequency') eq 'mana' ) {
324
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
325
            {
326
                description   => $query->param('sfdescription'),
327
                unit          => $query->param('unit'),
328
                unitsperissue => $query->param('unitsperissue'),
329
                issuesperunit => $query->param('issuesperunit'),
330
            }
331
        )->store();
332
        $periodicity = $subscription_freq->id;
333
    }
334
    else {
335
        $periodicity = $query->param('frequency');
336
    }
337
    return $periodicity;
338
}
339
291
sub redirect_add_subscription {
340
sub redirect_add_subscription {
341
    my $periodicity = manage_subscription_frequencies_id();
342
    my $numberpattern = manage_subscription_numbering_pattern_id();
343
292
    my $auser          = $query->param('user');
344
    my $auser          = $query->param('user');
293
    my $branchcode     = $query->param('branchcode');
345
    my $branchcode     = $query->param('branchcode');
294
    my $aqbooksellerid = $query->param('aqbooksellerid');
346
    my $aqbooksellerid = $query->param('aqbooksellerid');
295
    my $cost           = $query->param('cost');
347
    my $cost           = $query->param('cost');
296
    my $aqbudgetid     = $query->param('aqbudgetid');
348
    my $aqbudgetid     = $query->param('aqbudgetid');
297
    my $periodicity    = $query->param('frequency');
298
    my @irregularity   = $query->multi_param('irregularity');
349
    my @irregularity   = $query->multi_param('irregularity');
299
    my $numberpattern  = $query->param('numbering_pattern');
300
    my $locale         = $query->param('locale');
350
    my $locale         = $query->param('locale');
301
    my $graceperiod    = $query->param('graceperiod') || 0;
351
    my $graceperiod    = $query->param('graceperiod') || 0;
302
352
Lines 326-331 sub redirect_add_subscription { Link Here
326
    my $previousitemtype  = $query->param('previousitemtype');
376
    my $previousitemtype  = $query->param('previousitemtype');
327
    my $skip_serialseq    = $query->param('skip_serialseq');
377
    my $skip_serialseq    = $query->param('skip_serialseq');
328
378
379
    my $mana_id;
380
    if ( $query->param('mana_id') ne "" ) {
381
        $mana_id = $query->param('mana_id');
382
        Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id);
383
    }
384
    else {
385
        $mana_id = undef;
386
    }
387
329
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
388
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
330
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
389
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
331
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
390
    my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } );
Lines 337-343 sub redirect_add_subscription { Link Here
337
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
396
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
338
        }
397
        }
339
    }
398
    }
340
341
    my $subscriptionid = NewSubscription(
399
    my $subscriptionid = NewSubscription(
342
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
400
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
343
        $startdate, $periodicity, $numberlength, $weeklength,
401
        $startdate, $periodicity, $numberlength, $weeklength,
Lines 346-352 sub redirect_add_subscription { Link Here
346
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
404
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
347
        $manualhistory, $internalnotes, $serialsadditems,
405
        $manualhistory, $internalnotes, $serialsadditems,
348
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
406
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
349
        $skip_serialseq, $itemtype, $previousitemtype
407
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
350
    );
408
    );
351
409
352
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
410
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
Lines 376-388 sub redirect_mod_subscription { Link Here
376
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
434
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
377
        : $firstacquidate;
435
        : $firstacquidate;
378
436
379
    my $periodicity = $query->param('frequency');
437
    my $periodicity = manage_subscription_frequencies_id();
438
    my $numberpattern = manage_subscription_numbering_pattern_id();
380
439
381
    my $subtype = $query->param('subtype');
440
    my $subtype = $query->param('subtype');
382
    my $sublength = $query->param('sublength');
441
    my $sublength = $query->param('sublength');
383
    my ($numberlength, $weeklength, $monthlength)
442
    my ($numberlength, $weeklength, $monthlength)
384
        = _get_sub_length( $subtype, $sublength );
443
        = _get_sub_length( $subtype, $sublength );
385
    my $numberpattern = $query->param('numbering_pattern');
386
    my $locale = $query->param('locale');
444
    my $locale = $query->param('locale');
387
    my $lastvalue1 = $query->param('lastvalue1');
445
    my $lastvalue1 = $query->param('lastvalue1');
388
    my $innerloop1 = $query->param('innerloop1');
446
    my $innerloop1 = $query->param('innerloop1');
Lines 405-410 sub redirect_mod_subscription { Link Here
405
    my $previousitemtype  = $query->param('previousitemtype');
463
    my $previousitemtype  = $query->param('previousitemtype');
406
    my $skip_serialseq    = $query->param('skip_serialseq');
464
    my $skip_serialseq    = $query->param('skip_serialseq');
407
465
466
    my $mana_id;
467
    if ( defined( $query->param('mana_id') ) ) {
468
        $mana_id = $query->param('mana_id');
469
        Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id);
470
    }
471
    else {
472
        $mana_id = undef;
473
    }
474
408
    # Guess end date
475
    # Guess end date
409
    if(!defined $enddate || $enddate eq '') {
476
    if(!defined $enddate || $enddate eq '') {
410
        if($subtype eq "issues") {
477
        if($subtype eq "issues") {
Lines 430-436 sub redirect_mod_subscription { Link Here
430
        $status, $biblionumber, $callnumber, $notes, $letter,
497
        $status, $biblionumber, $callnumber, $notes, $letter,
431
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
498
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
432
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
499
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
433
        $skip_serialseq, $itemtype, $previousitemtype
500
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
434
    );
501
    );
435
502
436
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
503
    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 72-102 my ($totalissues,@serialslist) = GetSerials($subscriptionid); Link Here
72
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
78
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
73
79
74
if ($op eq 'del') {
80
if ($op eq 'del') {
75
	if ($$subs{'cannotedit'}){
81
    if ($$subs{'cannotedit'}){
76
		carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
82
        carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
77
		print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
83
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
78
		exit;
84
        exit;
79
	}
85
    }
80
	
86
81
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
87
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
82
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
88
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
83
    my $linkedissues = CountIssues($subscriptionid);
89
    my $linkedissues = CountIssues($subscriptionid);
84
    my $countitems   = HasItems($subscriptionid);
90
    my $countitems   = HasItems($subscriptionid);
85
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
91
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
86
		$template->param(NEEDSCONFIRMATION => 1);
92
        $template->param(NEEDSCONFIRMATION => 1);
87
		if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
93
        if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
88
		if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
94
        if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
89
		if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
95
        if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
90
    } else {
96
    } else {
91
		$issueconfirmed = "1";
97
        $issueconfirmed = "1";
92
    }
98
    }
93
    # If it's ok to delete the subscription, we do so
99
    # If it's ok to delete the subscription, we do so
94
    if ($issueconfirmed eq "1") {
100
    if ($issueconfirmed eq "1") {
95
		&DelSubscription($subscriptionid);
101
        &DelSubscription($subscriptionid);
96
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
102
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
97
        exit;
103
        exit;
98
    }
104
    }
99
}
105
}
106
elsif ( $op and $op eq "share" ) {
107
    my $mana_language;
108
    if ( $query->param('mana_language') ) {
109
        $mana_language = $query->param('mana_language');
110
    }
111
    else {
112
        $mana_language = C4::Context->preference('language');
113
    }
114
115
    my $mana_email;
116
    if ( $loggedinuser ne 0 ) {
117
        my $borrower = Koha::Patrons->find($loggedinuser);
118
        $mana_email = $borrower->email
119
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
120
        $mana_email = $borrower->emailpro
121
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
122
        $mana_email =
123
          Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
124
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
125
    }
126
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
127
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
128
    my %versions = C4::Context::get_versions();
129
130
    my $mana_info = {
131
        language    => $mana_language,
132
        kohaversion => $versions{'kohaVersion'},
133
        exportemail => $mana_email
134
    };
135
    my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid);
136
    $sub_mana_info = { %$sub_mana_info, %$mana_info };
137
    my $result = Koha::SharedContent::manaPostRequest( "subscription",
138
        $sub_mana_info );
139
    if ( $result->{code} eq "200" and $result->{code} eq "201" ) {
140
        my $subscription = Koha::Subscriptions->find($subscriptionid);
141
        $subscription->set( { mana_id => $result->{id} } )->store;
142
        $subs->{mana_id} = $result->{id};
143
    }
144
    $template->param( mana_code => $result->{code} );
145
}
146
100
my $hasRouting = check_routing($subscriptionid);
147
my $hasRouting = check_routing($subscriptionid);
101
148
102
(undef, $cookie, undef, undef)
149
(undef, $cookie, undef, undef)
(-)a/svc/mana/search (+62 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 BibLibre Morgane Alonso
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
#
20
21
use strict;
22
use warnings;
23
24
use Koha::SharedContent;
25
use Koha::Subscription;
26
use C4::Auth qw(check_cookie_auth), qw(get_template_and_user);
27
use C4::Output qw( output_with_http_headers );
28
29
use CGI;
30
use JSON;
31
32
my $input = new CGI;
33
34
my ( $auth_status, $sessionID ) =
35
  check_cookie_auth( $input->cookie('CGISESSID'),
36
    { serials => 'create_subscription' } );
37
38
if ( $auth_status ne "ok" ) {
39
    exit 0;
40
}
41
42
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
    {
44
        template_name   => "serials/mana-subscription-search-result.tt",
45
        query           => $input,
46
        type            => "intranet",
47
        authnotrequired => 0,
48
49
        # flagsrequired   => { serials => $permission },
50
        flagsrequired => { serials => 'create_subscription' },
51
        debug         => 1,
52
    }
53
);
54
55
my $biblionumber = $input->param('biblionumber');
56
57
my $sub_mana_info = Koha::Subscription::get_search_info($biblionumber);
58
my $result =
59
  Koha::SharedContent::manaGetRequest( "subscription", $sub_mana_info );
60
$template->param( subscriptions => $result->{data} );
61
62
output_with_http_headers $input, $cookie, $template->output, 'json';
(-)a/svc/mana/use (+48 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 BibLibre Morgane Alonso
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
#
20
21
use strict;
22
use warnings;
23
24
use Koha::SharedContent;
25
use C4::Auth qw(check_cookie_auth);
26
27
use CGI;
28
use JSON;
29
30
31
my $input = new CGI;
32
binmode STDOUT, ":encoding(UTF-8)";
33
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
34
35
my ( $auth_status, $sessionID ) =
36
  check_cookie_auth( $input->cookie('CGISESSID'),
37
    { serials => 'create_subscription' } );
38
39
if ( $auth_status ne "ok" ) {
40
    exit 0;
41
}
42
43
my $result = Koha::SharedContent::manaGetRequestWithId("subscription", $input->param('id') );
44
45
my $subscription;
46
$subscription = $result->{data};
47
48
print(to_json($subscription));
(-)a/t/db_dependent/Koha/SharedContent.t (+29 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 BibLibre Morgane Alonso
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use t::lib::TestBuilder;
23
use Test::More tests => 1;
24
use Koha::Database;
25
26
use_ok('Koha::SharedContent');
27
28
my $schema = Koha::Database->new->schema;
29
$schema->storage->txn_begin;    # mode insertion
(-)a/t/db_dependent/Koha/Subscription.t (-2 / +80 lines)
Lines 19-36 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 10;
23
23
24
use Koha::Database;
25
use Koha::Subscription;
24
use Koha::Subscriptions;
26
use Koha::Subscriptions;
25
use Koha::Biblio;
27
use Koha::Biblio;
28
use Koha::Biblios;
26
29
27
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
28
31
29
my $schema = Koha::Database->new->schema;
32
my $schema = Koha::Database->new->schema;
30
$schema->storage->txn_begin;
33
$schema->storage->txn_begin;
31
32
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
33
35
36
use_ok('Koha::Subscription');
37
34
subtest 'Koha::Subscription->biblio' => sub {
38
subtest 'Koha::Subscription->biblio' => sub {
35
    plan tests => 1;
39
    plan tests => 1;
36
40
Lines 101-106 subtest 'Koha::Subscription->frequency' => sub { Link Here
101
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
105
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
102
};
106
};
103
107
108
my $nb_of_subs = Koha::Subscriptions->search->count;
109
my $biblio_1   = $builder->build( { source => 'Biblio' } );
110
my $bi_1       = $builder->build(
111
    {
112
        source => 'Biblioitem',
113
        value  => {
114
            biblionumber => $biblio_1->{biblionumber}
115
        }
116
    }
117
);
118
my $sub_freq_1 = $builder->build( { source => 'SubscriptionFrequency' } );
119
my $sub_np_1   = $builder->build( { source => 'SubscriptionNumberpattern' } );
120
my $sub_1      = $builder->build(
121
    {
122
        source => 'Subscription',
123
        value  => {
124
            biblionumber  => $biblio_1->{biblionumber},
125
            periodicity   => $sub_freq_1->{id},
126
            numberpattern => $sub_np_1->{id}
127
        }
128
    }
129
);
130
131
is(
132
    Koha::Subscriptions->search->count,
133
    $nb_of_subs + 1,
134
    'The subscription should have been added'
135
);
136
is(
137
    $sub_1->{biblionumber},
138
    $biblio_1->{biblionumber},
139
    'The link between sub and biblio is well done'
140
);
141
is( $sub_1->{periodicity}, $sub_freq_1->{id},
142
    'The link between sub and sub_freq is well done' );
143
is( $sub_1->{numberpattern},
144
    $sub_np_1->{id},
145
    'The link between sub and sub_numberpattern is well done' );
146
147
my $ref = {
148
    'title'           => $biblio_1->{title},
149
    'sfdescription'   => $sub_freq_1->{description},
150
    'unit'            => $sub_freq_1->{unit},
151
    'unitsperissue'   => $sub_freq_1->{unitsperissue},
152
    'issuesperunit'   => $sub_freq_1->{issuesperunit},
153
    'sndescription'   => $sub_np_1->{description},
154
    'numberingmethod' => $sub_np_1->{numberingmethod},
155
    'label'           => $sub_np_1->{label},
156
    'label1'          => $sub_np_1->{label1},
157
    'add1'            => $sub_np_1->{add1},
158
    'every1'          => $sub_np_1->{every1},
159
    'whenmorethan1'   => $sub_np_1->{whenmorethan1},
160
    'setto1'          => $sub_np_1->{setto1},
161
    'numbering1'      => $sub_np_1->{numbering1},
162
    'label2'          => $sub_np_1->{label2},
163
    'add2'            => $sub_np_1->{add2},
164
    'every2'          => $sub_np_1->{every2},
165
    'whenmorethan2'   => $sub_np_1->{whenmorethan2},
166
    'setto2'          => $sub_np_1->{setto2},
167
    'numbering2'      => $sub_np_1->{numbering2},
168
    'label3'          => $sub_np_1->{label3},
169
    'add3'            => $sub_np_1->{add3},
170
    'every3'          => $sub_np_1->{every3},
171
    'whenmorethan3'   => $sub_np_1->{whenmorethan3},
172
    'setto3'          => $sub_np_1->{setto3},
173
    'numbering3'      => $sub_np_1->{numbering3},
174
    'issn'            => $bi_1->{issn},
175
    'ean'             => $bi_1->{ean},
176
    'publishercode'   => $bi_1->{publishercode}
177
};
178
179
is_deeply( Koha::Subscription::get_sharable_info( $sub_1->{subscriptionid} ),
180
    $ref, "get_sharable_info function is ok" );
181
104
$schema->storage->txn_rollback;
182
$schema->storage->txn_rollback;
105
183
106
1;
184
1;
(-)a/t/db_dependent/Serials.t (-1 / +2 lines)
Lines 283-289 my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscrip Link Here
283
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
283
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
284
my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
284
my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
285
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
285
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
286
my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, 1);
286
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
287
my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, $frequency, 1);
287
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
288
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
288
# Add 14 serials
289
# Add 14 serials
289
my $counter = 0;
290
my $counter = 0;
(-)a/t/db_dependent/Serials/GetFictiveIssueNumber.t (-207 / +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)
3
use C4::Context;
4
4
use Test::More tests => 18;
5
use Modern::Perl;
5
use Modern::Perl;
6
use Test::More tests => 5;
7
8
use Koha::Database;
9
use C4::Serials;
10
use C4::Serials::Frequency;
11
6
12
my $schema  = Koha::Database->new->schema;
13
$schema->storage->txn_begin;
14
my $dbh = C4::Context->dbh;
7
my $dbh = C4::Context->dbh;
8
$dbh->{RaiseError} = 1;
9
$dbh->{AutoCommit} = 0;
15
10
16
subtest 'Tests for irregular frequency' => sub {
11
use C4::Serials::Frequency;
17
    plan tests => 2;
12
use C4::Serials;
18
19
    # Add a frequency
20
    my $freq_irr = AddSubscriptionFrequency({
21
        description => "Irregular",
22
        unit => undef,
23
    });
24
13
25
    # Test it
14
# TEST CASE - 1 issue per day, no irregularities
26
    my $subscription = {
15
my $frequency = {
27
        periodicity => $freq_irr,
16
    description   => "One issue per day",
28
        firstacquidate => '1972-02-07',
17
    unit          => 'day',
29
    };
18
    issuesperunit => 1,
30
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' );
19
    unitsperissue => 1,
31
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' );
32
};
20
};
33
21
34
subtest 'Tests for yearly frequencies' => sub {
22
my $subscription = {
35
    plan tests => 10;
23
    firstacquidate     => '1970-01-01',
36
24
    irregularity       => '',
37
    # First add a few frequencies
25
    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
};
26
};
99
27
my $issueNumber;
100
subtest 'Tests for monthly frequencies' => sub {
28
101
    plan tests => 8;
29
$issueNumber =
102
30
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
103
    # First add a few frequencies
31
is( $issueNumber, '1' );
104
    my $freq_1i_5m = AddSubscriptionFrequency({
32
105
        description => "1 issue per 5 months",
33
$issueNumber =
106
        unit => 'month',
34
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
107
        issuesperunit => 1,
35
is( $issueNumber, '2' );
108
        unitsperissue => 5,
36
$issueNumber =
109
    });
37
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
110
    my $freq_4i_1m = AddSubscriptionFrequency({
38
is( $issueNumber, '3' );
111
        description => "4 issue per month",
39
112
        unit => 'month',
40
# TEST CASE - 2 issues per day, no irregularity
113
        issuesperunit => 4,
41
$frequency = {
114
        unitsperissue => 1,
42
    description   => "Two issues per day",
115
    });
43
    unit          => 'day',
116
44
    issuesperunit => 2,
117
    # TEST CASE - 1 issue per 5 months
45
    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
};
46
};
143
47
$subscription = {
144
subtest 'Tests for weekly frequencies' => sub {
48
    firstacquidate     => '1970-01-01',
145
    plan tests => 4;
49
    irregularity       => '',
146
50
    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
};
51
};
181
52
$issueNumber =
182
subtest 'Tests for dayly frequencies' => sub {
53
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
183
    plan tests => 4;
54
is( $issueNumber, '1' );
184
55
$issueNumber =
185
    # First add a few frequencies
56
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
186
    my $freq_1i_12d = AddSubscriptionFrequency({
57
is( $issueNumber, '3' );
187
        description => "1 issue per 12 days",
58
$issueNumber =
188
        unit => 'day',
59
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
189
        issuesperunit => 1,
60
is( $issueNumber, '5' );
190
        unitsperissue => 12,
61
191
    });
62
$subscription->{countissuesperunit} = 2;
192
    my $freq_3i_1d = AddSubscriptionFrequency({
63
$issueNumber =
193
        description => "3 issues per day",
64
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
194
        unit => 'day',
65
is( $issueNumber, '2' );
195
        issuesperunit => 3,
66
$issueNumber =
196
        unitsperissue => 1,
67
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
197
    });
68
is( $issueNumber, '4' );
198
69
$issueNumber =
199
    # TEST CASE - 1 issue per 12 days
70
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
200
    my $subscription = {
71
is( $issueNumber, '6' );
201
        periodicity => $freq_1i_12d,
72
202
        firstacquidate => '1972-03-16',
73
# TEST CASE - 1 issue every 2 days, no irregularity
203
        countissuesperunit => 1,
74
$frequency = {
204
    };
75
    description   => "one issue every two days",
205
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27'), 1, 'Mar 27 still 1' );
76
    unit          => 'day',
206
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28'), 2, 'Mar 28 goes to 2' );
77
    issuesperunit => 1,
207
78
    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
};
79
};
219
80
$subscription = {
220
$schema->storage->txn_rollback;
81
    firstacquidate     => '1970-01-01',
82
    irregularity       => '',
83
    countissuesperunit => 1,
84
};
85
$issueNumber =
86
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
87
is( $issueNumber, 1 );
88
$issueNumber =
89
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
90
is( $issueNumber, 1 );
91
$issueNumber =
92
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
93
is( $issueNumber, 2 );
94
$issueNumber =
95
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-04', $frequency );
96
is( $issueNumber, 2 );
97
$issueNumber =
98
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-05', $frequency );
99
is( $issueNumber, 3 );
100
101
# TEST CASE - 1 issue per week, no irregularity
102
$frequency = {
103
    description   => "one issue per week",
104
    unit          => 'week',
105
    issuesperunit => 1,
106
    unitsperissue => 1,
107
};
108
$subscription = {
109
    firstacquidate     => '1970-01-01',
110
    irregularity       => '',
111
    countissuesperunit => 1,
112
};
113
$issueNumber =
114
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
115
is( $issueNumber, 1 );
116
$issueNumber =
117
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
118
is( $issueNumber, 1 );
119
$issueNumber =
120
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-08', $frequency );
121
is( $issueNumber, 2 );
122
$issueNumber =
123
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-15', $frequency );
124
is( $issueNumber, 3 );
125
126
$dbh->rollback;
(-)a/t/db_dependent/Serials/GetNextDate.t (-167 / +140 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
};
525
$subscription = {
500
$subscription = {
526
    periodicity => $id,
527
    firstacquidate => '1970-08-10',
501
    firstacquidate => '1970-08-10',
528
    irregularity => '',
502
    irregularity => '',
529
    countissuesperunit => 1,
503
    countissuesperunit => 1,
530
};
504
};
531
my @dates = ( $subscription->{firstacquidate} );
505
my @dates = ( $subscription->{firstacquidate} );
532
foreach(1..27) {
506
foreach(1..27) {
533
    push @dates, GetNextDate( $subscription, $dates[-1] );
507
    push @dates, GetNextDate( $subscription, $dates[-1], $frequency );
534
}
508
}
535
is( $dates[9],  '1971-08-10', 'Freq 9/yr, 1 year passed' );
509
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)' );
510
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' );
511
is( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' );
538
# Keep (first) position in cycle, but shift back 9 days
512
# 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' );
513
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
514
# Set position to last in cycle, and shift back 9 days; annual correction
541
$subscription->{countissuesperunit} = 9;
515
$subscription->{countissuesperunit} = 9;
542
is( GetNextDate( $subscription, '1973-08-01' ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' );
516
is( GetNextDate( $subscription, '1973-08-01', $frequency ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' );
543
517
544
# TEST CASE - Irregular
518
# TEST CASE - Irregular
545
$id = AddSubscriptionFrequency({
519
$frequency = {
546
    description => "Irregular",
520
    description => "Irregular",
547
    unit => undef,
521
    unit => undef,
548
    issuesperunit => 1,
522
    issuesperunit => 1,
549
    unitsperissue => 1,
523
    unitsperissue => 1,
550
});
524
};
551
$subscription = {
525
$subscription = {
552
    periodicity => $id,
553
    firstacquidate => '1970-01-01',
526
    firstacquidate => '1970-01-01',
554
    irregularity => '',
527
    irregularity => '',
555
    countissuesperunit => 1,
528
    countissuesperunit => 1,
556
};
529
};
557
$publisheddate = $subscription->{firstacquidate};
530
$publisheddate = $subscription->{firstacquidate};
558
# GetNextDate always return undef if subscription is irregular
531
# GetNextDate always return undef if subscription is irregular
559
$publisheddate = GetNextDate($subscription, $publisheddate);
532
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
560
is($publisheddate, undef);
533
is($publisheddate, undef);
561
534
562
# GetNextDate returns undef if one of two first parameters is undef
535
# GetNextDate returns undef if one of two first parameters is undef
563
$publisheddate = GetNextDate($subscription, undef);
536
$publisheddate = GetNextDate($subscription, undef, $frequency);
564
is($publisheddate, undef);
537
is($publisheddate, undef);
565
$publisheddate = GetNextDate(undef, $subscription->{firstacquidate});
538
$publisheddate = GetNextDate(undef, $subscription->{firstacquidate}, $frequency);
566
is($publisheddate, undef);
539
is($publisheddate, undef);
567
$publisheddate = GetNextDate(undef, undef);
540
$publisheddate = GetNextDate(undef, undef, $frequency);
568
is($publisheddate, undef);
541
is($publisheddate, undef);
569
542
570
$schema->storage->txn_rollback;
543
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials/GetNextSeq.t (-63 / +62 lines)
Lines 44-59 my $subscription = { Link Here
44
};
44
};
45
my $publisheddate = $subscription->{firstacquidate};
45
my $publisheddate = $subscription->{firstacquidate};
46
46
47
my $seq = _next_seq($subscription, $pattern, $publisheddate);
47
my $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
48
is($seq, 'X: 2');
48
is($seq, 'X: 2');
49
$publisheddate = GetNextDate($subscription, $publisheddate);
49
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
50
$seq = _next_seq($subscription, $pattern, $publisheddate);
50
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
51
is($seq, 'X: 4');
51
is($seq, 'X: 4');
52
$publisheddate = GetNextDate($subscription, $publisheddate);
52
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
53
$seq = _next_seq($subscription, $pattern, $publisheddate);
53
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
54
is($seq, 'X: 2');
54
is($seq, 'X: 2');
55
$publisheddate = GetNextDate($subscription, $publisheddate);
55
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
56
$seq = _next_seq($subscription, $pattern, $publisheddate);
56
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
57
is($seq, 'X: 3');
57
is($seq, 'X: 3');
58
58
59
# TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
59
# TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
Lines 80-98 $pattern = { Link Here
80
80
81
$publisheddate = $subscription->{firstacquidate};
81
$publisheddate = $subscription->{firstacquidate};
82
82
83
$seq = _next_seq($subscription, $pattern, $publisheddate);
83
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
84
is($seq, 'X: Tuesday');
84
is($seq, 'X: Tuesday');
85
$publisheddate = GetNextDate($subscription, $publisheddate);
85
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
86
$seq = _next_seq($subscription, $pattern, $publisheddate);
86
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
87
is($seq, 'X: Friday');
87
is($seq, 'X: Friday');
88
$publisheddate = GetNextDate($subscription, $publisheddate);
88
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
89
$seq = _next_seq($subscription, $pattern, $publisheddate);
89
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
90
is($seq, 'X: Sunday');
90
is($seq, 'X: Sunday');
91
$publisheddate = GetNextDate($subscription, $publisheddate);
91
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
92
$seq = _next_seq($subscription, $pattern, $publisheddate);
92
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
93
is($seq, 'X: Monday');
93
is($seq, 'X: Monday');
94
$publisheddate = GetNextDate($subscription, $publisheddate);
94
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
95
$seq = _next_seq($subscription, $pattern, $publisheddate);
95
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
96
is($seq, 'X: Tuesday');
96
is($seq, 'X: Tuesday');
97
97
98
# TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
98
# TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
Lines 119-137 $pattern = { Link Here
119
119
120
$publisheddate = $subscription->{firstacquidate};
120
$publisheddate = $subscription->{firstacquidate};
121
121
122
$seq = _next_seq($subscription, $pattern, $publisheddate);
122
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
123
is($seq, 'X: March');
123
is($seq, 'X: March');
124
$publisheddate = GetNextDate($subscription, $publisheddate);
124
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
125
$seq = _next_seq($subscription, $pattern, $publisheddate);
125
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
126
is($seq, 'X: September');
126
is($seq, 'X: September');
127
$publisheddate = GetNextDate($subscription, $publisheddate);
127
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
128
$seq = _next_seq($subscription, $pattern, $publisheddate);
128
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
129
is($seq, 'X: January');
129
is($seq, 'X: January');
130
$publisheddate = GetNextDate($subscription, $publisheddate);
130
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
131
$seq = _next_seq($subscription, $pattern, $publisheddate);
131
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
132
is($seq, 'X: March');
132
is($seq, 'X: March');
133
$publisheddate = GetNextDate($subscription, $publisheddate);
133
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
134
$seq = _next_seq($subscription, $pattern, $publisheddate);
134
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
135
is($seq, 'X: May');
135
is($seq, 'X: May');
136
136
137
# TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
137
# TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
Lines 158-176 $pattern = { Link Here
158
158
159
$publisheddate = $subscription->{firstacquidate};
159
$publisheddate = $subscription->{firstacquidate};
160
160
161
$seq = _next_seq($subscription, $pattern, $publisheddate);
161
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
162
is($seq, 'X: Summer');
162
is($seq, 'X: Summer');
163
$publisheddate = GetNextDate($subscription, $publisheddate);
163
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
164
$seq = _next_seq($subscription, $pattern, $publisheddate);
164
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
165
is($seq, 'X: Spring');
165
is($seq, 'X: Spring');
166
$publisheddate = GetNextDate($subscription, $publisheddate);
166
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
167
$seq = _next_seq($subscription, $pattern, $publisheddate);
167
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
168
is($seq, 'X: Fall');
168
is($seq, 'X: Fall');
169
$publisheddate = GetNextDate($subscription, $publisheddate);
169
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
170
$seq = _next_seq($subscription, $pattern, $publisheddate);
170
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
171
is($seq, 'X: Winter');
171
is($seq, 'X: Winter');
172
$publisheddate = GetNextDate($subscription, $publisheddate);
172
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
173
$seq = _next_seq($subscription, $pattern, $publisheddate);
173
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
174
is($seq, 'X: Spring');
174
is($seq, 'X: Spring');
175
175
176
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
176
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
Lines 197-215 $pattern = { Link Here
197
197
198
$publisheddate = $subscription->{firstacquidate};
198
$publisheddate = $subscription->{firstacquidate};
199
199
200
$seq = _next_seq($subscription, $pattern, $publisheddate);
200
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
201
is($seq, 'Y: 1, X: 2');
201
is($seq, 'Y: 1, X: 2');
202
$publisheddate = GetNextDate($subscription, $publisheddate);
202
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
203
$seq = _next_seq($subscription, $pattern, $publisheddate);
203
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
204
is($seq, 'Y: 2, X: 1');
204
is($seq, 'Y: 2, X: 1');
205
$publisheddate = GetNextDate($subscription, $publisheddate);
205
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
206
$seq = _next_seq($subscription, $pattern, $publisheddate);
206
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
207
is($seq, 'Y: 2, X: 3');
207
is($seq, 'Y: 2, X: 3');
208
$publisheddate = GetNextDate($subscription, $publisheddate);
208
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
209
$seq = _next_seq($subscription, $pattern, $publisheddate);
209
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
210
is($seq, 'Y: 2, X: 4');
210
is($seq, 'Y: 2, X: 4');
211
$publisheddate = GetNextDate($subscription, $publisheddate);
211
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
212
$seq = _next_seq($subscription, $pattern, $publisheddate);
212
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
213
is($seq, 'Y: 3, X: 1');
213
is($seq, 'Y: 3, X: 1');
214
214
215
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
215
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
Lines 236-276 $pattern = { Link Here
236
236
237
$publisheddate = $subscription->{firstacquidate};
237
$publisheddate = $subscription->{firstacquidate};
238
238
239
$seq = _next_seq($subscription, $pattern, $publisheddate);
239
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
240
is($seq, 'Z: 1, Y: 1, X: 2');
240
is($seq, 'Z: 1, Y: 1, X: 2');
241
$publisheddate = GetNextDate($subscription, $publisheddate);
241
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
242
$seq = _next_seq($subscription, $pattern, $publisheddate);
242
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
243
is($seq, 'Z: 1, Y: 2, X: 1');
243
is($seq, 'Z: 1, Y: 2, X: 1');
244
$publisheddate = GetNextDate($subscription, $publisheddate);
244
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
245
$seq = _next_seq($subscription, $pattern, $publisheddate);
245
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
246
is($seq, 'Z: 1, Y: 2, X: 3');
246
is($seq, 'Z: 1, Y: 2, X: 3');
247
$publisheddate = GetNextDate($subscription, $publisheddate);
247
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
248
$seq = _next_seq($subscription, $pattern, $publisheddate);
248
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
249
is($seq, 'Z: 1, Y: 2, X: 4');
249
is($seq, 'Z: 1, Y: 2, X: 4');
250
for (1..100) {
250
for (1..100) {
251
    $publisheddate = GetNextDate($subscription, $publisheddate);
251
    $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
252
    $seq = _next_seq($subscription, $pattern, $publisheddate);
252
    $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
253
}
253
}
254
$publisheddate = GetNextDate($subscription, $publisheddate);
254
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
255
$seq = _next_seq($subscription, $pattern, $publisheddate);
255
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
256
is($seq, 'Z: 4, Y: 4, X: 1');
256
is($seq, 'Z: 4, Y: 4, X: 1');
257
# 110th is here
257
# 110th is here
258
$publisheddate = GetNextDate($subscription, $publisheddate);
258
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
259
$seq = _next_seq($subscription, $pattern, $publisheddate);
259
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
260
is($seq, 'Z: 4, Y: 4, X: 3');
260
is($seq, 'Z: 4, Y: 4, X: 3');
261
$publisheddate = GetNextDate($subscription, $publisheddate);
261
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
262
$seq = _next_seq($subscription, $pattern, $publisheddate);
262
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
263
is($seq, 'Z: 4, Y: 4, X: 4');
263
is($seq, 'Z: 4, Y: 4, X: 4');
264
$publisheddate = GetNextDate($subscription, $publisheddate);
264
$publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
265
$seq = _next_seq($subscription, $pattern, $publisheddate);
265
$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
266
is($seq, 'Z: 4, Y: 5, X: 1');
266
is($seq, 'Z: 4, Y: 5, X: 1');
267
267
268
sub _next_seq {
268
sub _next_seq {
269
    my ($subscription, $pattern, $publisheddate) = @_;
269
    my ($subscription, $pattern, $frequency, $publisheddate) = @_;
270
    my $seq;
270
    my $seq;
271
    ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
271
    ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
272
        $subscription->{lastvalue3}, $subscription->{innerloop1},
272
        $subscription->{lastvalue3}, $subscription->{innerloop1},
273
        $subscription->{innerloop2}, $subscription->{innerloop3}) =
273
        $subscription->{innerloop2}, $subscription->{innerloop3}) =
274
            GetNextSeq($subscription, $pattern, $publisheddate);
274
            GetNextSeq($subscription, $pattern, $frequency, $publisheddate);
275
    return $seq;
275
    return $seq;
276
}
276
}
277
- 

Return to bug 17047