From 6b47830e692b4d2af492c9ed660c6e828726790c Mon Sep 17 00:00:00 2001 From: morgane alonso Date: Thu, 25 Aug 2016 08:22:50 +0000 Subject: [PATCH] Bug 17047 subscriptions management with Mana-KB - add a class SharedContent.pm to communicate with Mana-KB server - add a link in serials-menu.inc to serials_search.pl to open a mana-subscription research form - modify the research form in serials-search.tt to show the right fields for Mana-KB - create datatable in mana-subscription-search-result.inc to show results from a research on Mana-KB - modify serials-search.pl to manage research on Mana-KB - add a mana_id to subscription table - add a share button on serials-toolbar.inc and a modal to ask the language of the share and to alert if the subscription is already link to a Mana-KB subscription model - add function in C4/Serials to get all the info for a subscription sharing - modify subscription-detail.pl to manage sharing to Mana-KB - modify subscription-add.tt and subscription.pl to manage a import from Mana-KB during a subscription creation - add 2 script in svc for ajax calling from subscription-add.tt to communicate with Mana-KB server during a asubscription creation - add a function in Subscription.pm to have all the info for a Mana-KB research from a biblionumber - modify functions used by subscription-add.pl in C4/Serials to manage a frequency which came from Mana-KB server and not already created on the koha database, and modify the tests of the said functions Signed-off-by: Brendan A Gallagher Signed-off-by: Kyle M Hall --- C4/Serials.pm | 39 +-- Koha/SharedContent.pm | 90 ++++++ Koha/Subscription.pm | 65 +++++ Koha/Subscription/Frequencies.pm | 57 ++++ Koha/Subscription/Frequency.pm | 48 ++++ Koha/Subscription/Numberpattern.pm | 48 ++++ Koha/Subscription/Numberpatterns.pm | 77 +++++ .../mana_01-add_mana_id_in_subscription.sql | 1 + .../includes/mana-subscription-search-result.inc | 46 +++ .../prog/en/includes/serials-menu.inc | 3 + .../prog/en/includes/serials-toolbar.inc | 105 +++++++ .../serials/mana-subscription-search-result.tt | 1 + .../prog/en/modules/serials/serials-home.tt | 1 + .../prog/en/modules/serials/serials-search.tt | 73 ++++- .../prog/en/modules/serials/subscription-add.tt | 26 +- .../prog/en/modules/serials/subscription-detail.tt | 15 +- .../intranet-tmpl/prog/js/subscription-add.js | 184 ++++++++++-- misc/cronjobs/serialsUpdate.pl | 4 +- serials/serials-collection.pl | 6 +- serials/serials-search.pl | 122 +++++--- serials/showpredictionpattern.pl | 23 +- serials/subscription-add.pl | 81 +++++- serials/subscription-detail.pl | 71 ++++- svc/mana/search | 62 ++++ svc/mana/use | 48 ++++ t/db_dependent/Koha/SharedContent.t | 29 ++ t/db_dependent/Koha/Subscription.t | 85 +++++- t/db_dependent/Serials.t | 3 +- t/db_dependent/Serials/GetFictiveIssueNumber.t | 320 ++++++++------------- t/db_dependent/Serials/GetNextDate.t | 307 +++++++++----------- t/db_dependent/Serials/GetNextSeq.t | 124 ++++---- 31 files changed, 1612 insertions(+), 552 deletions(-) create mode 100644 Koha/SharedContent.pm create mode 100644 Koha/Subscription/Frequencies.pm create mode 100644 Koha/Subscription/Frequency.pm create mode 100644 Koha/Subscription/Numberpattern.pm create mode 100644 Koha/Subscription/Numberpatterns.pm create mode 100644 installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt create mode 100755 svc/mana/search create mode 100755 svc/mana/use create mode 100644 t/db_dependent/Koha/SharedContent.t diff --git a/C4/Serials.pm b/C4/Serials.pm index 45bae8c..d7c44e8 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -871,19 +871,20 @@ sub GetDistributedTo { my ( $nextseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq( $subscription, $pattern, $planneddate ); + ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate ); $subscription is a hashref containing all the attributes of the table 'subscription'. $pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns'. +$frequency is a hashref containing all the attributes of the table 'subscription_frequencies' $planneddate is a date string in iso format. This function get the next issue for the subscription given on input arg =cut sub GetNextSeq { - my ($subscription, $pattern, $planneddate) = @_; + my ($subscription, $pattern, $frequency, $planneddate) = @_; return unless ($subscription and $pattern); @@ -896,7 +897,7 @@ sub GetNextSeq { if(@irreg > 0) { my $irregularities = {}; $irregularities->{$_} = 1 foreach(@irreg); - my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1; + my $issueno = GetFictiveIssueNumber($subscription, $planneddate, $frequency) + 1; while($irregularities->{$issueno}) { $count++; $issueno++; @@ -1039,7 +1040,7 @@ sub GetExpirationDate { #calculate the date of the last issue. for ( my $i = 1 ; $i <= $length ; $i++ ) { - $enddate = GetNextDate( $subscription, $enddate ); + $enddate = GetNextDate( $subscription, $enddate, $frequency ); } } elsif ( $subscription->{monthlength} ) { if ( $$subscription{startdate} ) { @@ -1191,16 +1192,17 @@ sub ModSerialStatus { if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); + my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); # next issue number my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) - = GetNextSeq( $subscription, $pattern, $publisheddate ); + = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate ); # next date (calculated from actual date & frequency parameters) - my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1); + my $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency, 1); my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? WHERE subscriptionid = ?"; @@ -1409,7 +1411,7 @@ sub NewSubscription { $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id ) = @_; my $dbh = C4::Context->dbh; @@ -1423,8 +1425,8 @@ sub NewSubscription { irregularity, numberpattern, locale, callnumber, manualhistory, internalnotes, serialsadditems, staffdisplaycount, opacdisplaycount, graceperiod, location, enddate, skip_serialseq, - itemtype, previousitemtype) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + itemtype, previousitemtype, mana_id) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?) |; my $sth = $dbh->prepare($query); $sth->execute( @@ -1435,7 +1437,7 @@ sub NewSubscription { $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype + $itemtype, $previousitemtype, $mana_id ); my $subscriptionid = $dbh->{'mysql_insertid'}; @@ -2166,7 +2168,7 @@ sub abouttoexpire { my $expirationdate = GetExpirationDate($subscriptionid); my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); - my $nextdate = GetNextDate($subscription, $res); + my $nextdate = GetNextDate($subscription, $res, $frequency); # only compare dates if both dates exist. if ($nextdate and $expirationdate) { @@ -2232,7 +2234,7 @@ sub GetSubscriptionsFromBorrower { =head2 GetFictiveIssueNumber -$issueno = GetFictiveIssueNumber($subscription, $publishedate); +$issueno = GetFictiveIssueNumber($subscription, $publishedate, $frequency); Get the position of the issue published at $publisheddate, considering the first issue (at firstacquidate) is at position 1, the next is at position 2, etc... @@ -2251,9 +2253,8 @@ date (in GetNextDate) or the next issue number (in GetNextSeq). =cut sub GetFictiveIssueNumber { - my ($subscription, $publisheddate) = @_; + my ($subscription, $publisheddate, $frequency) = @_; - my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'}); my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef; return if !$unit; my $issueno; @@ -2397,12 +2398,13 @@ sub _get_next_date_year { =head2 GetNextDate -$resultdate = GetNextDate($publisheddate,$subscription) +$resultdate = GetNextDate($publisheddate,$subscription,$freqdata,$updatecount) this function it takes the publisheddate and will return the next issue's date and will skip dates if there exists an irregularity. $publisheddate has to be an ISO date -$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit' +$subscription is a hashref containing at least 'firstacquidate', 'irregularity', and 'countissuesperunit' +$frequency is a hashref containing frequency informations $updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database - eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be skipped then the returned date will be 2007-05-10 @@ -2415,11 +2417,10 @@ Return undef if subscription is irregular =cut sub GetNextDate { - my ( $subscription, $publisheddate, $updatecount ) = @_; + my ( $subscription, $publisheddate, $freqdata, $updatecount ) = @_; return unless $subscription and $publisheddate; - my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); if ($freqdata->{'unit'}) { my ( $year, $month, $day ) = split /-/, $publisheddate; @@ -2439,7 +2440,7 @@ sub GetNextDate { # Get the 'fictive' next issue number # It is used to check if next issue is an irregular issue. - my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1; + my $issueno = GetFictiveIssueNumber($subscription, $publisheddate, $freqdata) + 1; # Then get the next date my $unit = lc $freqdata->{'unit'}; diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm new file mode 100644 index 0000000..e0c512b --- /dev/null +++ b/Koha/SharedContent.pm @@ -0,0 +1,90 @@ +package Koha::SharedContent; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use JSON; +use HTTP::Request; +use LWP::UserAgent; + +our $MANA_IP = "http://10.25.159.107:5000"; + +sub manaRequest { + my $mana_request = shift; + my $result; + + $mana_request->content_type('application/json'); + my $userAgent = LWP::UserAgent->new; + my $response = $userAgent->request($mana_request); + + if ( $response->code ne "204" ) { + $result = from_json( $response->decoded_content ); + } + $result->{code} = $response->code; + + return $result if ( $response->code =~ /^2..$/ ); +} + +sub manaNewUserPatchRequest { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json/newUser"; + my $request = HTTP::Request->new( PATCH => $url ); + + return manaRequest($request); +} + +sub manaPostRequest { + my $resource = shift; + my $content = shift; + + my $url = "$MANA_IP/$resource.json"; + my $request = HTTP::Request->new( POST => $url ); + + $content->{bulk_import} = 0; + my $json = to_json( $content, { utf8 => 1 } ); + $request->content($json); + + return manaRequest($request); +} + +sub manaGetRequestWithId { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + +sub manaGetRequest { + my $resource = shift; + my $parameters = shift; + + $parameters = join '&', + map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () } + keys %$parameters; + my $url = "$MANA_IP/$resource.json?$parameters"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + +1; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 2a793e5..b865eaf 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -23,6 +23,11 @@ use Carp; use Koha::Database; use Koha::Biblios; +use Koha::Biblioitems; +use Koha::Subscriptions; +use Koha::Subscription::Frequencies; +use Koha::Subscription::Numberpatterns; +use JSON; use base qw(Koha::Object); @@ -52,6 +57,66 @@ sub biblio { =cut +sub get_search_info { + my $searched_sub_id = shift; + my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } ); + my $biblioitem = + Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } ); + + my $sub_mana_info = { + 'title' => $biblio->title, + 'issn' => $biblioitem->issn, + 'ean' => $biblioitem->ean, + 'publishercode' => $biblioitem->publishercode + }; + return $sub_mana_info; +} + +sub get_sharable_info { + my $shared_sub_id = shift; + my $subscription = Koha::Subscriptions->find($shared_sub_id); + my $biblio = Koha::Biblios->find( $subscription->biblionumber ); + my $biblioitem = Koha::Biblioitems->find( + { 'biblionumber' => $subscription->biblionumber } ); + my $sub_frequency = + Koha::Subscription::Frequencies->find( $subscription->periodicity ); + my $sub_numberpatteern = + Koha::Subscription::Numberpatterns->find( $subscription->numberpattern ); + + my $sub_mana_info = { + 'title' => $biblio->title, + 'sfdescription' => $sub_frequency->description, + 'unit' => $sub_frequency->unit, + 'unitsperissue' => $sub_frequency->unitsperissue, + 'issuesperunit' => $sub_frequency->issuesperunit, + 'label' => $sub_numberpatteern->label, + 'sndescription' => $sub_numberpatteern->description, + 'numberingmethod' => $sub_numberpatteern->numberingmethod, + 'label1' => $sub_numberpatteern->label1, + 'add1' => $sub_numberpatteern->add1, + 'every1' => $sub_numberpatteern->every1, + 'whenmorethan1' => $sub_numberpatteern->whenmorethan1, + 'setto1' => $sub_numberpatteern->setto1, + 'numbering1' => $sub_numberpatteern->numbering1, + 'label2' => $sub_numberpatteern->label2, + 'add2' => $sub_numberpatteern->add2, + 'every2' => $sub_numberpatteern->every2, + 'whenmorethan2' => $sub_numberpatteern->whenmorethan2, + 'setto2' => $sub_numberpatteern->setto2, + 'numbering2' => $sub_numberpatteern->numbering2, + 'label3' => $sub_numberpatteern->label3, + 'add3' => $sub_numberpatteern->add3, + 'every3' => $sub_numberpatteern->every3, + 'whenmorethan3' => $sub_numberpatteern->whenmorethan3, + 'setto3' => $sub_numberpatteern->setto3, + 'numbering3' => $sub_numberpatteern->numbering3, + 'issn' => $biblioitem->issn, + 'ean' => $biblioitem->ean, + 'publishercode' => $biblioitem->publishercode + }; + return $sub_mana_info; +} + sub _type { return 'Subscription'; } diff --git a/Koha/Subscription/Frequencies.pm b/Koha/Subscription/Frequencies.pm new file mode 100644 index 0000000..0742a67 --- /dev/null +++ b/Koha/Subscription/Frequencies.pm @@ -0,0 +1,57 @@ +package Koha::Subscription::Frequencies; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use Koha::Subscription::Frequency; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Subscription::Frequencies - Koha Subscription::Frequency object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Frequency'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/Koha/Subscription/Frequency.pm b/Koha/Subscription/Frequency.pm new file mode 100644 index 0000000..a0b7834 --- /dev/null +++ b/Koha/Subscription/Frequency.pm @@ -0,0 +1,48 @@ +package Koha::Subscription::Frequency; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::Subscription::Frequency - Koha Subscription::Frequency Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/Koha/Subscription/Numberpattern.pm b/Koha/Subscription/Numberpattern.pm new file mode 100644 index 0000000..049fbfe --- /dev/null +++ b/Koha/Subscription/Numberpattern.pm @@ -0,0 +1,48 @@ +package Koha::Subscription::Numberpattern; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::SubscriptionNumberpattern - Koha SubscriptionNumberpattern Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionNumberpattern'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/Koha/Subscription/Numberpatterns.pm b/Koha/Subscription/Numberpatterns.pm new file mode 100644 index 0000000..638e028 --- /dev/null +++ b/Koha/Subscription/Numberpatterns.pm @@ -0,0 +1,77 @@ +package Koha::Subscription::Numberpatterns; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use Koha::Subscription::Numberpattern; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 uniqeLabel + +=cut + +sub uniqueLabel { + my ($self, $label) = @_; + + my $samelabel = Koha::Subscription::Numberpatterns->search({label => $label})->next(); + if ($samelabel) { + my $i = 2; + my $newlabel = $samelabel->label . " ($i)"; + while (my $othersamelabel = $self->search({label => $newlabel})->next()) { + $i++; + $newlabel = $samelabel->label . " ($i)"; + } + $label = $newlabel; + } + return $label; +} + +=head3 type + +=cut + +sub _type { + return 'SubscriptionNumberpattern'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Numberpattern'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql new file mode 100644 index 0000000..5c590d1 --- /dev/null +++ b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql @@ -0,0 +1 @@ +ALTER TABLE subscription ADD mana_id int(11); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc new file mode 100644 index 0000000..4ce9b9b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc @@ -0,0 +1,46 @@ +[% USE KohaDates %] + + + + + + + + + + [% UNLESS search_only %] + + [% END %] + + + + + + + + + + + [% UNLESS search_only %] + + [% END %] + + + + [% FOREACH subscription IN subscriptions %] + [% UNLESS subscription.cannotdisplay %] + + + + + + + + [% UNLESS search_only %] + + [% END %] + + [% END %] + [% END %] + +
ISSNTitleFrequencyNumbering patternNumber of usersLast ImportActions
[% IF ( subscription.issn ) %][% subscription.issn %][% END %][% subscription.title %][% IF ( subscription.sfdescription ) %][% subscription.sfdescription %][% END %][% IF ( subscription.numberingmethod ) %][% subscription.numberingmethod %][% END %][% IF ( subscription.nbofusers ) %][% subscription.nbofusers %][% END %][% subscription.lastimport | $KohaDates %] Use
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc index 21dff3a..ee66508 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc @@ -31,4 +31,7 @@
  • Add subscription fields
  • + [% IF Koha.Preference('Mana') %] +
  • Search on Mana
  • + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc index 19b264d..150e3dd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc @@ -6,6 +6,13 @@ [% ELSE %] [% END %] + [% IF Koha.Preference('Mana') %] + [% IF one_language_enabled==0 or mana_id %] + + [% ELSE %] + + [% END %] + [% END %] [% END %] [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %] @@ -62,3 +69,101 @@ [% END %] [% END %] + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt new file mode 100644 index 0000000..0afe02c --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt @@ -0,0 +1 @@ +[% INCLUDE 'mana-subscription-search-result.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt index 049f386..8e736da 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt @@ -1,4 +1,5 @@ [% USE KohaDates %] +[% USE Koha %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials [% biblionumber %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt index a7896f0..88c412b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -1,6 +1,7 @@ [% USE AuthorisedValues %] [% USE Branches %] [% USE KohaDates %] +[% USE Koha %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials [% biblionumber %] @@ -92,6 +93,7 @@ [% END %] + [% IF ( mana ) %][% END %]
    @@ -99,13 +101,22 @@ [% END %] - [% IF ( done_searched ) %] - [% IF ( total ) %] -
    - + [% IF ( done_searched ) %] + [% IF ( total ) %] +
    + + [% IF mana %] +
    + [% INCLUDE 'mana-subscription-search-result.inc' %] +
    + [% ELSE %]
    [% IF openedsubscriptions %] @@ -323,6 +334,7 @@ [% END %] + [% END %] [% ELSE %]
    @@ -336,6 +348,7 @@
    [% INCLUDE 'serials-menu.inc' %] [% IF ( done_searched ) %] + [% UNLESS ( mana ) %]
    @@ -408,10 +421,12 @@
    +
    [% END %] + [% END %]
    @@ -452,6 +467,50 @@ $("#reopensub").click(function(){ return confirm(_("Are you sure you want to reopen this subscription?")); }); + var manarlt = $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, { + "sPaginationType": "four_button", + "aoColumnDefs": [ + { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, + { "sType": "title-string", "aTargets" : [ "title-string" ] }, + { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } + ] + })); + var osrlt = $("#osrlt").dataTable($.extend(true, {}, dataTablesDefaults, { + "sPaginationType": "four_button", + "aoColumnDefs": [ + { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, + { "sType": "title-string", "aTargets" : [ "title-string" ] }, + { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } + ] + })); + + var csrlt = $("#csrlt").dataTable($.extend(true, {}, dataTablesDefaults, { + "sPaginationType": "four_button", + "aoColumnDefs": [ + { 'bSortable': false, 'aTargets': [ 'NoSort' ] }, + { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } + ] + } ) ); + + manarlt.fnAddFilters("dt-filter", 750); + osrlt.fnAddFilters("dt-filter", 750); + csrlt.fnAddFilters("dt-filter", 750); + + $('#serialstabs').tabs(); + $("#reopensub").click(function(){ + return confirm(_("Are you sure you want to reopen this subscription?")); + }); + [% IF ( mana ) %] + $("label[for=callnumber], input#callnumber").hide(); + $("label[for=bookseller], input#bookseller").hide(); + $("label[for=branch], select#branch").hide(); + $("label[for=to], input#to").hide(); + $(".ui-datepicker-trigger").hide(); + $("label[for=location], select#location_filter").hide(); + [% FOR field IN additional_fields_for_subscription %] + $("label[for=additional_field_[% field.id %]], input#additional_field_[% field.id %]").hide(); + [% END %] + [% END %] }); [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index f9c0cae..6e65b78 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -1,5 +1,6 @@ [% USE KohaDates %] [% USE Branches %] +[% USE Koha %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials › [% IF ( modify ) %][% bibliotitle |html %] › Modify subscription[% ELSE %]New subscription[% END %] @@ -204,6 +205,9 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
    +
    Serials planning @@ -468,10 +472,16 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
    [% END %] + + + + + +
    - +
    @@ -483,6 +493,20 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ + [% MACRO jsinclude BLOCK %] [% INCLUDE 'calendar.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index c9d0330..34521e7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -18,7 +18,7 @@
    - [% INCLUDE 'serials-toolbar.inc' %] + [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]

    Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]

    [% IF ( abouttoexpire ) %] @@ -47,7 +47,18 @@
    - [% END %] + [% END %] + [% IF mana_code.defined %] +
    +

    + [% IF (mana_code == 201) %] + The export is done, thank you for your contribution. + [% ELSIF (mana_code == 200) %] + The model already exists on Mana, thank you for your contribution. + [% END %] +

    +
    + [% END %]
      diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index c995751..df26753 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -2,6 +2,9 @@ var globalnumpatterndata; var globalfreqdata; +var mananumpatterndata; +var manafreqdata; +var manaid; var advancedpatternlocked; var patternneedtobetested = 0; if ( irregularity !== "" ){ @@ -85,31 +88,57 @@ function Check_page2(){ } function frequencyload(){ - $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'}, - function(freqdata){ - globalfreqdata=freqdata; - if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) { - var option = $("#subtype option[value='issues']"); - $(option).attr('selected', 'selected'); - $("#subtype option[value!='issues']").prop('disabled', true) - } else { - $("#subtype option").prop('disabled', false) - } + if ($("#frequency option:selected").val() === "mana"){ + globalfreqdata=manafreqdata; + $("input[name='sfdescription']").val(manafreqdata.description); + $("input[name='unit']").val(manafreqdata.unit); + $("input[name='unitsperissue']").val(manafreqdata.unitsperissue); + $("input[name='issuesperunit']").val(manafreqdata.issuesperunit); + if ($( "#numberpattern option:selected" ).val() === "mana" ) { + $("input[name='mana_id']").val(manaid); } - ) + } else { + $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'}, + function(freqdata){ + globalfreqdata=freqdata; + if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) { + var option = $("#subtype option[value='issues']"); + $(option).attr('selected', 'selected'); + $("#subtype option[value!='issues']").prop('disabled', true); + } else { + $("#subtype option").prop('disabled', false); + } + } + ); + $("input[name='mana_id']").val(""); + } } function numberpatternload(){ - $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'}, - function(numpatterndata){ - globalnumpatterndata=numpatterndata; - if (globalnumpatterndata==undefined){ - return false; - } - displaymoreoptions(); - restoreAdvancedPattern(); + if($("#numberpattern option:selected" ).val() === "mana"){ + globalnumpatterndata=mananumpatterndata; + $("input[name='sndescription']").val(mananumpatterndata.description); + if($("#frequency option:selected" ).val() === "mana"){ + $("input[name='mana_id']").val(manaid); } - ); + if (globalnumpatterndata==undefined){ + return false; + } + displaymoreoptions(); + restoreAdvancedPattern(); + } else { + $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'}, + function(numpatterndata){ + globalnumpatterndata=numpatterndata; + if (globalnumpatterndata==undefined){ + return false; + } + displaymoreoptions(); + restoreAdvancedPattern(); + } + ); + $("input[name='mana_id']").val(""); + } } function displaymoreoptions() { @@ -275,7 +304,8 @@ function testPredictionPattern() { 'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3', 'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3', 'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3', - 'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale' + 'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale', + 'sfdescription', 'unitsperissue', 'issuesperunit', 'unit' ]; for(i in ajaxParams) { var param = ajaxParams[i]; @@ -288,7 +318,7 @@ function testPredictionPattern() { url:"/cgi-bin/koha/serials/showpredictionpattern.pl", data: ajaxData, success: function(data) { - $("#displayexample").html(data); + $("#displayexample").html(data).show(); patternneedtobetested = 0; } }); @@ -362,8 +392,113 @@ function show_page_2() { displaymoreoptions(); } +function mana_search() { + $.ajax({ + type: "POST", + url: "/cgi-bin/koha/svc/mana/search", + data: {biblionumber : $("#biblionumber").val()}, + dataType: "html", + }) + .done( function( result ) { + $("#mana_search_result .modal-body").html(result); + $("#mana_search_result_label").text("Results from Mana"); + $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, { + "sPaginationType": "four_button", + "aoColumnDefs": [ + { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, + { "sType": "title-string", "aTargets" : [ "title-string" ] }, + { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } + ] + })); + if($("td.dataTables_empty").length == 0){ + $("#mana_search").show(); + } + }).fail(function(result){ + }); +} + +function mana_use(mana_id){ + $("tr").removeClass("selected"); + $("#row"+mana_id).addClass("selected"); + $.ajax( { + type: "POST", + url: "/cgi-bin/koha/svc/mana/use", + data: {id : mana_id}, + dataType: "json", + }) + .done(function(result){ + var select = document.getElementById('numberpattern'); + for(i = 0; i < select.length; i++){ + if(select[i].value === "mana"){ + select.remove(i); + } + } + var optionnumpattern = document.createElement("option"); + optionnumpattern.text = result.label + " (mana)"; + optionnumpattern.selected = true; + optionnumpattern.value="mana"; + select.add(optionnumpattern); + + mananumpatterndata = { + id:"mana", + add1:result.add1, + add2:result.add2, + add3:result.add3, + description:result.sndescription, + displayorder:result.displayorder, + every1:result.every1, + every2:result.every2, + every3:result.every3, + label:result.label, + label1:result.label1, + label2:result.label2, + label3:result.label3, + numbering1:result.numbering1, + numbering2:result.numbering2, + numbering3:result.numbering3, + numberingmethod:result.numberingmethod, + setto1:result.setto1, + setto2:result.setto2, + setto3:result.setto3, + whenmorethan1:result.whenmorethan1, + whenmorethan2:result.whenmorethan2, + whenmorethan3:result.whenmorethan3, + }; + select = document.getElementById("frequency"); + for(i = 0; i < select.length; i++){ + if(select[i].value === "mana"){ + select.remove(i); + } + } + var optionfreq = document.createElement("option"); + optionfreq.text = result.sfdescription + " (mana)"; + optionfreq.selected = true; + optionfreq.value="mana"; + select.add(optionfreq); + manafreqdata = { + id:"mana", + description:result.sfdescription, + displayorder:result.displayorder, + issuesperunit:result.issuesperunit, + unit:result.unit, + unitsperissue:result.unitsperissue, + }; + manaid = result.id; + $("input[name='mana_id']").val(manaid); + $("#mana_search_result").modal("hide"); + frequencyload(); + numberpatternload(); + }).fail( function( result ){ + }); +} + +function removeDisabledAttr() { + $('select:disabled').removeAttr('disabled'); +} $(document).ready(function() { + $("#displayexample").hide(); + $("#mana_search_result").modal("hide"); $("#aqbooksellerid").on('keypress', function(e) { if (e.keyCode == 13) { e.preventDefault(); @@ -447,6 +582,8 @@ $(document).ready(function() { }); } + $("#mana_search").hide(); + show_page_1(); $("#subscription_add_form").on("submit",function(){ return Check_page2(); @@ -469,6 +606,9 @@ $(document).ready(function() { }); $("#subscription_add_next").on("click",function(){ if ( Check_page1() ){ + [% IF Koha.Preference('Mana') %] + mana_search(); + [% END %] show_page_2(); } }); diff --git a/misc/cronjobs/serialsUpdate.pl b/misc/cronjobs/serialsUpdate.pl index aae1e56..a478476 100755 --- a/misc/cronjobs/serialsUpdate.pl +++ b/misc/cronjobs/serialsUpdate.pl @@ -33,6 +33,7 @@ use C4::Debug; use C4::Serials; use C4::Log; use Koha::DateUtils; +use C4::Serials::Frequency; use Date::Calc qw/Date_to_Days check_date/; use Getopt::Long; @@ -118,7 +119,8 @@ while ( my $issue = $sth->fetchrow_hashref ) { my $publisheddate = $issue->{publisheddate}; if ( $subscription && $publisheddate && $publisheddate ne "0000-00-00" ) { - my $nextpublisheddate = GetNextDate( $subscription, $publisheddate ); + my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); + my $nextpublisheddate = GetNextDate( $subscription, $publisheddate, $freqdata ); my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); if ( $nextpublisheddate && $today ) { diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index e9cb3fd..afb4462 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -74,14 +74,16 @@ if($op eq 'gennext' && @subscriptionid){ require C4::Serials::Numberpattern; my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); + my $frequency = C4::Serials::Frequency::GetSubscriptionFrequencies($subscription->{periodicity}); my $expected = GetNextExpected($subscriptionid); my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq($subscription, $pattern, $expected->{publisheddate}); + ) = GetNextSeq($subscription, $pattern, $frequency, $expected->{publisheddate}); ## We generate the next publication date - my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1); + my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); + my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, $frequency, 1); ## Creating the new issue NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpublisheddate, $nextpublisheddate ); diff --git a/serials/serials-search.pl b/serials/serials-search.pl index 30bf7db..d6cb85c 100755 --- a/serials/serials-search.pl +++ b/serials/serials-search.pl @@ -38,6 +38,7 @@ use C4::Serials; use Koha::AdditionalField; use Koha::DateUtils; +use Koha::SharedContent; my $query = new CGI; my $title = $query->param('title_filter') || ''; @@ -52,6 +53,7 @@ my $location = $query->param('location_filter') || ''; my $expiration_date = $query->param('expiration_date_filter') || ''; my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); my $searched = $query->param('searched') || 0; +my $mana = $query->param('mana') || 0; my @subscriptionids = $query->multi_param('subscriptionid'); my $op = $query->param('op'); @@ -95,7 +97,17 @@ for my $field ( @$additional_fields ) { my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef; my @subscriptions; if ($searched){ - @subscriptions = SearchSubscriptions( + if ($mana) { + my $result = Koha::SharedContent::manaGetRequest("subscription",{ + title => $title, + issn => $ISSN, + ean => $EAN, + publisher => $publisher + }); + @subscriptions = @{ $result->{data} }; + } + else { + @subscriptions = SearchSubscriptions( { biblionumber => $biblionumber, title => $title, @@ -108,46 +120,84 @@ if ($searched){ additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}{value}, authorised_value_category => $additional_field_filters->{$_}{authorised_value_category} } } keys %$additional_field_filters ], location => $location, expiration_date => $expiration_date_dt, - } - ); + }); + } } -# to toggle between create or edit routing list options -if ($routing) { - for my $subscription ( @subscriptions) { - $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); - } +if ($mana) { + $template->param( + subscriptions => \@subscriptions, + total => scalar @subscriptions, + title_filter => $title, + ISSN_filter => $ISSN, + EAN_filter => $EAN, + callnumber_filter => $callnumber, + publisher_filter => $publisher, + bookseller_filter => $bookseller, + branch_filter => $branch, + location_filter => $location, + expiration_date_filter => $expiration_date_dt, + done_searched => $searched, + routing => $routing, + additional_field_filters => $additional_field_filters, + additional_fields_for_subscription => $additional_fields, + marcflavour => (uc(C4::Context->preference("marcflavour"))), + mana => $mana, + search_only => 1 + ); } +else +{ + # to toggle between create or edit routing list options + if ($routing) { + for my $subscription ( @subscriptions) { + $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); + } + } -my (@openedsubscriptions, @closedsubscriptions); -for my $sub ( @subscriptions ) { - unless ( $sub->{closed} ) { - push @openedsubscriptions, $sub - unless $sub->{cannotdisplay}; - } else { - push @closedsubscriptions, $sub - unless $sub->{cannotdisplay}; + my (@openedsubscriptions, @closedsubscriptions); + for my $sub ( @subscriptions ) { + unless ( $sub->{closed} ) { + push @openedsubscriptions, $sub + unless $sub->{cannotdisplay}; + } else { + push @closedsubscriptions, $sub + unless $sub->{cannotdisplay}; + } } -} -$template->param( - openedsubscriptions => \@openedsubscriptions, - closedsubscriptions => \@closedsubscriptions, - total => @openedsubscriptions + @closedsubscriptions, - title_filter => $title, - ISSN_filter => $ISSN, - EAN_filter => $EAN, - callnumber_filter => $callnumber, - publisher_filter => $publisher, - bookseller_filter => $bookseller, - branch_filter => $branch, - location_filter => $location, - expiration_date_filter => $expiration_date_dt, - done_searched => $searched, - routing => $routing, - additional_field_filters => $additional_field_filters, - additional_fields_for_subscription => $additional_fields, - marcflavour => (uc(C4::Context->preference("marcflavour"))) -); + my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } ); + my @branches_loop; + foreach my $b ( @branches ) { + my $selected = 0; + $selected = 1 if( defined $branch and $branch eq $b->branchcode ); + push @branches_loop, { + branchcode => $b->branchcode, + branchname => $b->branchname, + selected => $selected, + }; + } + $template->param( + openedsubscriptions => \@openedsubscriptions, + closedsubscriptions => \@closedsubscriptions, + total => @openedsubscriptions + @closedsubscriptions, + title_filter => $title, + ISSN_filter => $ISSN, + EAN_filter => $EAN, + callnumber_filter => $callnumber, + publisher_filter => $publisher, + bookseller_filter => $bookseller, + branch_filter => $branch, + location_filter => $location, + expiration_date_filter => $expiration_date_dt, + branches_loop => \@branches_loop, + done_searched => $searched, + routing => $routing, + additional_field_filters => $additional_field_filters, + additional_fields_for_subscription => $additional_fields, + marcflavour => (uc(C4::Context->preference("marcflavour"))), + mana => $mana + ); +} output_html_with_http_headers $query, $cookie, $template->output; diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl index 6986b5e..ec55f0e 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -56,7 +56,21 @@ my $subtype = $input->param('subtype'); my $sublength = $input->param('sublength'); my $custompattern = $input->param('custompattern'); -my $frequency = GetSubscriptionFrequency($frequencyid); + +my $frequency; +if ( $frequencyid eq 'mana' ) { + $frequency = { + 'id' => undef, + 'displayorder' => undef, + 'description' => scalar $input->param('sfdescription') // '', + 'unitsperissue' => scalar $input->param('unitsperissue') // '', + 'issuesperunit' => scalar $input->param('issuesperunit') // '', + 'unit' => scalar $input->param('unit') // '' + }; +} +else { + $frequency = GetSubscriptionFrequency($frequencyid); +} my %pattern = ( numberingmethod => scalar $input->param('numberingmethod') // '', @@ -98,14 +112,13 @@ my %subscription = ( innerloop2 => scalar $input->param('innerloop2') // '', innerloop3 => scalar $input->param('innerloop3') // '', irregularity => '', - periodicity => $frequencyid, countissuesperunit => 1, firstacquidate => $firstacquidate, ); my $issuenumber; if(defined $subscriptionid) { - ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date); + ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date, $frequency); } else { $issuenumber = 1; } @@ -135,7 +148,7 @@ while( $i < 1000 ) { my %line; if(defined $date){ - $date = GetNextDate(\%subscription, $date); + $date = GetNextDate(\%subscription, $date, $frequency); } if(defined $date){ $line{'publicationdate'} = $date; @@ -156,7 +169,7 @@ while( $i < 1000 ) { last; } - ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern); + ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern, $frequency); $issuenumber++; $line{'number'} = $calculated; $line{'issuenumber'} = $issuenumber; diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index 16d397b..afa51dd 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -36,6 +36,10 @@ use Koha::DateUtils; use Koha::ItemTypes; use Carp; +use Koha::Subscription::Numberpattern; +use Koha::Subscription::Frequency; +use Koha::SharedContent; + #use Smart::Comments; our $query = CGI->new; @@ -286,15 +290,61 @@ sub _guess_enddate { return $enddate; } +sub manage_subscription_numbering_pattern_id { + my $params; + if ( $query->param('numbering_pattern') eq 'mana' ) { + foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1 + numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2 + label3 add3 every3 whenmorethan3 setto3 numbering3/) { + $params->{$_} = $query->param($_) if $query->param($_); + } + + my $existing = Koha::Subscription::Numberpatterns->search($params)->next(); + + if ($existing) { + return $existing->id; + } + + $params->{label} = Koha::Subscription::Numberpattern->uniqueLabel($query->param('patternname')); + $params->{description} = $query->param('sndescription'); + + + my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params)->store(); + return $subscription_np->id; + } + + return $query->param('numbering_pattern'); +} + +sub manage_subscription_frequencies_id { + my $periodicity; + if ( $query->param('frequency') eq 'mana' ) { + my $subscription_freq = Koha::Subscription::Frequency->new()->set( + { + description => $query->param('sfdescription'), + unit => $query->param('unit'), + unitsperissue => $query->param('unitsperissue'), + issuesperunit => $query->param('issuesperunit'), + } + )->store(); + $periodicity = $subscription_freq->id; + } + else { + $periodicity = $query->param('frequency'); + } + return $periodicity; +} + sub redirect_add_subscription { + my $periodicity = manage_subscription_frequencies_id(); + my $numberpattern = manage_subscription_numbering_pattern_id(); + my $auser = $query->param('user'); my $branchcode = $query->param('branchcode'); my $aqbooksellerid = $query->param('aqbooksellerid'); my $cost = $query->param('cost'); my $aqbudgetid = $query->param('aqbudgetid'); - my $periodicity = $query->param('frequency'); my @irregularity = $query->multi_param('irregularity'); - my $numberpattern = $query->param('numbering_pattern'); my $locale = $query->param('locale'); my $graceperiod = $query->param('graceperiod') || 0; @@ -324,6 +374,15 @@ sub redirect_add_subscription { my $previousitemtype = $query->param('previousitemtype'); my $skip_serialseq = $query->param('skip_serialseq'); + my $mana_id; + if ( $query->param('mana_id') ne "" ) { + $mana_id = $query->param('mana_id'); + Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id); + } + else { + $mana_id = undef; + } + my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } ); my $enddate = output_pref( { str => scalar $query->param('enddate'), dateonly => 1, dateformat => 'iso' } ); my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } ); @@ -335,7 +394,6 @@ sub redirect_add_subscription { $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength) } } - my $subscriptionid = NewSubscription( $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, $numberlength, $weeklength, @@ -344,7 +402,7 @@ sub redirect_add_subscription { join(";",@irregularity), $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, - $skip_serialseq + $skip_serialseq, $mana_id ); my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); @@ -374,13 +432,13 @@ sub redirect_mod_subscription { ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } ) : $firstacquidate; - my $periodicity = $query->param('frequency'); + my $periodicity = manage_subscription_frequencies_id(); + my $numberpattern = manage_subscription_numbering_pattern_id(); my $subtype = $query->param('subtype'); my $sublength = $query->param('sublength'); my ($numberlength, $weeklength, $monthlength) = _get_sub_length( $subtype, $sublength ); - my $numberpattern = $query->param('numbering_pattern'); my $locale = $query->param('locale'); my $lastvalue1 = $query->param('lastvalue1'); my $innerloop1 = $query->param('innerloop1'); @@ -403,6 +461,15 @@ sub redirect_mod_subscription { my $previousitemtype = $query->param('previousitemtype'); my $skip_serialseq = $query->param('skip_serialseq'); + my $mana_id; + if ( defined( $query->param('mana_id') ) ) { + $mana_id = $query->param('mana_id'); + Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id); + } + else { + $mana_id = undef; + } + # Guess end date if(!defined $enddate || $enddate eq '') { if($subtype eq "issues") { @@ -428,7 +495,7 @@ sub redirect_mod_subscription { $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, - $skip_serialseq, $itemtype, $previousitemtype + $skip_serialseq, $itemtype, $previousitemtype, $mana_id ); my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index b7e7c05..f992fe1 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -33,6 +33,12 @@ use Koha::Acquisition::Bookseller; use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/; use Carp; +use LWP::UserAgent; +use Koha::SharedContent; +use Koha::Patrons; +use Koha::Subscriptions; +use Koha::Libraries; + my $query = new CGI; my $op = $query->param('op') || q{}; my $issueconfirmed = $query->param('issueconfirmed'); @@ -68,31 +74,72 @@ my ($totalissues,@serialslist) = GetSerials($subscriptionid); $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue) if ($op eq 'del') { - if ($$subs{'cannotedit'}){ - carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; - print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); - exit; - } - + if ($$subs{'cannotedit'}){ + carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; + print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); + exit; + } + # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid); my $linkedissues = CountIssues($subscriptionid); my $countitems = HasItems($subscriptionid); if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) { - $template->param(NEEDSCONFIRMATION => 1); - if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); } - if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); } - if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); } + $template->param(NEEDSCONFIRMATION => 1); + if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); } + if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); } + if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); } } else { - $issueconfirmed = "1"; + $issueconfirmed = "1"; } # If it's ok to delete the subscription, we do so if ($issueconfirmed eq "1") { - &DelSubscription($subscriptionid); + &DelSubscription($subscriptionid); print $query->redirect("/cgi-bin/koha/serials/serials-home.pl"); exit; } } +elsif ( $op and $op eq "share" ) { + my $mana_language; + if ( $query->param('mana_language') ) { + $mana_language = $query->param('mana_language'); + } + else { + $mana_language = C4::Context->preference('language'); + } + + my $mana_email; + if ( $loggedinuser ne 0 ) { + my $borrower = Koha::Patrons->find($loggedinuser); + $mana_email = $borrower->email + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + $mana_email = $borrower->emailpro + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + $mana_email = + Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + } + $mana_email = C4::Context->preference('KohaAdminEmailAddress') + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + my %versions = C4::Context::get_versions(); + + my $mana_info = { + language => $mana_language, + kohaversion => $versions{'kohaVersion'}, + exportemail => $mana_email + }; + my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid); + $sub_mana_info = { %$sub_mana_info, %$mana_info }; + my $result = Koha::SharedContent::manaPostRequest( "subscription", + $sub_mana_info ); + if ( $result->{code} eq "200" and $result->{code} eq "201" ) { + my $subscription = Koha::Subscriptions->find($subscriptionid); + $subscription->set( { mana_id => $result->{id} } )->store; + $subs->{mana_id} = $result->{id}; + } + $template->param( mana_code => $result->{code} ); +} + my $hasRouting = check_routing($subscriptionid); (undef, $cookie, undef, undef) diff --git a/svc/mana/search b/svc/mana/search new file mode 100755 index 0000000..0f58c84 --- /dev/null +++ b/svc/mana/search @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . +# + +use strict; +use warnings; + +use Koha::SharedContent; +use Koha::Subscription; +use C4::Auth qw(check_cookie_auth), qw(get_template_and_user); +use C4::Output qw( output_with_http_headers ); + +use CGI; +use JSON; + +my $input = new CGI; + +my ( $auth_status, $sessionID ) = + check_cookie_auth( $input->cookie('CGISESSID'), + { serials => 'create_subscription' } ); + +if ( $auth_status ne "ok" ) { + exit 0; +} + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "serials/mana-subscription-search-result.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + + # flagsrequired => { serials => $permission }, + flagsrequired => { serials => 'create_subscription' }, + debug => 1, + } +); + +my $biblionumber = $input->param('biblionumber'); + +my $sub_mana_info = Koha::Subscription::get_search_info($biblionumber); +my $result = + Koha::SharedContent::manaGetRequest( "subscription", $sub_mana_info ); +$template->param( subscriptions => $result->{data} ); + +output_with_http_headers $input, $cookie, $template->output, 'json'; diff --git a/svc/mana/use b/svc/mana/use new file mode 100755 index 0000000..a2f2e44 --- /dev/null +++ b/svc/mana/use @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . +# + +use strict; +use warnings; + +use Koha::SharedContent; +use C4::Auth qw(check_cookie_auth); + +use CGI; +use JSON; + + +my $input = new CGI; +binmode STDOUT, ":encoding(UTF-8)"; +print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); + +my ( $auth_status, $sessionID ) = + check_cookie_auth( $input->cookie('CGISESSID'), + { serials => 'create_subscription' } ); + +if ( $auth_status ne "ok" ) { + exit 0; +} + +my $result = Koha::SharedContent::manaGetRequestWithId("subscription", $input->param('id') ); + +my $subscription; +$subscription = $result->{data}; + +print(to_json($subscription)); diff --git a/t/db_dependent/Koha/SharedContent.t b/t/db_dependent/Koha/SharedContent.t new file mode 100644 index 0000000..3784028 --- /dev/null +++ b/t/db_dependent/Koha/SharedContent.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use t::lib::TestBuilder; +use Test::More tests => 1; +use Koha::Database; + +use_ok('Koha::SharedContent'); + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; # mode insertion diff --git a/t/db_dependent/Koha/Subscription.t b/t/db_dependent/Koha/Subscription.t index 46256d3..4f9da6f 100644 --- a/t/db_dependent/Koha/Subscription.t +++ b/t/db_dependent/Koha/Subscription.t @@ -19,13 +19,21 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 7; +use t::lib::TestBuilder; + +use Koha::Database; use Koha::Subscription; use Koha::Biblio; +use Koha::Subscriptions; +use Koha::Biblios; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; +my $builder = t::lib::TestBuilder->new; + +use_ok('Koha::Subscription'); subtest 'Koha::Subscription::biblio' => sub { plan tests => 1; @@ -39,6 +47,81 @@ subtest 'Koha::Subscription::biblio' => sub { is($b->biblionumber, $biblio->biblionumber, 'Koha::Subscription::biblio returns the correct biblio'); }; +my $nb_of_subs = Koha::Subscriptions->search->count; +my $biblio_1 = $builder->build( { source => 'Biblio' } ); +my $bi_1 = $builder->build( + { + source => 'Biblioitem', + value => { + biblionumber => $biblio_1->{biblionumber} + } + } +); +my $sub_freq_1 = $builder->build( { source => 'SubscriptionFrequency' } ); +my $sub_np_1 = $builder->build( { source => 'SubscriptionNumberpattern' } ); +my $sub_1 = $builder->build( + { + source => 'Subscription', + value => { + biblionumber => $biblio_1->{biblionumber}, + periodicity => $sub_freq_1->{id}, + numberpattern => $sub_np_1->{id} + } + } +); + +is( + Koha::Subscriptions->search->count, + $nb_of_subs + 1, + 'The subscription should have been added' +); +is( + $sub_1->{biblionumber}, + $biblio_1->{biblionumber}, + 'The link between sub and biblio is well done' +); +is( $sub_1->{periodicity}, $sub_freq_1->{id}, + 'The link between sub and sub_freq is well done' ); +is( $sub_1->{numberpattern}, + $sub_np_1->{id}, + 'The link between sub and sub_numberpattern is well done' ); + +my $ref = { + 'title' => $biblio_1->{title}, + 'notes' => $sub_1->{notes}, + 'sfdescription' => $sub_freq_1->{description}, + 'displayorder' => $sub_freq_1->{displayorder}, + 'unit' => $sub_freq_1->{unit}, + 'unitsperissue' => $sub_freq_1->{unitsperissue}, + 'issuesperunit' => $sub_freq_1->{issuesperunit}, + 'sndescription' => $sub_np_1->{description}, + 'numberingmethod' => $sub_np_1->{numberingmethod}, + 'label1' => $sub_np_1->{label1}, + 'add1' => $sub_np_1->{add1}, + 'every1' => $sub_np_1->{every1}, + 'whenmorethan1' => $sub_np_1->{whenmorethan1}, + 'setto1' => $sub_np_1->{setto1}, + 'numbering1' => $sub_np_1->{numbering1}, + 'label2' => $sub_np_1->{label2}, + 'add2' => $sub_np_1->{add2}, + 'every2' => $sub_np_1->{every2}, + 'whenmorethan2' => $sub_np_1->{whenmorethan2}, + 'setto2' => $sub_np_1->{setto2}, + 'numbering2' => $sub_np_1->{numbering2}, + 'label3' => $sub_np_1->{label3}, + 'add3' => $sub_np_1->{add3}, + 'every3' => $sub_np_1->{every3}, + 'whenmorethan3' => $sub_np_1->{whenmorethan3}, + 'setto3' => $sub_np_1->{setto3}, + 'numbering3' => $sub_np_1->{numbering3}, + 'issn' => $bi_1->{issn}, + 'ean' => $bi_1->{ean}, + 'publishercode' => $bi_1->{publishercode} +}; + +is_deeply( Koha::Subscription::get_sharable_info( $sub_1->{subscriptionid} ), + $ref, "get_sharable_info function is ok" ); + $schema->storage->txn_rollback; 1; diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index de623fe..5e8e76b 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -288,7 +288,8 @@ my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscrip ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid ); my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid ); -my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, 1); +my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); +my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, $frequency, 1); my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 ); # Add 14 serials my $counter = 0; diff --git a/t/db_dependent/Serials/GetFictiveIssueNumber.t b/t/db_dependent/Serials/GetFictiveIssueNumber.t index 993baf4..e944de9 100644 --- a/t/db_dependent/Serials/GetFictiveIssueNumber.t +++ b/t/db_dependent/Serials/GetFictiveIssueNumber.t @@ -1,220 +1,126 @@ #!/usr/bin/perl -# This test deals with GetFictiveIssueNumber (from C4::Serials) - +use C4::Context; +use Test::More tests => 18; use Modern::Perl; -use Test::More tests => 5; - -use Koha::Database; -use C4::Serials; -use C4::Serials::Frequency; -my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; my $dbh = C4::Context->dbh; +$dbh->{RaiseError} = 1; +$dbh->{AutoCommit} = 0; -subtest 'Tests for irregular frequency' => sub { - plan tests => 2; - - # Add a frequency - my $freq_irr = AddSubscriptionFrequency({ - description => "Irregular", - unit => undef, - }); +use C4::Serials::Frequency; +use C4::Serials; - # Test it - my $subscription = { - periodicity => $freq_irr, - firstacquidate => '1972-02-07', - }; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' ); +# TEST CASE - 1 issue per day, no irregularities +my $frequency = { + description => "One issue per day", + unit => 'day', + issuesperunit => 1, + unitsperissue => 1, }; -subtest 'Tests for yearly frequencies' => sub { - plan tests => 10; - - # First add a few frequencies - my $freq_1i_1y = AddSubscriptionFrequency({ - description => "1 issue per year", - unit => 'year', - issuesperunit => 1, - unitsperissue => 1, - }); - my $freq_1i_3y = AddSubscriptionFrequency({ - description => "1 issue per 3 years", - unit => 'year', - issuesperunit => 1, - unitsperissue => 3, - }); - my $freq_5i_1y = AddSubscriptionFrequency({ - description => "5 issues per year", - unit => 'year', - issuesperunit => 5, - unitsperissue => 1, - }); - my $freq_366i_1y = AddSubscriptionFrequency({ - description => "366 issue per year", - unit => 'year', - issuesperunit => 366, - unitsperissue => 1, - }); - - # TEST CASE - 1 issue per year - my $subscription = { - periodicity => $freq_1i_1y, - firstacquidate => '1972-02-10', - countissuesperunit => 1, - }; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09'), 1, 'Feb 9 still 1' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10'), 2, 'Feb 10 goes to 2' ); - - # TEST CASE - 1 issue per 3 years - $subscription->{periodicity} = $freq_1i_3y; - $subscription->{firstacquidate} = '1972-02-20'; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19'), 1, 'Feb 19, 1975 still 1' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20'), 2, 'Feb 20, 1975 goes to 2' ); - - # TEST CASE - 5 issues per year - $subscription->{periodicity} = $freq_5i_1y; - $subscription->{firstacquidate} = '1972-02-29'; #leap year - $subscription->{countissuesperunit} = 1; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11'), 1, 'May 11 still 1' ); - $subscription->{countissuesperunit} = 2; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12'), 2, 'May 12 goes to 2' ); - $subscription->{countissuesperunit} = 5; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27'), 5, 'Feb 27 should still be 5' ); - $subscription->{countissuesperunit} = 1; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 6, 'Feb 28 goes to 6' ); - - # TEST CASE - 366 issues per year (hypothetical example) - # Testing prevention of divide by zero - $subscription->{periodicity} = $freq_366i_1y; - $subscription->{firstacquidate} = '1972-02-29'; #leap year - $subscription->{countissuesperunit} = 366; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27'), 366, 'Feb 27 still at 366' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 732, 'Feb 28 goes to 732' ); - +my $subscription = { + firstacquidate => '1970-01-01', + irregularity => '', + countissuesperunit => 1, }; - -subtest 'Tests for monthly frequencies' => sub { - plan tests => 8; - - # First add a few frequencies - my $freq_1i_5m = AddSubscriptionFrequency({ - description => "1 issue per 5 months", - unit => 'month', - issuesperunit => 1, - unitsperissue => 5, - }); - my $freq_4i_1m = AddSubscriptionFrequency({ - description => "4 issue per month", - unit => 'month', - issuesperunit => 4, - unitsperissue => 1, - }); - - # TEST CASE - 1 issue per 5 months - my $subscription = { - periodicity => $freq_1i_5m, - firstacquidate => '1972-02-10', - countissuesperunit => 1, - }; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09'), 1, 'Jul 9 still 1' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10'), 2, 'Jul 10 goes to 2' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09'), 3, 'May 9 still 3' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10'), 4, 'May 10 goes to 4' ); - - # TEST CASE - 4 issue per 1 months - $subscription = { - periodicity => $freq_4i_1m, - firstacquidate => '1972-02-22', - countissuesperunit => 1, - }; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28'), 1, 'Feb 28 still 1' ); - $subscription->{countissuesperunit} = 2; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29'), 2, 'Feb 29 goes to 2' ); - $subscription->{countissuesperunit} = 4; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21'), 4, 'Mar 21 still 4' ); - $subscription->{countissuesperunit} = 1; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22'), 5, 'Mar 22 goes to 5' ); - +my $issueNumber; + +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); +is( $issueNumber, '1' ); + +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); +is( $issueNumber, '2' ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); +is( $issueNumber, '3' ); + +# TEST CASE - 2 issues per day, no irregularity +$frequency = { + description => "Two issues per day", + unit => 'day', + issuesperunit => 2, + unitsperissue => 1, }; - -subtest 'Tests for weekly frequencies' => sub { - plan tests => 4; - - # First add a few frequencies - my $freq_1i_7w = AddSubscriptionFrequency({ - description => "1 issue per 7 weeks", - unit => 'week', - issuesperunit => 1, - unitsperissue => 7, - }); - my $freq_3i_1w = AddSubscriptionFrequency({ - description => "3 issues per week", - unit => 'week', - issuesperunit => 3, - unitsperissue => 1, - }); - - # TEST CASE - 1 issue per 7 weeks - my $subscription = { - periodicity => $freq_1i_7w, - firstacquidate => '1972-02-10', - countissuesperunit => 1, - }; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29'), 1, 'Mar 29 still 1' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30'), 2, 'Mar 30 goes to 2' ); - - # TEST CASE - 3 issue per 1 week - $subscription = { - periodicity => $freq_3i_1w, - firstacquidate => '1972-02-03', - countissuesperunit => 1, - }; - $subscription->{countissuesperunit} = 3; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09'), 3, 'Feb 9 still 3' ); - $subscription->{countissuesperunit} = 1; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10'), 4, 'Feb 10 goes to 4' ); +$subscription = { + firstacquidate => '1970-01-01', + irregularity => '', + countissuesperunit => 1, }; - -subtest 'Tests for dayly frequencies' => sub { - plan tests => 4; - - # First add a few frequencies - my $freq_1i_12d = AddSubscriptionFrequency({ - description => "1 issue per 12 days", - unit => 'day', - issuesperunit => 1, - unitsperissue => 12, - }); - my $freq_3i_1d = AddSubscriptionFrequency({ - description => "3 issues per day", - unit => 'day', - issuesperunit => 3, - unitsperissue => 1, - }); - - # TEST CASE - 1 issue per 12 days - my $subscription = { - periodicity => $freq_1i_12d, - firstacquidate => '1972-03-16', - countissuesperunit => 1, - }; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27'), 1, 'Mar 27 still 1' ); - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28'), 2, 'Mar 28 goes to 2' ); - - # TEST CASE - 3 issue per day - $subscription = { - periodicity => $freq_3i_1d, - firstacquidate => '1972-04-23', - countissuesperunit => 1, - }; - $subscription->{countissuesperunit} = 3; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01'), 27, 'May 1 still 27' ); - $subscription->{countissuesperunit} = 1; - is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02'), 28, 'May 2 goes to 28' ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); +is( $issueNumber, '1' ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); +is( $issueNumber, '3' ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); +is( $issueNumber, '5' ); + +$subscription->{countissuesperunit} = 2; +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); +is( $issueNumber, '2' ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); +is( $issueNumber, '4' ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); +is( $issueNumber, '6' ); + +# TEST CASE - 1 issue every 2 days, no irregularity +$frequency = { + description => "one issue every two days", + unit => 'day', + issuesperunit => 1, + unitsperissue => 2, }; - -$schema->storage->txn_rollback; +$subscription = { + firstacquidate => '1970-01-01', + irregularity => '', + countissuesperunit => 1, +}; +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); +is( $issueNumber, 1 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); +is( $issueNumber, 1 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); +is( $issueNumber, 2 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-04', $frequency ); +is( $issueNumber, 2 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-05', $frequency ); +is( $issueNumber, 3 ); + +# TEST CASE - 1 issue per week, no irregularity +$frequency = { + description => "one issue per week", + unit => 'week', + issuesperunit => 1, + unitsperissue => 1, +}; +$subscription = { + firstacquidate => '1970-01-01', + irregularity => '', + countissuesperunit => 1, +}; +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); +is( $issueNumber, 1 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); +is( $issueNumber, 1 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-08', $frequency ); +is( $issueNumber, 2 ); +$issueNumber = + C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-15', $frequency ); +is( $issueNumber, 3 ); + +$dbh->rollback; diff --git a/t/db_dependent/Serials/GetNextDate.t b/t/db_dependent/Serials/GetNextDate.t index a0422d7..bcbb76c 100644 --- a/t/db_dependent/Serials/GetNextDate.t +++ b/t/db_dependent/Serials/GetNextDate.t @@ -19,552 +19,525 @@ my $frequency = { issuesperunit => 1, unitsperissue => 1, }; -my $id = AddSubscriptionFrequency($frequency); my $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; my $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-03'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-04'); # TEST CASE - 1 issue per day, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '2;4', # Skip the second and fourth issues countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-03'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-05'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-06'); # TEST CASE - 2 issues per day, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "Two issues per day", unit => 'day', issuesperunit => 2, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-03'); # TEST CASE - 2 issues per day, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3;5;6', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-04'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-04'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-05'); # TEST CASE - 1 issue every 2 days, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "one issue every two days", unit => 'day', issuesperunit => 1, unitsperissue => 2, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-03'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-05'); # TEST CASE - 1 issue every 2 days, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-03'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-07'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-09'); # TEST CASE - 1 issue per week, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "one issue per week", unit => 'week', issuesperunit => 1, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-08'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-15'); # TEST CASE - 1 issue per week, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-08'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-22'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-29'); # TEST CASE - 1 issue every 2 weeks, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "one issue every 2 weeks", unit => 'week', issuesperunit => 1, unitsperissue => 2, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-15'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-29'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-02-12'); # TEST CASE - 1 issue every 2 weeks, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-15'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-02-12'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-02-26'); # TEST CASE - 2 issues per week, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "two issues per week", unit => 'week', issuesperunit => 2, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-04'); -$publisheddate = GetNextDate($subscription, $publisheddate); +# when more than 1 issue per week, date is automatically set to the same day of +# week as firstacquidate +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-08'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-11'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-15'); # TEST CASE - 2 issues per week, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3;5;6', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-04'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-11'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-22'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-25'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-29'); # TEST CASE - 6 issues per week, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "six issues per week", unit => 'week', issuesperunit => 6, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-06', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-07'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-08'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-09'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-10'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-11'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-13'); # TEST CASE - 6 issues per week, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-06', irregularity => '3;5;6', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-07'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-09'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-13'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-01-14'); # TEST CASE - 1 issue per month, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "1 issue per month", unit => 'month', issuesperunit => 1, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-02-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-03-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-04-01'); # TEST CASE - 1 issue per month, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '2;4', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-03-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-05-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-06-01'); # TEST CASE - 1 issue every 2 months, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "1 issue every 2 months", unit => 'month', issuesperunit => 1, unitsperissue => 2, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-03-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-05-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-07-01'); # TEST CASE - 1 issue every 2 months, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '2;3', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-07-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-09-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-11-01'); # TEST CASE - 2 issues per month, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "2 issues per month", unit => 'month', issuesperunit => 2, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-01-16', 'Jan 16'); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-02-01', 'Feb 1'); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-02-16', 'Feb 16'); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-03-01', 'Mar 1' ); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-01-16', 'January has 31 days'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-02-01'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-02-16', 'February has only 28 days'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-03-01'); # TEST CASE - 2 issues per month, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3;5;6', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-01-16', 'Jan 16' ); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-02-16', 'Feb 16 (skipping Feb 1)' ); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-04-01', 'Apr 1 (skipping Mar 1 and 16)' ); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-04-16', 'Apr 16' ); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-05-01', 'May 1' ); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-01-16', 'January has 31 days'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-02-16', 'February has only 28 days'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-04-01'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-04-16', 'April has 30 days'); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +is($publisheddate, '1970-05-01'); # TEST CASE - 1 issue per year, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "1 issue per year", unit => 'year', issuesperunit => 1, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1971-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1972-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1973-01-01'); # TEST CASE - 1 issue per year, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '2;4', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1972-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1974-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1975-01-01'); # TEST CASE - 1 issue every 2 years, no irregularity -$id = AddSubscriptionFrequency({ +$frequency = { description => "1 issue every 2 years", unit => 'year', issuesperunit => 1, unitsperissue => 2, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1972-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1974-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1976-01-01'); # TEST CASE - 1 issue every 2 years, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '2;4', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1974-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1978-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1980-01-01'); # Move publisheddate to Feb 29 (leap year 1980) $publisheddate = '1980-02-29'; -$publisheddate = GetNextDate( $subscription, $publisheddate ); +$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); is( $publisheddate, '1982-02-28', 'Test +2 year from Feb 29' ); # TEST CASE - 2 issues per year, no irregularity -$id = AddSubscriptionFrequency({ - description => "2 issues per year", +$frequency = { + description => "1 issue every 2 years", unit => 'year', issuesperunit => 2, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-07-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1971-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1971-07-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1972-01-01'); # TEST CASE - 2 issues per year, irregularities $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '3;5;6', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1970-07-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1971-07-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1973-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1973-07-02'); -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, '1974-01-01'); # TEST CASE - 9 issues per year, dates spread throughout month -$id = AddSubscriptionFrequency({ +$frequency = { description => "9 issues per year", unit => 'year', issuesperunit => 9, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-08-10', irregularity => '', countissuesperunit => 1, }; my @dates = ( $subscription->{firstacquidate} ); foreach(1..27) { - push @dates, GetNextDate( $subscription, $dates[-1] ); + push @dates, GetNextDate( $subscription, $dates[-1], $frequency ); } is( $dates[9], '1971-08-10', 'Freq 9/yr, 1 year passed' ); is( $dates[18], '1972-08-10', 'Freq 9/yr, 2 years passed (leap year)' ); is( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' ); # Keep (first) position in cycle, but shift back 9 days -is( GetNextDate( $subscription, '1973-08-01' ), '1973-09-10', 'Back 9 days, without annual correction' ); +is( GetNextDate( $subscription, '1973-08-01', $frequency ), '1973-09-10', 'Back 9 days, without annual correction' ); # Set position to last in cycle, and shift back 9 days; annual correction $subscription->{countissuesperunit} = 9; -is( GetNextDate( $subscription, '1973-08-01' ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' ); +is( GetNextDate( $subscription, '1973-08-01', $frequency ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' ); # TEST CASE - Irregular -$id = AddSubscriptionFrequency({ +$frequency = { description => "Irregular", unit => undef, issuesperunit => 1, unitsperissue => 1, -}); +}; $subscription = { - periodicity => $id, firstacquidate => '1970-01-01', irregularity => '', countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; # GetNextDate always return undef if subscription is irregular -$publisheddate = GetNextDate($subscription, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); is($publisheddate, undef); # GetNextDate returns undef if one of two first parameters is undef -$publisheddate = GetNextDate($subscription, undef); +$publisheddate = GetNextDate($subscription, undef, $frequency); is($publisheddate, undef); -$publisheddate = GetNextDate(undef, $subscription->{firstacquidate}); +$publisheddate = GetNextDate(undef, $subscription->{firstacquidate}, $frequency); is($publisheddate, undef); -$publisheddate = GetNextDate(undef, undef); +$publisheddate = GetNextDate(undef, undef, $frequency); is($publisheddate, undef); $schema->storage->txn_rollback; diff --git a/t/db_dependent/Serials/GetNextSeq.t b/t/db_dependent/Serials/GetNextSeq.t index fc6e3f2..c4152dd 100644 --- a/t/db_dependent/Serials/GetNextSeq.t +++ b/t/db_dependent/Serials/GetNextSeq.t @@ -43,16 +43,16 @@ my $subscription = { }; my $publisheddate = $subscription->{firstacquidate}; -my $seq = _next_seq($subscription, $pattern, $publisheddate); +my $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: 2'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: 4'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: 2'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: 3'); # TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7 @@ -79,19 +79,19 @@ $pattern = { $publisheddate = $subscription->{firstacquidate}; -$seq = _next_seq($subscription, $pattern, $publisheddate); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Tuesday'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Friday'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Sunday'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Monday'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Tuesday'); # TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2 @@ -118,19 +118,19 @@ $pattern = { $publisheddate = $subscription->{firstacquidate}; -$seq = _next_seq($subscription, $pattern, $publisheddate); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: March'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: September'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: January'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: March'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: May'); # TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3 @@ -157,19 +157,19 @@ $pattern = { $publisheddate = $subscription->{firstacquidate}; -$seq = _next_seq($subscription, $pattern, $publisheddate); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Summer'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Spring'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Fall'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Winter'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'X: Spring'); # TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4 @@ -196,19 +196,19 @@ $pattern = { $publisheddate = $subscription->{firstacquidate}; -$seq = _next_seq($subscription, $pattern, $publisheddate); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Y: 1, X: 2'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Y: 2, X: 1'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Y: 2, X: 3'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Y: 2, X: 4'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Y: 3, X: 1'); # TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4 @@ -235,44 +235,44 @@ $pattern = { $publisheddate = $subscription->{firstacquidate}; -$seq = _next_seq($subscription, $pattern, $publisheddate); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 1, Y: 1, X: 2'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 1, Y: 2, X: 1'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 1, Y: 2, X: 3'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 1, Y: 2, X: 4'); for (1..100) { - $publisheddate = GetNextDate($subscription, $publisheddate); - $seq = _next_seq($subscription, $pattern, $publisheddate); + $publisheddate = GetNextDate($subscription, $publisheddate, $frequency); + $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); } -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 4, Y: 4, X: 1'); # 110th is here -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 4, Y: 4, X: 3'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 4, Y: 4, X: 4'); -$publisheddate = GetNextDate($subscription, $publisheddate); -$seq = _next_seq($subscription, $pattern, $publisheddate); +$publisheddate = GetNextDate($subscription, $publisheddate, $frequency); +$seq = _next_seq($subscription, $pattern, $frequency, $publisheddate); is($seq, 'Z: 4, Y: 5, X: 1'); $dbh->rollback; sub _next_seq { - my ($subscription, $pattern, $publisheddate) = @_; + my ($subscription, $pattern, $frequency, $publisheddate) = @_; my $seq; ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2}, $subscription->{lastvalue3}, $subscription->{innerloop1}, $subscription->{innerloop2}, $subscription->{innerloop3}) = - GetNextSeq($subscription, $pattern, $publisheddate); + GetNextSeq($subscription, $pattern, $frequency, $publisheddate); return $seq; } -- 2.7.4