Bugzilla – Attachment 169441 Details for
Bug 35590
Add the translation of seasonal predictions for a chosen locale
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35590: Translate the seasons when testing the numbering pattern with a selected locale
Bug-35590-Translate-the-seasons-when-testing-the-n.patch (text/plain), 102.82 KB, created by
Alexandre Noel
on 2024-07-23 18:53:35 UTC
(
hide
)
Description:
Bug 35590: Translate the seasons when testing the numbering pattern with a selected locale
Filename:
MIME Type:
Creator:
Alexandre Noel
Created:
2024-07-23 18:53:35 UTC
Size:
102.82 KB
patch
obsolete
>From 8b1b6884e8450952e106eb91c6dc75b531c5b422 Mon Sep 17 00:00:00 2001 >From: Emily-Rose Francoeur <emily-rose.francoeur@inLibro.com> >Date: Tue, 19 Dec 2023 08:49:23 -0500 >Subject: [PATCH] Bug 35590: Translate the seasons when testing the numbering > pattern with a selected locale >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch allows you to test a numbering pattern that uses seasons or their abbreviations with the locale of your choice. Since DateTime() cannot handle translations for seasons, the patch relies on the translations in the .po files. Therefore, you need to have the .po file installed if you want to test this patch. > >TEST PLAN > >Prequisites: >Install the .po files for at least one language other than the one used in your staff interface (these files should be added to the misc/translator/po/ folder). Ensure that translations for seasons (Spring, Summer, Fall, and Winter) and their abbreviations (Spr, Sum, Fal, and Win) exist (these should be in the *-staff-prog.po). In my case, I use the .po files for French Canadian translations (fr-CA) because the translations for seasons and their abbreviations already exist. > >1) Apply the patch. >2) Navigate to "Serials > Manage numbering patterns" and click on the "Edit" button for the "Seasonal" pattern. >3) Under "Test prediction pattern": > - Set "First issue publication date" to today's date. > - Set "Subscription length" to "issues" and input "4". > - Choose the language you previously installed for "Locale" (in my case, it's "Français (French)"). > - Set "Begins with" to 0 (for X) and 2023 (for Y). >4) Click on the "Test pattern" button. > - Observe that the season names are displayed in the other language ("Printemps Ãté Automne Hiver" for me). >5) In the first section of the page, within the table, change "Formatting" to "Name of season (abbreviated)". >6) Click on the "Test pattern" button. > - Observe that the season abbreviated names are displayed in the other language ("Pri Ãté Aut Hiv" for me). >7) Navigate to a record detail page and click on "+ New" and then "New subscription". >8) Click on the "Next ->" button and then "OK". >9) Fill in the following fields: > - Set "First issue publication date" to today's date. > - Set "Frequency" to your preference. > - Set "Subscription length" to "issues" and input "4". > - Set "Subscription start date" to today's date. > - Select "Seasonal" for "Numbering pattern". > - Choose a language different from the one used in the staff interface for "Locale" (any language except English). > - Set "Begins with" to 0 (for Season) and 2023 (for Year). >10) Click on the "Test pattern" button. > - Observe that the season names are displayed in the other language ("Printemps Ãté Automne Hiver" for me). >11) Run the unit tests for Serials and GetNextSeq > - prove ./t/db_dependent/Serials.t > - prove ./t/db_dependent/Serials/GetNextSeq.t >--- > C4/Serials.pm | 119 ++- > .../modules/serials/showpredictionpattern.tt | 9 + > .../en/modules/serials/subscription-add.tt | 5 +- > .../serials/subscription-numberpatterns.tt | 14 +- > .../intranet-tmpl/prog/js/subscription-add.js | 11 +- > serials/showpredictionpattern.pl | 11 +- > serials/showpredictionpattern.pl.tdy | 218 ++++++ > serials/subscription-add.pl | 1 + > serials/subscription-add.pl.tdy | 527 +++++++++++++ > serials/subscription-numberpatterns.pl | 1 + > serials/subscription-numberpatterns.pl.tdy | 164 ++++ > t/db_dependent/Serials.t | 82 +- > t/db_dependent/Serials.t.tdy | 738 ++++++++++++++++++ > t/db_dependent/Serials/GetNextSeq.t | 1 + > t/db_dependent/Serials/GetNextSeq.t.tdy | 279 +++++++ > 15 files changed, 2158 insertions(+), 22 deletions(-) > create mode 100755 serials/showpredictionpattern.pl.tdy > create mode 100755 serials/subscription-add.pl.tdy > create mode 100755 serials/subscription-numberpatterns.pl.tdy > create mode 100755 t/db_dependent/Serials.t.tdy > create mode 100755 t/db_dependent/Serials/GetNextSeq.t.tdy > >diff --git a/C4/Serials.pm b/C4/Serials.pm >index ec88b0f3e6..f3aa86ce39 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -48,6 +48,8 @@ use Koha::Subscription::Histories; > use Koha::Subscriptions; > use Koha::Suggestions; > use Koha::TemplateUtils qw( process_tt ); >+use List::Util qw( first ); >+use Locale::PO; > > # Define statuses > use constant { >@@ -105,6 +107,7 @@ BEGIN { > > findSerialsByStatus > >+ GetSeasonsTranslations > ); > } > >@@ -859,6 +862,7 @@ sub GetNextSeq { > $newinnerloop1 = $subscription->{innerloop1} || 0; > $newinnerloop2 = $subscription->{innerloop2} || 0; > $newinnerloop3 = $subscription->{innerloop3} || 0; >+ my $translations = $subscription->{translations}; > my %calc; > foreach(qw/X Y Z/) { > $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); >@@ -897,15 +901,15 @@ sub GetNextSeq { > } > } > if($calc{'X'}) { >- my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); >+ my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale, $translations ); > $calculated =~ s/\{X\}/$newlastvalue1string/g; > } > if($calc{'Y'}) { >- my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); >+ my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale, $translations ); > $calculated =~ s/\{Y\}/$newlastvalue2string/g; > } > if($calc{'Z'}) { >- my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); >+ my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale, $translations ); > $calculated =~ s/\{Z\}/$newlastvalue3string/g; > } > >@@ -934,18 +938,20 @@ sub GetSeq { > > my $locale = $subscription->{locale}; > >+ my $translations = $subscription->{translations}; >+ > my $calculated = $pattern->{numberingmethod}; > > my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; >- $newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale) if ($pattern->{numbering1}); # reset counter if needed. >+ $newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale, $translations) if ($pattern->{numbering1}); # reset counter if needed. > $calculated =~ s/\{X\}/$newlastvalue1/g; > > my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; >- $newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale) if ($pattern->{numbering2}); # reset counter if needed. >+ $newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale, $translations) if ($pattern->{numbering2}); # reset counter if needed. > $calculated =~ s/\{Y\}/$newlastvalue2/g; > > my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; >- $newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed. >+ $newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale, $translations) if ($pattern->{numbering3}); # reset counter if needed. > $calculated =~ s/\{Z\}/$newlastvalue3/g; > return $calculated; > } >@@ -2501,7 +2507,7 @@ num_type can take : > =cut > > sub _numeration { >- my ($value, $num_type, $locale) = @_; >+ my ($value, $num_type, $locale, $translations) = @_; > $value ||= 0; > $num_type //= ''; > $locale ||= 'en'; >@@ -2529,13 +2535,11 @@ sub _numeration { > ? $dt->format_cldr( "LLLL" ) > : $dt->strftime("%b"); > } elsif ( $num_type =~ /^season$/ ) { >- my @seasons= qw( Spring Summer Fall Winter ); > $value = $value % 4; >- $string = $seasons[$value]; >+ $string = $translations->{seasons}->[$value]; > } elsif ( $num_type =~ /^seasonabrv$/ ) { >- my @seasonsabrv= qw( Spr Sum Fal Win ); > $value = $value % 4; >- $string = $seasonsabrv[$value]; >+ $string = $translations->{seasonsabrv}->[$value]; > } else { > $string = $value; > } >@@ -2597,6 +2601,58 @@ sub ReopenSubscription { > $sth->execute( EXPECTED, $subscriptionid, STOPPED ); > } > >+=head2 GetSeasonsTranslations >+ >+Provide translations for the seasons and their abbreviations for the specified locale >+ >+=cut >+ >+sub GetSeasonsTranslations { >+ my ( $need_seasons, $need_seasonsabrv, $subtag ) = @_; >+ my @seasons = qw( Spring Summer Fall Winter ); >+ my @seasonsabrv = qw( Spr Sum Fal Win ); >+ my @error_messages = qw(); >+ >+ my @dirs = ( >+ C4::Context->config('intranetdir') . '/misc/translator/po', >+ C4::Context->config('intranetdir') . '/../../misc/translator/po', >+ ); >+ >+ my $dir = first { -d } @dirs; >+ >+ if ($dir) { >+ my @po_paths = glob("$dir/$subtag*staff-prog.po"); >+ if (@po_paths) { >+ my $po_path = $po_paths[0]; >+ my $po_filename = ( $po_path =~ s/$dir\///gr ); >+ my $po_data = Locale::PO->load_file_ashash( $po_path, 'utf8' ); >+ >+ if ($need_seasons) { >+ my $response = _translate( $po_data, @seasons ); >+ @seasons = @{ $response->{translations} }; >+ @error_messages = >+ ( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); >+ } >+ >+ if ($need_seasonsabrv) { >+ my $response = _translate( $po_data, @seasonsabrv ); >+ @seasonsabrv = @{ $response->{translations} }; >+ @error_messages = >+ ( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); >+ } >+ } else { >+ push( >+ @error_messages, >+ "No translation file found for $subtag. Ensure that the translation files for $subtag are installed." >+ ); >+ } >+ } else { >+ push( @error_messages, "The PO directory has not been found. There is a problem in your Koha installation." ); >+ } >+ >+ return { seasons => \@seasons, seasonsabrv => \@seasonsabrv, error_messages => \@error_messages }; >+} >+ > =head2 subscriptionCurrentlyOnOrder > > $bool = subscriptionCurrentlyOnOrder( $subscriptionid ); >@@ -2691,6 +2747,47 @@ sub _can_do_on_subscription { > return 0; > } > >+=head2 _translate >+ >+Provide translations for the given words based on the provided data >+ >+=cut >+ >+sub _translate { >+ my ( $data, @words ) = @_; >+ >+ my @translations = qw(); >+ my @error_messages = qw(); >+ >+ for my $word (@words) { >+ my $regex = qr/^"$word"$|\%s$word\%s/; >+ my @msgids = grep /$regex/, keys %{$data}; >+ my $translation = ""; >+ >+ while ( ( $translation eq "" ) && ( my $msgid = shift(@msgids) ) ) { >+ next unless ( $data->{$msgid}->reference =~ /serials/ ); >+ my $msgstr = $data->{$msgid}->msgstr; >+ my @ids = split( /\%s/, $msgid ); >+ my @strs = split( /\%s/, $msgstr ); >+ >+ next unless ( scalar @ids == scalar @strs ); >+ >+ my $idx = first { $ids[$_] eq $word || $ids[$_] eq $msgid } 0 .. $#ids; >+ $translation = Locale::PO->dequote( $strs[$idx] ) if ( defined $idx ); >+ } >+ >+ if ( $translation eq "" ) { >+ push( @translations, $word ); >+ push( @error_messages, "The translation for $word doesn't exist in the file \%s" ); >+ next; >+ } >+ >+ push( @translations, $translation ); >+ } >+ >+ return { translations => \@translations, error_messages => \@error_messages }; >+} >+ > =head2 findSerialsByStatus > > @serials = findSerialsByStatus($status, $subscriptionid); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >index ea6e6ab46d..bd20729690 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >@@ -84,6 +84,15 @@ > </tbody> > </table> > >+[% IF (error_messages) %] >+ <div class="alert alert-warning"> >+ <h4 class="alert-heading"><i class="bi-exclamation-triangle-fill"></i> Warning</h4> >+ [% FOREACH error_message IN error_messages %] >+ <p>[% error_message | html %]</p> >+ [% END %] >+ </div> >+[% END %] >+ > <fieldset class="action"> > <button class="btn btn-default btn-sm" id="hidepredictionpattern">Done</button> > </fieldset> >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 2c6705656e..6eb775a93d 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 >@@ -383,12 +383,13 @@ fieldset.rows table { clear: none; margin: 0; } > <option value=""></option> > [% FOREACH l IN locales %] > [% IF l.language == locale %] >- <option value="[% l.language | html %]" selected="selected">[% l.description | html %]</option> >+ <option value="[% l.language | html %]" data-subtag="[% l.subtag | html %]" selected="selected">[% l.description | html %]</option> > [% ELSE %] >- <option value="[% l.language | html %]">[% l.description | html %]</option> >+ <option value="[% l.language | html %]" data-subtag="[% l.subtag | html %]">[% l.description | html %]</option> > [% END %] > [% END %] > </select> >+ <input type="hidden" id="subtag" name="subtag" value=""> > <div class="hint">If empty, English is used</div> > </li> > <li id="more_options"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt >index a358f68f7e..2feee471d1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt >@@ -210,10 +210,11 @@ > <select id="locale" name="locale"> > <option value=""></option> > [% FOREACH locale IN locales %] >- <option value="[% locale.language | html %]">[% locale.description | html %]</option> >+ <option value="[% locale.language | html %]" data-subtag="[% locale.subtag | html %]">[% locale.description | html %]</option> > [% END %] > </select> > <span class="hint">If empty, English is used</span> >+ <input type="hidden" id="subtag" name="subtag" value=""> > </li> > </ol> > <table> >@@ -334,6 +335,10 @@ > [% INCLUDE 'calendar.inc' %] > [% INCLUDE 'datatables.inc' %] > <script> >+ function setSubtag () { >+ $("#subtag").val($("#locale").find(':selected').data('subtag')); >+ } >+ > function confirmDelete() { > return confirm(_("Are you sure you want to delete this numbering pattern?")); > } >@@ -367,7 +372,7 @@ > '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', 'subtag' > ]; > for(i in ajaxParams) { > var param = ajaxParams[i]; >@@ -410,6 +415,11 @@ > $("#test_pattern").on("click",function(){ > testPattern(); > }); >+ $("#locale").on("change", function() { >+ setSubtag(); >+ }); >+ >+ setSubtag(); > }); > </script> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >index 927c5d71a3..21a2a5ab18 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >@@ -329,7 +329,7 @@ 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', 'subtag', > 'sfdescription', 'unitsperissue', 'issuesperunit', 'unit' > ]; > for(i in ajaxParams) { >@@ -543,6 +543,10 @@ function mana_comment_close(){ > $("#new_mana_comment").hide(); > } > >+function setSubtag () { >+ $("#subtag").val($("#locale").find(':selected').data('subtag')); >+} >+ > function showPredictionPatternTest( data ){ > $("#displayexample").html(data).show(); > $("#page_2 > div").attr("class","col-xs-6"); >@@ -744,4 +748,9 @@ $(document).ready(function() { > $(".use_items").css('display', display).find("select").val("") > }); > >+ $("#locale").on("change", function() { >+ setSubtag(); >+ }); >+ >+ setSubtag(); > }); >diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl >index 9fc801102b..28884a4ec1 100755 >--- a/serials/showpredictionpattern.pl >+++ b/serials/showpredictionpattern.pl >@@ -34,7 +34,7 @@ use CGI qw ( -utf8 ); > use Date::Calc qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days ); > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); >-use C4::Serials qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq ); >+use C4::Serials qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq GetSeasonsTranslations ); > use C4::Serials::Frequency; > use Koha::DateUtils qw( dt_from_string ); > >@@ -97,6 +97,13 @@ $enddate = dt_from_string($enddate)->ymd if $enddate; > $nextacquidate = $nextacquidate ? dt_from_string($nextacquidate)->ymd : $firstacquidate; > my $date = $nextacquidate; > >+my $need_seasons = grep { $_ =~ /^season$/ } %pattern; >+my $need_seasonsabrv = grep { $_ =~ /^seasonabrv$/ } %pattern; >+my $subtag = scalar $input->param('subtag'); >+ >+my $translations; >+$translations = GetSeasonsTranslations( $need_seasons, $need_seasonsabrv, $subtag ) if ( $need_seasons || $need_seasonsabrv ); >+ > my %subscription = ( > locale => scalar $input->param('locale') // '', > lastvalue1 => scalar $input->param('lastvalue1') // '', >@@ -108,6 +115,7 @@ my %subscription = ( > irregularity => '', > countissuesperunit => 1, > firstacquidate => $firstacquidate, >+ translations => $translations, > ); > > my $issuenumber; >@@ -178,6 +186,7 @@ while( $i < 1000 ) { > > $template->param( > predictions_loop => \@predictions_loop, >+ error_messages => \@{ $translations->{error_messages} }, > ); > > if ( $frequency->{unit} and not $custompattern ) { >diff --git a/serials/showpredictionpattern.pl.tdy b/serials/showpredictionpattern.pl.tdy >new file mode 100755 >index 0000000000..9e2ff98591 >--- /dev/null >+++ b/serials/showpredictionpattern.pl.tdy >@@ -0,0 +1,218 @@ >+#!/usr/bin/perl >+ >+# Copyright 2011-2013 Biblibre SARL >+# >+# 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 <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+showpredictionpattern.pl >+ >+=head1 DESCRIPTION >+ >+This script calculate numbering of serials based on numbering pattern, and >+publication date, based on frequency and first publication date. >+ >+=cut >+ >+use Modern::Perl; >+ >+use CGI qw ( -utf8 ); >+use Date::Calc qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days ); >+use C4::Auth qw( get_template_and_user ); >+use C4::Output qw( output_html_with_http_headers ); >+use C4::Serials >+ qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq GetSeasonsTranslations ); >+use C4::Serials::Frequency; >+use Koha::DateUtils qw( dt_from_string ); >+ >+my $input = CGI->new; >+my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( >+ { >+ template_name => 'serials/showpredictionpattern.tt', >+ query => $input, >+ type => 'intranet', >+ flagsrequired => { 'serials' => '*' }, >+ } >+); >+ >+my $subscriptionid = $input->param('subscriptionid'); >+my $frequencyid = $input->param('frequency'); >+my $firstacquidate = $input->param('firstacquidate'); >+my $nextacquidate = $input->param('nextacquidate'); >+my $enddate = $input->param('to'); >+my $subtype = $input->param('subtype'); >+my $sublength = $input->param('sublength'); >+my $custompattern = $input->param('custompattern'); >+ >+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') // '', >+ numbering1 => scalar $input->param('numbering1') // '', >+ numbering2 => scalar $input->param('numbering2') // '', >+ numbering3 => scalar $input->param('numbering3') // '', >+ add1 => scalar $input->param('add1') // '', >+ add2 => scalar $input->param('add2') // '', >+ add3 => scalar $input->param('add3') // '', >+ whenmorethan1 => scalar $input->param('whenmorethan1') // '', >+ whenmorethan2 => scalar $input->param('whenmorethan2') // '', >+ whenmorethan3 => scalar $input->param('whenmorethan3') // '', >+ setto1 => scalar $input->param('setto1') // '', >+ setto2 => scalar $input->param('setto2') // '', >+ setto3 => scalar $input->param('setto3') // '', >+ every1 => scalar $input->param('every1') // '', >+ every2 => scalar $input->param('every2') // '', >+ every3 => scalar $input->param('every3') // '', >+); >+ >+$firstacquidate = $firstacquidate ? dt_from_string($firstacquidate)->ymd : dt_from_string->ymd; >+ >+$enddate = dt_from_string($enddate)->ymd if $enddate; >+ >+$nextacquidate = $nextacquidate ? dt_from_string($nextacquidate)->ymd : $firstacquidate; >+my $date = $nextacquidate; >+ >+my $need_seasons = grep { $_ =~ /^season$/ } %pattern; >+my $need_seasonsabrv = grep { $_ =~ /^seasonabrv$/ } %pattern; >+my $subtag = scalar $input->param('subtag'); >+ >+my $translations; >+$translations = GetSeasonsTranslations( $need_seasons, $need_seasonsabrv, $subtag ) >+ if ( $need_seasons || $need_seasonsabrv ); >+ >+my %subscription = ( >+ locale => scalar $input->param('locale') // '', >+ lastvalue1 => scalar $input->param('lastvalue1') // '', >+ lastvalue2 => scalar $input->param('lastvalue2') // '', >+ lastvalue3 => scalar $input->param('lastvalue3') // '', >+ innerloop1 => scalar $input->param('innerloop1') // '', >+ innerloop2 => scalar $input->param('innerloop2') // '', >+ innerloop3 => scalar $input->param('innerloop3') // '', >+ irregularity => '', >+ countissuesperunit => 1, >+ firstacquidate => $firstacquidate, >+ translations => $translations, >+); >+ >+my $issuenumber; >+if ( defined $subscriptionid ) { >+ ($issuenumber) = C4::Serials::GetFictiveIssueNumber( \%subscription, $date, $frequency ); >+} else { >+ $issuenumber = 1; >+} >+ >+my @predictions_loop; >+my ($calculated) = GetSeq( \%subscription, \%pattern ); >+push @predictions_loop, { >+ number => $calculated, >+ publicationdate => $date, >+ issuenumber => $issuenumber, >+ dow => Day_of_Week( split /-/, $date ), >+}; >+my @irreg = (); >+if ( defined $subscriptionid ) { >+ @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid); >+ while ( @irreg && $issuenumber > $irreg[0] ) { >+ shift @irreg; >+ } >+ if ( @irreg && $issuenumber == $irreg[0] ) { >+ $predictions_loop[0]->{'not_published'} = 1; >+ shift @irreg; >+ } >+} >+ >+my $i = 1; >+while ( $i < 1000 ) { >+ my %line; >+ >+ if ( defined $date ) { >+ $date = GetNextDate( \%subscription, $date, $frequency ); >+ } >+ if ( defined $date ) { >+ $line{'publicationdate'} = $date; >+ $line{'dow'} = Day_of_Week( split /-/, $date ); >+ } >+ >+ # Check if we don't have exceed end date >+ if ($sublength) { >+ if ( $subtype eq "issues" && $i >= $sublength ) { >+ last; >+ } elsif ( $subtype eq "weeks" >+ && $date >+ && Delta_Days( split( /-/, $date ), Add_Delta_Days( split( /-/, $firstacquidate ), 7 * $sublength - 1 ) ) < >+ 0 ) >+ { >+ last; >+ } elsif ( $subtype eq "months" >+ && $date >+ && ( Delta_Days( split( /-/, $date ), Add_Delta_YM( split( /-/, $firstacquidate ), 0, $sublength ) ) - 1 ) >+ < 0 ) >+ { >+ last; >+ } >+ } >+ if ( $enddate && $date && Delta_Days( split( /-/, $date ), split( /-/, $enddate ) ) <= 0 ) { >+ last; >+ } >+ >+ ( >+ $calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, >+ $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'} >+ ) = GetNextSeq( \%subscription, \%pattern, $frequency ); >+ $issuenumber++; >+ $line{'number'} = $calculated; >+ $line{'issuenumber'} = $issuenumber; >+ if ( @irreg && $issuenumber == $irreg[0] ) { >+ $line{'not_published'} = 1; >+ shift @irreg; >+ } >+ push @predictions_loop, \%line; >+ >+ $i++; >+} >+ >+$template->param( >+ predictions_loop => \@predictions_loop, >+ error_messages => \@{ $translations->{error_messages} }, >+); >+ >+if ( $frequency->{unit} and not $custompattern ) { >+ $template->param( ask_for_irregularities => 1 ); >+ if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) { >+ $template->param( daily_options => 1 ); >+ } >+} >+ >+if ( ( $date && $enddate && $date ne $enddate ) >+ or ( $subtype eq 'issues' && $i < $sublength ) ) >+{ >+ $template->param( not_consistent_end_date => 1 ); >+} >+ >+output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl >index 13a57ecb91..5671f2cb5c 100755 >--- a/serials/subscription-add.pl >+++ b/serials/subscription-add.pl >@@ -225,6 +225,7 @@ if ($op eq 'cud-addsubscription') { > my $languages = [ map { > { > language => $_->{iso639_2_code}, >+ subtag => $_->{subtag}, > description => $_->{language_description} || $_->{language} > } > } @{ C4::Languages::getAllLanguages() } ]; >diff --git a/serials/subscription-add.pl.tdy b/serials/subscription-add.pl.tdy >new file mode 100755 >index 0000000000..677e364647 >--- /dev/null >+++ b/serials/subscription-add.pl.tdy >@@ -0,0 +1,527 @@ >+#!/usr/bin/perl >+ >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use CGI qw ( -utf8 ); >+use Date::Calc qw( Add_Delta_Days Add_Delta_YM ); >+use C4::Koha qw( GetAuthorisedValues ); >+use C4::Auth qw( get_template_and_user ); >+use C4::Output qw( output_and_exit output_html_with_http_headers ); >+use C4::Context; >+use C4::Serials >+ qw( GetSubscription GetNextExpected GetSerials GetSubscriptionLength NewSubscription ModNextExpected ModSubscription ); >+use C4::Serials::Frequency; >+use C4::Serials::Numberpattern; >+use C4::Letters qw( GetLetters ); >+use Koha::AdditionalFields; >+use Koha::Biblios; >+use Koha::DateUtils qw( output_pref ); >+use Koha::ItemTypes; >+use Carp qw( carp ); >+ >+use Koha::Subscription::Numberpattern; >+use Koha::Subscription::Frequency; >+use Koha::SharedContent; >+ >+our $query = CGI->new; >+my $op = $query->param('op') || ''; >+my $dbh = C4::Context->dbh; >+my $sub_length; >+ >+# Permission needed if it is a modification : edit_subscription >+# Permission needed otherwise (nothing or dup) : create_subscription >+my $permission = ( $op eq 'modify' || $op eq 'cud-modsubscription' ) ? "edit_subscription" : "create_subscription"; >+ >+our ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "serials/subscription-add.tt", >+ query => $query, >+ type => "intranet", >+ flagsrequired => { serials => $permission }, >+ } >+); >+ >+my $sub_on; >+ >+my $subs; >+our $firstissuedate; >+ >+my $mana_url = C4::Context->config('mana_config'); >+$template->param( 'mana_url' => $mana_url ); >+my $subscriptionid = $query->param('subscriptionid'); >+ >+if ( $op eq 'modify' || $op eq 'dup' || $op eq 'cud-modsubscription' ) { >+ >+ $subs = GetSubscription($subscriptionid); >+ >+ output_and_exit( $query, $cookie, $template, 'unknown_subscription' ) >+ unless $subs; >+ >+ ## FIXME : Check rights to edit if mod. Could/Should display an error message. >+ if ( $subs->{'cannotedit'} && $op eq 'modify' ) { >+ carp "Attempt to modify subscription $subscriptionid by " . C4::Context->userenv->{'id'} . " not allowed"; >+ print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); >+ } >+ $firstissuedate = $subs->{firstacquidate} || ''; # in iso format. >+ if ( !defined $subs->{letter} ) { >+ $subs->{letter} = q{}; >+ } >+ my $nextexpected = GetNextExpected($subscriptionid); >+ $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate} eq $firstissuedate; >+ $subs->{nextacquidate} = $nextexpected->{planneddate} if ( $op eq 'modify' ); >+ unless ( $op eq 'cud-modsubscription' ) { >+ foreach my $length_unit (qw(numberlength weeklength monthlength)) { >+ if ( $subs->{$length_unit} ) { >+ $sub_length = $subs->{$length_unit}; >+ $sub_on = $length_unit; >+ last; >+ } >+ } >+ >+ $template->param( %{$subs} ); >+ $template->param( >+ $op => 1, >+ "subtype_$sub_on" => 1, >+ sublength => $sub_length, >+ history => ( $op eq 'modify' ), >+ firstacquiyear => substr( $firstissuedate, 0, 4 ), >+ ); >+ >+ if ( $op eq 'modify' ) { >+ my ($serials_number) = GetSerials($subscriptionid); >+ if ( $serials_number > 1 ) { >+ $template->param( more_than_one_serial => 1 ); >+ } >+ } >+ } >+ >+ if ( $op eq 'dup' ) { >+ my $dont_copy_fields = C4::Context->preference('SubscriptionDuplicateDroppedInput'); >+ my @fields_id = map { fieldid => $_ }, split '\|', $dont_copy_fields; >+ $template->param( dont_export_field_loop => \@fields_id ); >+ } >+ >+ my $letters = get_letter_loop( $subs->{letter} ); >+ $template->param( letterloop => $letters ); >+ >+} >+ >+my $locations_loop = GetAuthorisedValues("LOC"); >+my $ccodes_loop = GetAuthorisedValues("CCODE"); >+ >+$template->param( >+ branchcode => $subs->{branchcode}, >+ locations_loop => $locations_loop, >+ ccodes_loop => $ccodes_loop >+); >+ >+my @additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list; >+my %additional_field_values; >+if ($subscriptionid) { >+ my $subscription = Koha::Subscriptions->find($subscriptionid); >+ foreach my $value ( $subscription->additional_field_values->as_list ) { >+ $additional_field_values{ $value->field_id } = $value->value; >+ } >+} >+ >+$template->param( >+ additional_fields => \@additional_fields, >+ additional_field_values => \%additional_field_values, >+); >+ >+my $typeloop = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; >+ >+# FIXME We should use the translated_description for item types >+my @typearg = >+ map { >+ { >+ code => $_, value => $typeloop->{$_}{'description'}, >+ selected => ( ( $subs->{itemtype} and $_ eq $subs->{itemtype} ) ? "selected=\"selected\"" : "" ), >+ } >+ } sort keys %{$typeloop}; >+my @previoustypearg = >+ map { >+ { >+ code => $_, value => $typeloop->{$_}{'description'}, selected => >+ ( ( $subs->{previousitemtype} and $_ eq $subs->{previousitemtype} ) ? "selected=\"selected\"" : "" ), >+ } >+ } sort keys %{$typeloop}; >+ >+$template->param( >+ typeloop => \@typearg, >+ previoustypeloop => \@previoustypearg, >+ locations_loop => $locations_loop, >+); >+ >+# prepare template variables common to all $op conditions: >+$template->param( 'makePreviousSerialAvailable' => 1 ) if ( C4::Context->preference('makePreviousSerialAvailable') ); >+ >+if ( $op !~ /^mod/ ) { >+ my $letters = get_letter_loop(); >+ $template->param( letterloop => $letters ); >+} >+ >+if ( $op eq 'cud-addsubscription' ) { >+ redirect_add_subscription(); >+} elsif ( $op eq 'cud-modsubscription' ) { >+ redirect_mod_subscription(); >+} else { >+ >+ $template->param( >+ subtypes => [qw( numberlength weeklength monthlength )], >+ subtype => $sub_on, >+ ); >+ >+ if ( $op ne 'cud-modsubscription' && $op ne 'dup' && $op ne 'modify' ) { >+ my $letters = get_letter_loop(); >+ $template->param( letterloop => $letters ); >+ } >+ >+ my $new_biblionumber = $query->param('biblionumber_for_new_subscription'); >+ if ( defined $new_biblionumber ) { >+ my $biblio = Koha::Biblios->find($new_biblionumber); >+ if ( defined $biblio ) { >+ $template->param( bibnum => $new_biblionumber ); >+ $template->param( bibliotitle => $biblio->title ); >+ } >+ } >+ >+ $template->param( ( uc( C4::Context->preference("marcflavour") ) ) => 1 ); >+ >+ my @frequencies = GetSubscriptionFrequencies; >+ my @frqloop; >+ foreach my $freq (@frequencies) { >+ my $selected = 0; >+ $selected = 1 if ( $subs->{periodicity} and $freq->{id} eq $subs->{periodicity} ); >+ my $row = { >+ id => $freq->{'id'}, >+ selected => $selected, >+ label => $freq->{'description'}, >+ }; >+ push @frqloop, $row; >+ } >+ $template->param( frequencies => \@frqloop ); >+ >+ my @numpatterns = GetSubscriptionNumberpatterns; >+ my @numberpatternloop; >+ foreach my $numpattern (@numpatterns) { >+ my $selected = 0; >+ $selected = 1 if ( $subs->{numberpattern} and $numpattern->{id} eq $subs->{numberpattern} ); >+ my $row = { >+ id => $numpattern->{'id'}, >+ selected => $selected, >+ label => $numpattern->{'label'}, >+ }; >+ push @numberpatternloop, $row; >+ } >+ $template->param( numberpatterns => \@numberpatternloop ); >+ >+ my $languages = [ >+ map { >+ { >+ language => $_->{iso639_2_code}, >+ subtag => $_->{subtag}, >+ description => $_->{language_description} || $_->{language} >+ } >+ } @{ C4::Languages::getAllLanguages() } >+ ]; >+ >+ $template->param( locales => $languages ); >+ >+ my @bookseller_ids = Koha::Acquisition::Booksellers->search->get_column('id'); >+ $template->param( bookseller_ids => \@bookseller_ids ); >+ >+ output_html_with_http_headers $query, $cookie, $template->output; >+} >+ >+sub get_letter_loop { >+ my ($selected_lettercode) = @_; >+ $selected_lettercode //= ''; >+ my $letters = GetLetters( { module => 'serial' } ); >+ return [ >+ map { >+ { >+ value => $_->{code}, >+ lettername => $_->{name}, >+ ( $_->{code} eq $selected_lettercode ? ( selected => 1 ) : () ), >+ } >+ } @$letters >+ ]; >+} >+ >+sub _guess_enddate { >+ my ( $startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength ) = @_; >+ my ( $year, $month, $day ); >+ my $enddate; >+ if ( $numberlength != 0 ) { >+ my $frequency = GetSubscriptionFrequency($frequencyid); >+ if ( $frequency->{'unit'} eq 'day' ) { >+ ( $year, $month, $day ) = Add_Delta_Days( >+ split( /-/, $startdate_iso ), >+ $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'} >+ ); >+ } elsif ( $frequency->{'unit'} eq 'week' ) { >+ ( $year, $month, $day ) = Add_Delta_Days( >+ split( /-/, $startdate_iso ), >+ $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'} >+ ); >+ } elsif ( $frequency->{'unit'} eq 'month' ) { >+ ( $year, $month, $day ) = Add_Delta_YM( >+ split( /-/, $startdate_iso ), 0, >+ $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'} >+ ); >+ } elsif ( $frequency->{'unit'} eq 'year' ) { >+ ( $year, $month, $day ) = Add_Delta_YM( >+ split( /-/, $startdate_iso ), >+ $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0 >+ ); >+ } >+ } elsif ( $weeklength != 0 ) { >+ ( $year, $month, $day ) = Add_Delta_Days( split( /-/, $startdate_iso ), $weeklength * 7 ); >+ } elsif ( $monthlength != 0 ) { >+ ( $year, $month, $day ) = Add_Delta_YM( split( /-/, $startdate_iso ), 0, $monthlength ); >+ } >+ if ( defined $year ) { >+ $enddate = sprintf( "%04d-%02d-%02d", $year, $month, $day ); >+ } else { >+ undef $enddate; >+ } >+ return $enddate; >+} >+ >+sub redirect_add_subscription { >+ my $periodicity = $query->param('frequency'); >+ if ( $periodicity 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; >+ } >+ my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing( { $query->Vars } ); >+ >+ 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 @irregularity = $query->multi_param('irregularity'); >+ my $locale = $query->param('locale'); >+ my $graceperiod = $query->param('graceperiod') || 0; >+ >+ my $subtype = $query->param('subtype'); >+ my $sublength = $query->param('sublength'); >+ my ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength ); >+ my $add1 = $query->param('add1'); >+ my $lastvalue1 = $query->param('lastvalue1'); >+ my $innerloop1 = $query->param('innerloop1'); >+ my $innerloop2 = $query->param('innerloop2'); >+ my $lastvalue2 = $query->param('lastvalue2'); >+ my $lastvalue3 = $query->param('lastvalue3'); >+ my $innerloop3 = $query->param('innerloop3'); >+ my $status = 1; >+ my $biblionumber = $query->param('biblionumber'); >+ my $callnumber = $query->param('callnumber'); >+ my $notes = $query->param('notes'); >+ my $internalnotes = $query->param('internalnotes'); >+ my $letter = $query->param('letter'); >+ my $manualhistory = $query->param('manualhist') ? 1 : 0; >+ my $serialsadditems = $query->param('serialsadditems'); >+ my $staffdisplaycount = $query->param('staffdisplaycount'); >+ my $opacdisplaycount = $query->param('opacdisplaycount'); >+ my $location = $query->param('location'); >+ my $itemtype = $query->param('itemtype'); >+ my $previousitemtype = $query->param('previousitemtype'); >+ my $skip_serialseq = $query->param('skip_serialseq'); >+ my $ccode = $query->param('ccode'); >+ my $published_on_template = $query->param('published_on_template'); >+ >+ my $mana_id; >+ if ( $query->param('mana_id') ne "" ) { >+ $mana_id = $query->param('mana_id'); >+ Koha::SharedContent::increment_entity_value( "subscription", $mana_id, "nbofusers" ); >+ } >+ >+ 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' } ); >+ >+ if ( !defined $enddate || $enddate eq '' ) { >+ if ( $subtype eq "issues" ) { >+ $enddate = _guess_enddate( $firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength ); >+ } else { >+ $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength ); >+ } >+ } >+ my $subscriptionid = NewSubscription( >+ $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, >+ $startdate, $periodicity, $numberlength, $weeklength, >+ $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, >+ $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, >+ join( ";", @irregularity ), $numberpattern, $locale, $callnumber, >+ $manualhistory, $internalnotes, $serialsadditems, >+ $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, >+ $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template >+ ); >+ if ( ( C4::Context->preference('Mana') == 1 ) >+ and ( grep { $_ eq "subscription" } split( /,/, C4::Context->preference('AutoShareWithMana') ) ) ) >+ { >+ my $result = Koha::SharedContent::send_entity( >+ $query->param('mana_language') || '', $loggedinuser, $subscriptionid, >+ 'subscription' >+ ); >+ $template->param( mana_msg => $result->{msg} ); >+ } >+ >+ my @additional_fields; >+ my $biblio = Koha::Biblios->find($biblionumber); >+ my $subscription_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } ); >+ while ( my $field = $subscription_fields->next ) { >+ my $value = $query->param( 'additional_field_' . $field->id ); >+ push @additional_fields, { >+ id => $field->id, >+ value => $value, >+ }; >+ } >+ Koha::Subscriptions->find($subscriptionid)->set_additional_fields( \@additional_fields ); >+ >+ print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); >+ return; >+} >+ >+sub redirect_mod_subscription { >+ my $subscriptionid = $query->param('subscriptionid'); >+ my @irregularity = $query->multi_param('irregularity'); >+ my $auser = $query->param('user'); >+ my $librarian => scalar $query->param('librarian'), >+ my $branchcode = $query->param('branchcode'); >+ my $cost = $query->param('cost'); >+ my $aqbooksellerid = $query->param('aqbooksellerid'); >+ my $biblionumber = $query->param('biblionumber'); >+ my $aqbudgetid = $query->param('aqbudgetid'); >+ >+ 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' } ); >+ >+ my $nextacquidate = $query->param('nextacquidate'); >+ $nextacquidate = >+ $nextacquidate >+ ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } ) >+ : $firstacquidate; >+ >+ my $periodicity = $query->param('frequency'); >+ if ( $periodicity 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; >+ } >+ my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing( { $query->Vars } ); >+ >+ my $subtype = $query->param('subtype'); >+ my $sublength = $query->param('sublength'); >+ my ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength ); >+ my $locale = $query->param('locale'); >+ my $lastvalue1 = $query->param('lastvalue1'); >+ my $innerloop1 = $query->param('innerloop1'); >+ my $lastvalue2 = $query->param('lastvalue2'); >+ my $innerloop2 = $query->param('innerloop2'); >+ my $lastvalue3 = $query->param('lastvalue3'); >+ my $innerloop3 = $query->param('innerloop3'); >+ my $status = 1; >+ my $callnumber = $query->param('callnumber'); >+ my $notes = $query->param('notes'); >+ my $internalnotes = $query->param('internalnotes'); >+ my $letter = $query->param('letter'); >+ my $manualhistory = $query->param('manualhist') ? 1 : 0; >+ my $serialsadditems = $query->param('serialsadditems'); >+ my $staffdisplaycount = $query->param('staffdisplaycount'); >+ my $opacdisplaycount = $query->param('opacdisplaycount'); >+ my $graceperiod = $query->param('graceperiod') || 0; >+ my $location = $query->param('location'); >+ my $itemtype = $query->param('itemtype'); >+ my $previousitemtype = $query->param('previousitemtype'); >+ my $skip_serialseq = $query->param('skip_serialseq'); >+ my $ccode = $query->param('ccode'); >+ my $published_on_template = $query->param('published_on_template'); >+ >+ my $mana_id; >+ if ( $query->param('mana_id') ne "" ) { >+ $mana_id = $query->param('mana_id'); >+ Koha::SharedContent::increment_entity_value( "subscription", $mana_id, "nbofusers" ); >+ } else { >+ $mana_id = undef; >+ } >+ >+ # Guess end date >+ if ( !defined $enddate || $enddate eq '' ) { >+ if ( $subtype eq "issues" ) { >+ $enddate = _guess_enddate( $nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength ); >+ } else { >+ $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength ); >+ } >+ } >+ >+ my $nextexpected = GetNextExpected($subscriptionid); >+ >+ # If it's a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary. >+ if ( $nextexpected->{planneddate} && $nextacquidate ne $nextexpected->{planneddate} ) { >+ ModNextExpected( $subscriptionid, $nextacquidate ); >+ >+ # if we have not received any issues yet, then we also must change the firstacquidate for the subs. >+ $firstissuedate = $nextacquidate if ( $nextexpected->{isfirstissue} ); >+ } >+ >+ ModSubscription( >+ $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, >+ $periodicity, $firstacquidate, join( ";", @irregularity ), >+ $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1, >+ $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, >+ $status, $biblionumber, $callnumber, $notes, $letter, >+ $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, >+ $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, >+ $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template >+ ); >+ >+ my @additional_fields; >+ my $biblio = Koha::Biblios->find($biblionumber); >+ my $subscription_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } ); >+ while ( my $field = $subscription_fields->next ) { >+ my $value = $query->param( 'additional_field_' . $field->id ); >+ push @additional_fields, { >+ id => $field->id, >+ value => $value, >+ }; >+ } >+ Koha::Subscriptions->find($subscriptionid)->set_additional_fields( \@additional_fields ); >+ >+ print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); >+ return; >+} >diff --git a/serials/subscription-numberpatterns.pl b/serials/subscription-numberpatterns.pl >index 4b931edae8..c0e051a9b2 100755 >--- a/serials/subscription-numberpatterns.pl >+++ b/serials/subscription-numberpatterns.pl >@@ -116,6 +116,7 @@ if($op && ($op eq 'new' || $op eq 'modify')) { > my $languages = [ map { > { > language => $_->{iso639_2_code}, >+ subtag => $_->{subtag}, > description => $_->{language_description} || $_->{language} > } > } @{ C4::Languages::getAllLanguages() } ]; >diff --git a/serials/subscription-numberpatterns.pl.tdy b/serials/subscription-numberpatterns.pl.tdy >new file mode 100755 >index 0000000000..4b7435315e >--- /dev/null >+++ b/serials/subscription-numberpatterns.pl.tdy >@@ -0,0 +1,164 @@ >+#!/usr/bin/perl >+ >+# Copyright 2011-2013 Biblibre SARL >+# >+# 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 <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+subscription-numberpatterns.pl >+ >+=head1 DESCRIPTION >+ >+Manage numbering patterns >+ >+=cut >+ >+use Modern::Perl; >+use CGI qw ( -utf8 ); >+ >+use C4::Auth qw( get_template_and_user ); >+use C4::Output qw( output_html_with_http_headers ); >+use C4::Serials::Numberpattern qw( >+ AddSubscriptionNumberpattern >+ DelSubscriptionNumberpattern >+ GetSubscriptionNumberpattern >+ GetSubscriptionNumberpatternByName >+ GetSubscriptionNumberpatterns >+ GetSubscriptionsWithNumberpattern >+ ModSubscriptionNumberpattern >+); >+use C4::Serials::Frequency qw( GetSubscriptionFrequencies ); >+ >+my @NUMBERPATTERN_FIELDS = qw/ >+ label description numberingmethod displayorder >+ label1 label2 label3 add1 add2 add3 every1 every2 every3 >+ setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3 >+ numbering1 numbering2 numbering3 /; >+ >+my $input = CGI->new; >+my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( >+ { >+ template_name => 'serials/subscription-numberpatterns.tt', >+ query => $input, >+ type => 'intranet', >+ flagsrequired => { 'serials' => "*" } >+ } >+); >+ >+my $op = $input->param('op'); >+ >+if ( $op && $op eq 'cud-savenew' ) { >+ my $label = $input->param('label'); >+ my $numberpattern; >+ foreach (@NUMBERPATTERN_FIELDS) { >+ $numberpattern->{$_} = $input->param($_); >+ if ( defined $numberpattern->{$_} and $numberpattern->{$_} eq '' ) { >+ $numberpattern->{$_} = undef; >+ } >+ } >+ my $numberpattern2 = GetSubscriptionNumberpatternByName($label); >+ >+ if ( !defined $numberpattern2 ) { >+ AddSubscriptionNumberpattern($numberpattern); >+ } else { >+ $op = 'new'; >+ $template->param( error_existing_numberpattern => 1 ); >+ $template->param(%$numberpattern); >+ } >+} elsif ( $op && $op eq 'cud-savemod' ) { >+ my $id = $input->param('id'); >+ my $label = $input->param('label'); >+ my $numberpattern = GetSubscriptionNumberpattern($id); >+ my $mod_ok = 1; >+ if ( $numberpattern->{'label'} ne $label ) { >+ my $numberpattern2 = GetSubscriptionNumberpatternByName($label); >+ if ( defined $numberpattern2 && $id != $numberpattern2->{'id'} ) { >+ $mod_ok = 0; >+ } >+ } >+ if ($mod_ok) { >+ foreach (@NUMBERPATTERN_FIELDS) { >+ $numberpattern->{$_} = $input->param($_) || undef; >+ if ( defined $numberpattern->{$_} and $numberpattern->{$_} eq '' ) { >+ $numberpattern->{$_} = undef; >+ } >+ } >+ ModSubscriptionNumberpattern($numberpattern); >+ } else { >+ $op = 'cud-modify'; >+ $template->param( error_existing_numberpattern => 1 ); >+ } >+} >+ >+if ( $op && ( $op eq 'new' || $op eq 'modify' ) ) { >+ if ( $op eq 'modify' ) { >+ my $id = $input->param('id'); >+ if ( defined $id ) { >+ my $numberpattern = GetSubscriptionNumberpattern($id); >+ $template->param(%$numberpattern); >+ } else { >+ $op = 'new'; >+ } >+ } >+ my @frequencies = GetSubscriptionFrequencies(); >+ my $languages = [ >+ map { >+ { >+ language => $_->{iso639_2_code}, >+ subtag => $_->{subtag}, >+ description => $_->{language_description} || $_->{language} >+ } >+ } @{ C4::Languages::getAllLanguages() } >+ ]; >+ >+ $template->param( >+ $op => 1, >+ frequencies_loop => \@frequencies, >+ locales => $languages, >+ ); >+ output_html_with_http_headers $input, $cookie, $template->output; >+ exit; >+} >+ >+if ( $op && $op eq 'cud-del' ) { >+ my $id = $input->param('id'); >+ if ($id) { >+ my $confirm = $input->param('confirm'); >+ if ($confirm) { >+ DelSubscriptionNumberpattern($id); >+ } else { >+ my @subs = GetSubscriptionsWithNumberpattern($id); >+ if (@subs) { >+ $template->param( >+ id => $id, >+ still_used => 1, >+ subscriptions => \@subs >+ ); >+ } else { >+ DelSubscriptionNumberpattern($id); >+ } >+ } >+ } >+} >+ >+my @numberpatterns_loop = GetSubscriptionNumberpatterns(); >+ >+$template->param( >+ numberpatterns_loop => \@numberpatterns_loop, >+); >+ >+output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t >index 7a431c1edd..5af156ca16 100755 >--- a/t/db_dependent/Serials.t >+++ b/t/db_dependent/Serials.t >@@ -5,22 +5,24 @@ > > use Modern::Perl; > >-use C4::Serials qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate ); >+use C4::Serials qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations ); > use C4::Serials::Frequency; > use C4::Serials::Numberpattern; > use C4::Biblio qw( AddBiblio GetMarcFromKohaField ); > use C4::Budgets qw( AddBudgetPeriod AddBudget ); >+use C4::Context; > use C4::Items qw( AddItemFromMarc ); >+use Encode qw( encode ); >+use File::Temp; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Acquisition::Booksellers; > use t::lib::Mocks; > use t::lib::TestBuilder; >-use Test::MockModule; >-use Test::More tests => 54; >+use Test::More tests => 55; > > BEGIN { >- use_ok('C4::Serials', qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate )); >+ use_ok('C4::Serials', qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations )); > } > > # Auth required for cataloguing plugins >@@ -554,7 +556,7 @@ subtest "NewSubscription|ModSubscription" => sub { > > subtest "_numeration" => sub { > >- plan tests => 6; >+ plan tests => 8; > > my $s = C4::Serials::_numeration(0, 'monthname', 'cat'); > is( $s, "gener" ); >@@ -569,4 +571,74 @@ subtest "_numeration" => sub { > like( $s, qr{^ene\.?} ); > $s = C4::Serials::_numeration(0, 'monthabrv', 'fr'); > is( $s, "janv." ); >+ >+ my $translations = { >+ seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ], >+ seasonsabrv => [ 'Spr', 'Sum', 'Fal', 'Win' ], >+ }; >+ >+ $s = C4::Serials::_numeration( 0, 'season', 'en', $translations ); >+ is( $s, "Spring" ); >+ $s = C4::Serials::_numeration( 0, 'seasonabrv', 'en', $translations ); >+ is( $s, "Spr" ); >+}; >+ >+subtest "GetSeasonsTranslations" => sub { >+ >+ plan tests => 8; >+ >+ my @seasons = qw( Printemps Ãté Automne Hiver ); >+ my @seasonsabrv = qw( Pri Ãté Aut Hiv ); >+ >+ my $dir = C4::Context->config('intranetdir') . '/misc/translator/po/'; >+ my $fh = File::Temp->new( DIR => $dir, SUFFIX => '-staff-prog.po' ); >+ my $filename = $fh->filename; >+ >+ my $txt = ' >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Spring" >+msgstr "Printemps" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Summer" >+msgstr "Ãté" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Fall" >+msgstr "Automne" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Winter" >+msgstr "Hiver" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:208 >+#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:210 >+#, c-format >+msgid "Sum" >+msgstr "Total" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt:248 >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt:43 >+#, c-format >+msgid "" >+"%s %sSpring%s %s %sSummer%s %s %sFall%s %s %sWinter%s %s %sSpr%s %s %sSum%s " >+"%s %sFal%s %s %sWin%s %s %s %s " >+msgstr "" >+"%s %sPrintemps%s %s %sÃté%s %s %sAutomne%s %s %sHiver%s %s %sPri%s %s %sÃté" >+"%s %s %sAut%s %s %sHiv%s %s %s %s " >+ '; >+ >+ print $fh encode( 'utf-8', $txt ); >+ close($fh); >+ >+ my $translations = GetSeasonsTranslations( 1, 1, $filename =~ s/($dir|-staff-prog.po)//gr ); >+ >+ for my $idx ( 0 .. $#{ $translations->{seasons} } ) { >+ is( $translations->{seasons}->[$idx], $seasons[$idx] ); >+ is( $translations->{seasonsabrv}->[$idx], $seasonsabrv[$idx] ); >+ } > }; >diff --git a/t/db_dependent/Serials.t.tdy b/t/db_dependent/Serials.t.tdy >new file mode 100755 >index 0000000000..266f606737 >--- /dev/null >+++ b/t/db_dependent/Serials.t.tdy >@@ -0,0 +1,738 @@ >+#!/usr/bin/perl >+# >+# This Koha test module is a stub! >+# Add more tests here!!! >+ >+use Modern::Perl; >+ >+use C4::Serials >+ qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations ); >+use C4::Serials::Frequency; >+use C4::Serials::Numberpattern; >+use C4::Biblio qw( AddBiblio GetMarcFromKohaField ); >+use C4::Budgets qw( AddBudgetPeriod AddBudget ); >+use C4::Context; >+use C4::Items qw( AddItemFromMarc ); >+use Encode qw( encode ); >+use File::Temp; >+use Koha::Database; >+use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Acquisition::Booksellers; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+use Test::More tests => 55; >+ >+BEGIN { >+ use_ok( >+ 'C4::Serials', >+ qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations ) >+ ); >+} >+ >+# Auth required for cataloguing plugins >+my $mAuth = Test::MockModule->new('C4::Auth'); >+$mAuth->mock( 'check_cookie_auth', sub { return ('ok') } ); >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $dbh = C4::Context->dbh; >+ >+$dbh->do('DELETE FROM subscription'); >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+# This could/should be used for all untested methods >+my @methods = ('updateClaim'); >+can_ok( 'C4::Serials', @methods ); >+ >+$dbh->do( >+ q|UPDATE marc_subfield_structure SET value_builder="callnumber.pl" where kohafield="items.itemcallnumber" and frameworkcode=''| >+); >+ >+my $bookseller = Koha::Acquisition::Bookseller->new( >+ { >+ name => "my vendor", >+ address1 => "bookseller's address", >+ phone => "0123456", >+ active => 1 >+ } >+); >+ >+my ( $biblionumber, $biblioitemnumber ) = AddBiblio( MARC::Record->new, '' ); >+ >+my $bpid = AddBudgetPeriod( >+ { >+ budget_period_startdate => '2015-01-01', >+ budget_period_enddate => '2015-12-31', >+ budget_period_description => "budget desc" >+ } >+); >+ >+my $budget_id = AddBudget( >+ { >+ budget_code => "ABCD", >+ budget_amount => "123.132", >+ budget_name => "Périodiques", >+ budget_notes => "This is a note", >+ budget_period_id => $bpid >+ } >+); >+ >+my $frequency_id = AddSubscriptionFrequency( { description => "Test frequency 1" } ); >+my $pattern_id = AddSubscriptionNumberpattern( >+ { >+ label => 'Test numberpattern 1', >+ description => 'Description for numberpattern 1', >+ numberingmethod => '{X}', >+ label1 => q{}, >+ add1 => 1, >+ every1 => 1, >+ every1 => 1, >+ numbering1 => 1, >+ whenmorethan1 => 1, >+ } >+); >+ >+my $notes = "a\nnote\non\nseveral\nlines"; >+my $internalnotes = 'intnotes'; >+my $ccode = 'FIC'; >+my $subscriptionid = NewSubscription( >+ undef, >+ "", >+ undef, >+ undef, >+ $budget_id, >+ $biblionumber, >+ '2013-01-01', >+ $frequency_id, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ 1, >+ $notes, >+ undef, >+ '2013-01-01', >+ undef, >+ $pattern_id, >+ undef, >+ undef, >+ 0, >+ $internalnotes, >+ 0, >+ undef, >+ undef, >+ 0, >+ undef, >+ '2013-12-31', 0, >+ undef, >+ undef, >+ undef, >+ $ccode >+); >+ >+NewSubscription( >+ undef, >+ "", >+ undef, >+ undef, >+ $budget_id, >+ $biblionumber, >+ '2013-01-02', >+ $frequency_id, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ undef, >+ 1, >+ $notes, >+ undef, >+ '2013-01-02', >+ undef, >+ $pattern_id, >+ undef, >+ undef, >+ 0, >+ $internalnotes, >+ 0, >+ undef, >+ undef, >+ 0, >+ undef, >+ '2013-12-31', >+ 0, >+ undef, >+ undef, >+ undef, >+ $ccode >+); >+ >+my $subscriptioninformation = GetSubscription($subscriptionid); >+ >+is( $subscriptioninformation->{notes}, $notes, 'NewSubscription should set notes' ); >+is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' ); >+is( $subscriptioninformation->{ccode}, $ccode, 'NewSubscription should set ccode' ); >+ >+my $subscription_history = C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid); >+is( $subscription_history->{opacnote}, undef, 'NewSubscription should not set subscriptionhistory opacnotes' ); >+is( >+ $subscription_history->{librariannote}, undef, >+ 'NewSubscription should not set subscriptionhistory librariannotes' >+); >+ >+my @subscriptions = SearchSubscriptions( { string => $subscriptioninformation->{bibliotitle}, orderby => 'title' } ); >+isa_ok( \@subscriptions, 'ARRAY' ); >+ >+@subscriptions = SearchSubscriptions( { issn => $subscriptioninformation->{issn}, orderby => 'title' } ); >+isa_ok( \@subscriptions, 'ARRAY' ); >+ >+@subscriptions = SearchSubscriptions( { ean => $subscriptioninformation->{ean}, orderby => 'title' } ); >+isa_ok( \@subscriptions, 'ARRAY' ); >+ >+@subscriptions = SearchSubscriptions( { biblionumber => $subscriptioninformation->{bibnum}, orderby => 'title' } ); >+isa_ok( \@subscriptions, 'ARRAY' ); >+ >+@subscriptions = SearchSubscriptions( {} ); >+is( >+ @subscriptions, >+ 2, >+ 'SearchSubscriptions returned the expected number of subscriptions when results_limit is not set' >+); >+ >+@subscriptions = SearchSubscriptions( {}, { results_limit => 1 } ); >+is( >+ @subscriptions, >+ 1, >+ 'SearchSubscriptions returned only one subscription when results_limit is set to "1"' >+); >+ >+my $frequency = GetSubscriptionFrequency( $subscriptioninformation->{periodicity} ); >+my $old_frequency; >+if ( not $frequency->{unit} ) { >+ $old_frequency = $frequency->{id}; >+ $frequency->{unit} = "month"; >+ $frequency->{unitsperissue} = 1; >+ $frequency->{issuesperunit} = 1; >+ $frequency->{description} = "Frequency created by t/db_dependant/Serials.t"; >+ $subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency); >+ $subscriptioninformation->{serialsadditems} = 1; >+ $subscriptioninformation->{ccode} = 'NFIC'; >+ >+ ModSubscription( >+ @$subscriptioninformation{ >+ qw( >+ librarian branchcode aqbooksellerid cost aqbudgetid startdate >+ periodicity firstacquidate irregularity numberpattern locale >+ numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 >+ innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes >+ letter manualhistory internalnotes serialsadditems staffdisplaycount >+ opacdisplaycount graceperiod location enddate subscriptionid >+ skip_serialseq itemtype previousitemtype mana_id ccode >+ ) >+ } >+ ); >+} >+my $expirationdate = GetExpirationDate($subscriptionid); >+ok( $expirationdate, "expiration date is not NULL" ); >+ >+# Check ModSubscription has updated the ccode >+my $subscriptioninformation2 = GetSubscription($subscriptionid); >+is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' ); >+ >+ok( C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription' ); >+ >+my ( $serials_count, @serials ) = GetSerials($subscriptionid); >+ok( $serials_count > 0, 'Subscription has at least one serial' ); >+my $serial = $serials[0]; >+ >+isa_ok( C4::Serials::GetSerialInformation( $serial->{serialid} ), 'HASH', 'test getting Serial Information' ); >+ >+subtest 'Values should not be erased on editing' => sub { >+ >+ plan tests => 1; >+ >+ my $biblio = $builder->build_sample_biblio(); >+ my $biblionumber = $biblio->biblionumber; >+ my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField('items.itemcallnumber'); >+ my ( $it_tag, $it_sf ) = GetMarcFromKohaField('items.itype'); >+ >+ my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; >+ my $itemcallnumber = 'XXXmy itemcallnumberXXX'; >+ >+ my $item_record = MARC::Record->new; >+ >+ $item_record->append_fields( >+ MARC::Field->new( '080', '', '', "a" => "default" ), >+ MARC::Field->new( >+ $icn_tag, '', '', >+ $icn_sf => $itemcallnumber, >+ $it_sf => $itemtype >+ ) >+ ); >+ my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber ); >+ my $serialid = C4::Serials::NewIssue( >+ "serialseq", $subscriptionid, $biblionumber, >+ 1, undef, undef, "publisheddatetext", "notes", "routingnotes" >+ ); >+ C4::Serials::AddItem2Serial( $serialid, $itemnumber ); >+ my $serial_info = C4::Serials::GetSerialInformation($serialid); >+ my ($itemcallnumber_info) = >+ grep { $_->{kohafield} eq 'items.itemcallnumber' } @{ $serial_info->{items}[0]->{iteminformation} }; >+ like( $itemcallnumber_info->{marc_value}, qr|value="$itemcallnumber"| ); >+}; >+ >+# Delete created frequency >+if ($old_frequency) { >+ my $freq_to_delete = $subscriptioninformation->{periodicity}; >+ $subscriptioninformation->{periodicity} = $old_frequency; >+ >+ ModSubscription( >+ @$subscriptioninformation{ >+ qw( >+ librarian branchcode aqbooksellerid cost aqbudgetid startdate >+ periodicity firstacquidate irregularity numberpattern locale >+ numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 >+ innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes >+ letter manualhistory internalnotes serialsadditems staffdisplaycount >+ opacdisplaycount graceperiod location enddate subscriptionid >+ skip_serialseq >+ ) >+ } >+ ); >+ >+ DelSubscriptionFrequency($freq_to_delete); >+} >+ >+# Test calling subs without parameters >+is( C4::Serials::AddItem2Serial(), undef, 'test adding item to serial' ); >+is( C4::Serials::GetFullSubscription(), undef, 'test getting full subscription' ); >+is( C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data' ); >+ >+subtest 'GetSubscriptionsFromBiblionumber' => sub { >+ plan tests => 4; >+ >+ is( >+ C4::Serials::GetSubscriptionsFromBiblionumber(), >+ undef, 'test getting subscriptions form biblio number' >+ ); >+ >+ my $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber); >+ ModSubscriptionHistory( >+ $subscriptions->[0]->{subscriptionid}, >+ undef, undef, $notes, $notes, $notes >+ ); >+ >+ $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber); >+ is( >+ $subscriptions->[0]->{opacnote}, $notes, >+ 'GetSubscriptionsFromBiblionumber should have returned the opacnote as it is in DB, ie. without br tags' >+ ); >+ is( >+ $subscriptions->[0]->{recievedlist}, $notes, >+ 'GetSubscriptionsFromBiblionumber should have returned recievedlist as it is in DB, ie. without br tags' >+ ); >+ is( >+ $subscriptions->[0]->{missinglist}, $notes, >+ 'GetSubscriptionsFromBiblionumber should have returned missinglist as it is in DB, ie. without br tags' >+ ); >+}; >+ >+is( C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing' ); >+is( C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing' ); >+ >+is( C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials' ); >+ >+is( C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing' ); >+ >+is( C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing' ); >+ >+is( C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered' ); >+ >+is( C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history' ); >+ >+is( C4::Serials::ModSerialStatus(), undef, 'test modding serials' ); >+ >+is( C4::Serials::findSerialsByStatus(), 0, 'test finding serial by status with no parameters' ); >+ >+is( C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered' ); >+ >+is( C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired' ); >+is( C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired' ); >+ >+is( C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues' ); >+ >+subtest 'test_updateClaim' => sub { >+ plan tests => 11; >+ >+ my $today = output_pref( { dt => dt_from_string, dateonly => 1 } ); >+ >+ # Given ... nothing much >+ # When ... Then ... >+ my $result_0 = C4::Serials::updateClaim(undef); >+ is( $result_0, undef, 'Got the expected undef from update claim with nothin' ); >+ >+ # Given ... 3 serial. 2 of them updated. >+ my $claimdate_1 = dt_from_string('2001-01-13'); # arbitrary date some time in the past. >+ my $claim_count_1 = 5; >+ my $biblio = $builder->build_sample_biblio; >+ my $serial1 = $builder->build_object( >+ { >+ class => 'Koha::Serials', >+ value => { >+ serialseq => 'serialseq', >+ subscriptionid => $subscriptionid, >+ status => 3, >+ biblionumber => $biblio->biblionumber, >+ claimdate => $claimdate_1, >+ claims_count => $claim_count_1, >+ } >+ } >+ ); >+ my $serial2 = $builder->build_object( >+ { >+ class => 'Koha::Serials', >+ value => { >+ serialseq => 'serialseq', >+ subscriptionid => $subscriptionid, >+ status => 3, >+ biblionumber => $biblio->biblionumber, >+ claimdate => $claimdate_1, >+ claims_count => $claim_count_1, >+ } >+ } >+ ); >+ my $serial3 = $builder->build_object( >+ { >+ class => 'Koha::Serials', >+ value => { >+ serialseq => 'serialseq', >+ subscriptionid => $subscriptionid, >+ status => 3, >+ biblionumber => $biblio->biblionumber, >+ claimdate => $claimdate_1, >+ claims_count => $claim_count_1, >+ } >+ } >+ ); >+ >+ # When ... >+ my $result_1 = C4::Serials::updateClaim( [ $serial1->serialid, $serial2->serialid ] ); >+ >+ # Then ... >+ is( $result_1, 2, 'Got the expected 2 from update claim with 2 serial ids' ); >+ >+ my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues( undef, $serial1->serialid ); >+ is( >+ output_pref( { str => $late_or_missing_issues_1_0[0]->{claimdate}, dateonly => 1 } ), $today, >+ 'Got the expected first different claim date from update claim' >+ ); >+ is( >+ $late_or_missing_issues_1_0[0]->{claims_count}, $claim_count_1 + 1, >+ 'Got the expected first claim count from update claim' >+ ); >+ is( $late_or_missing_issues_1_0[0]->{status}, 7, 'Got the expected first claim status from update claim' ); >+ >+ my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues( undef, $serial2->serialid ); >+ is( >+ output_pref( { str => $late_or_missing_issues_1_1[0]->{claimdate}, dateonly => 1 } ), $today, >+ 'Got the expected second different claim date from update claim' >+ ); >+ is( >+ $late_or_missing_issues_1_1[0]->{claims_count}, $claim_count_1 + 1, >+ 'Got the expected second claim count from update claim' >+ ); >+ is( $late_or_missing_issues_1_1[0]->{status}, 7, 'Got the expected second claim status from update claim' ); >+ >+ my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues( undef, $serial3->serialid ); >+ is( >+ output_pref( { str => $late_or_missing_issues_1_2[0]->{claimdate}, dateonly => 1 } ), >+ output_pref( { dt => $claimdate_1, dateonly => 1 } ), >+ 'Got the expected unchanged claim date from update claim' >+ ); >+ is( >+ $late_or_missing_issues_1_2[0]->{claims_count}, $claim_count_1, >+ 'Got the expected unchanged claim count from update claim' >+ ); >+ is( $late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim' ); >+}; >+ >+is( C4::Serials::check_routing(), undef, 'test checking route' ); >+is( C4::Serials::check_routing($subscriptionid), 0, 'There should not have any routing list for the subscription' ); >+ >+# TODO really test this check_routing subroutine >+ >+is( C4::Serials::addroutingmember(), undef, 'test adding route member' ); >+ >+# Unit tests for statuses management (Bug 11689) >+$subscriptionid = NewSubscription( >+ undef, "", undef, undef, $budget_id, $biblionumber, >+ '2013-01-01', $frequency_id, undef, undef, undef, >+ undef, undef, undef, undef, undef, undef, >+ 1, $notes, undef, '2013-01-01', undef, $pattern_id, >+ undef, undef, 0, $internalnotes, 0, >+ undef, undef, 0, undef, '2013-12-31', 0 >+); >+my $total_issues; >+( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid); >+is( $total_issues, 1, "NewSubscription created a first serial" ); >+is( @serials, 1, "GetSerials returns the serial" ); >+my $subscription = C4::Serials::GetSubscription($subscriptionid); >+my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern( $subscription->{numberpattern} ); >+( $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); >+$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; >+for my $status (@statuses) { >+ my $serialseq = "No." . $counter; >+ my ($expected_serial) = GetSerials2( $subscriptionid, [1] ); >+ C4::Serials::ModSerialStatus( >+ $expected_serial->{serialid}, $serialseq, $publisheddate, $publisheddate, >+ $publisheddate, $statuses[$counter], 'an useless note' >+ ); >+ $counter++; >+} >+ >+# Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1 >+my @serialsByStatus = C4::Serials::findSerialsByStatus( 2, $subscriptionid ); >+is( @serialsByStatus, 2, "findSerialsByStatus returns all serials with chosen status" ); >+( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid); >+is( $total_issues, @statuses + 1, "GetSerials returns total_issues" ); >+my @arrived_missing = map { >+ my $status = $_->{status}; >+ ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () >+} @serials; >+my @others = map { >+ my $status = $_->{status}; >+ ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ >+} @serials; >+is( @arrived_missing, 5, "GetSerials returns 5 arrived/missing by default" ); >+is( @others, 6, "GetSerials returns all serials not arrived and not missing" ); >+ >+( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid, 10 ); >+is( $total_issues, @statuses + 1, "GetSerials returns total_issues" ); >+@arrived_missing = map { >+ my $status = $_->{status}; >+ ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () >+} @serials; >+@others = map { >+ my $status = $_->{status}; >+ ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ >+} @serials; >+is( @arrived_missing, 9, "GetSerials returns all arrived/missing if count given" ); >+is( @others, 6, "GetSerials returns all serials not arrived and not missing if count given" ); >+ >+$subscription = C4::Serials::GetSubscription($subscriptionid); # Retrieve the updated subscription >+ >+my @serialseqs; >+for my $am (@arrived_missing) { >+ if ( grep { /^$am->{status}$/ } qw( 4 41 42 43 44 ) ) { >+ push @serialseqs, $am->{serialseq}; >+ } elsif ( grep { /^$am->{status}$/ } qw( 5 ) ) { >+ push @serialseqs, 'not issued ' . $am->{serialseq}; >+ } >+} >+is( >+ $subscription->{missinglist}, join( '; ', @serialseqs ), >+ "subscription missinglist is updated after ModSerialStatus" >+); >+ >+subtest "Do not generate an expected if one already exists" => sub { >+ plan tests => 2; >+ my ($expected_serial) = GetSerials2( $subscriptionid, [1] ); >+ >+ #Find serialid for serial with status Expected >+ my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0]; >+ >+ #delete serial with status Expected >+ C4::Serials::ModSerialStatus( >+ $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, >+ $publisheddate, $publisheddate, '1', 'an useless note' >+ ); >+ @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid ); >+ is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and create another if not exist" ); >+ >+ # add 1 serial with status=Expected 1 >+ C4::Serials::ModSerialStatus( >+ $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, >+ $publisheddate, '1', 'an useless note' >+ ); >+ >+ #Now we have two serials it have status expected >+ #put status delete for last serial >+ C4::Serials::ModSerialStatus( >+ $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, >+ $publisheddate, $publisheddate, '1', 'an useless note' >+ ); >+ >+ #try if create or not another serial with status is expected >+ @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid ); >+ is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" ); >+}; >+ >+subtest "PreserveSerialNotes preference" => sub { >+ plan tests => 2; >+ my ($expected_serial) = GetSerials2( $subscriptionid, [1] ); >+ >+ t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 1 ); >+ >+ C4::Serials::ModSerialStatus( >+ $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, >+ $publisheddate, '1', 'an useless note' >+ ); >+ @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid ); >+ is( $serialsByStatus[0]->{note}, $expected_serial->{note}, "note passed through if supposed to" ); >+ >+ t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 0 ); >+ $expected_serial = $serialsByStatus[0]; >+ C4::Serials::ModSerialStatus( >+ $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, >+ $publisheddate, '1', 'an useless note' >+ ); >+ is( $serialsByStatus[0]->{note}, $expected_serial->{note}, "note not passed through if not supposed to" ); >+ >+}; >+ >+subtest "NewSubscription|ModSubscription" => sub { >+ plan tests => 4; >+ my $subscriptionid = NewSubscription( >+ "", "", "", "", $budget_id, $biblionumber, >+ '2013-01-01', $frequency_id, "", "", "", >+ "", "", "", "", "", "", >+ 1, $notes, "", '2013-01-01', "", $pattern_id, >+ "", "", 0, $internalnotes, 0, >+ "", "", 0, "", '2013-12-31', 0 >+ ); >+ ok( $subscriptionid, "Sending empty string instead of undef to reflect use of the interface" ); >+ >+ my $subscription = Koha::Subscriptions->find($subscriptionid); >+ my $serials = Koha::Serials->search( { subscriptionid => $subscriptionid } ); >+ is( $serials->count, 1, "NewSubscription created a first serial" ); >+ >+ my $biblio_2 = $builder->build_sample_biblio; >+ my $subscription_info = $subscription->unblessed; >+ $subscription_info->{biblionumber} = $biblio_2->biblionumber; >+ ModSubscription( >+ @$subscription_info{ >+ qw( >+ librarian branchcode aqbooksellerid cost aqbudgetid startdate >+ periodicity firstacquidate irregularity numberpattern locale >+ numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 >+ innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes >+ letter manualhistory internalnotes serialsadditems staffdisplaycount >+ opacdisplaycount graceperiod location enddate subscriptionid >+ skip_serialseq >+ ) >+ } >+ ); >+ >+ $serials = Koha::Serials->search( { subscriptionid => $subscriptionid } ); >+ is( $serials->count, 1, "Still only one serial" ); >+ is( >+ $serials->next->biblionumber, $biblio_2->biblionumber, >+ 'ModSubscription should have updated serial.biblionumber' >+ ); >+}; >+ >+subtest "_numeration" => sub { >+ >+ plan tests => 8; >+ >+ my $s = C4::Serials::_numeration( 0, 'monthname', 'cat' ); >+ is( $s, "gener" ); >+ $s = C4::Serials::_numeration( 0, 'monthname', 'es' ); >+ is( $s, "enero" ); >+ $s = C4::Serials::_numeration( 0, 'monthname', 'fr' ); >+ is( $s, "janvier" ); >+ >+ $s = C4::Serials::_numeration( 0, 'monthabrv', 'cat' ); >+ is( $s, "de gen." ); >+ $s = C4::Serials::_numeration( 0, 'monthabrv', 'es' ); >+ like( $s, qr{^ene\.?} ); >+ $s = C4::Serials::_numeration( 0, 'monthabrv', 'fr' ); >+ is( $s, "janv." ); >+ >+ my $translations = { >+ seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ], >+ seasonsabrv => [ 'Spr', 'Sum', 'Fal', 'Win' ], >+ }; >+ >+ $s = C4::Serials::_numeration( 0, 'season', 'en', $translations ); >+ is( $s, "Spring" ); >+ $s = C4::Serials::_numeration( 0, 'seasonabrv', 'en', $translations ); >+ is( $s, "Spr" ); >+}; >+ >+subtest "GetSeasonsTranslations" => sub { >+ >+ plan tests => 8; >+ >+ my @seasons = qw( Printemps Ãté Automne Hiver ); >+ my @seasonsabrv = qw( Pri Ãté Aut Hiv ); >+ >+ my $dir = C4::Context->config('intranetdir') . '/misc/translator/po/'; >+ my $fh = File::Temp->new( DIR => $dir, SUFFIX => '-staff-prog.po' ); >+ my $filename = $fh->filename; >+ >+ my $txt = ' >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Spring" >+msgstr "Printemps" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Summer" >+msgstr "Ãté" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Fall" >+msgstr "Automne" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 >+#, c-format >+msgid "Winter" >+msgstr "Hiver" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:208 >+#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:210 >+#, c-format >+msgid "Sum" >+msgstr "Total" >+ >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt:248 >+#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt:43 >+#, c-format >+msgid "" >+"%s %sSpring%s %s %sSummer%s %s %sFall%s %s %sWinter%s %s %sSpr%s %s %sSum%s " >+"%s %sFal%s %s %sWin%s %s %s %s " >+msgstr "" >+"%s %sPrintemps%s %s %sÃté%s %s %sAutomne%s %s %sHiver%s %s %sPri%s %s %sÃté" >+"%s %s %sAut%s %s %sHiv%s %s %s %s " >+ '; >+ >+ print $fh encode( 'utf-8', $txt ); >+ close($fh); >+ >+ my $translations = GetSeasonsTranslations( 1, 1, $filename =~ s/($dir|-staff-prog.po)//gr ); >+ >+ for my $idx ( 0 .. $#{ $translations->{seasons} } ) { >+ is( $translations->{seasons}->[$idx], $seasons[$idx] ); >+ is( $translations->{seasonsabrv}->[$idx], $seasonsabrv[$idx] ); >+ } >+}; >diff --git a/t/db_dependent/Serials/GetNextSeq.t b/t/db_dependent/Serials/GetNextSeq.t >index 270568de60..b8bd95b46a 100755 >--- a/t/db_dependent/Serials/GetNextSeq.t >+++ b/t/db_dependent/Serials/GetNextSeq.t >@@ -143,6 +143,7 @@ $subscription = { > irregularity => '3;4;6', > countissuesperunit => 1, > locale => 'C', >+ translations => { seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ] }, > }; > $pattern = { > add1 => 1, add2 => 0, add3 => 0, >diff --git a/t/db_dependent/Serials/GetNextSeq.t.tdy b/t/db_dependent/Serials/GetNextSeq.t.tdy >new file mode 100755 >index 0000000000..cbca088e8d >--- /dev/null >+++ b/t/db_dependent/Serials/GetNextSeq.t.tdy >@@ -0,0 +1,279 @@ >+#!/usr/bin/perl >+ >+use C4::Context; >+use Test::More tests => 32; >+use Modern::Perl; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+use C4::Serials::Frequency; >+use C4::Serials qw( GetNextDate GetNextSeq ); >+ >+my $frequency = { >+ description => "One issue per day", >+ unit => 'day', >+ issuesperunit => 1, >+ unitsperissue => 1, >+}; >+my $id = AddSubscriptionFrequency($frequency); >+ >+# TEST CASE 1 - 1 variable, from 1 to 4 >+my $pattern = { >+ add1 => 1, add2 => 0, add3 => 0, >+ every1 => 1, every2 => 0, every3 => 0, >+ whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0, >+ setto1 => 1, setto2 => 0, setto3 => 0, >+ numberingmethod => 'X: {X}', >+ numbering1 => '', >+ numbering2 => '', >+ numbering3 => '', >+}; >+ >+my $subscription = { >+ periodicity => $id, >+ firstacquidate => '1970-01-01', >+ lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, >+ innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, >+ skip_serialseq => 1, >+ irregularity => '3;5', >+ countissuesperunit => 1, >+ locale => 'en', >+}; >+my $publisheddate = $subscription->{firstacquidate}; >+ >+my $seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: 2' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: 4' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: 2' ); >+$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 >+$subscription = { >+ periodicity => $id, >+ firstacquidate => '1970-01-01', >+ lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, >+ innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, >+ skip_serialseq => 1, >+ irregularity => '3;4;6', >+ countissuesperunit => 1, >+ locale => 'C', >+}; >+$pattern = { >+ add1 => 1, add2 => 0, add3 => 0, >+ every1 => 1, every2 => 0, every3 => 0, >+ whenmorethan1 => 7, whenmorethan2 => 0, whenmorethan3 => 0, >+ setto1 => 1, setto2 => 0, setto3 => 0, >+ numberingmethod => 'X: {X}', >+ numbering1 => 'dayname', >+ numbering2 => '', >+ numbering3 => '', >+}; >+ >+$publisheddate = $subscription->{firstacquidate}; >+ >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Tuesday' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Friday' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Sunday' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Monday' ); >+$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 >+$subscription = { >+ periodicity => $id, >+ firstacquidate => '1970-01-01', >+ lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1, >+ innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, >+ skip_serialseq => 1, >+ irregularity => '3;4;6', >+ countissuesperunit => 1, >+ locale => 'C', >+}; >+$pattern = { >+ add1 => 2, add2 => 0, add3 => 0, >+ every1 => 1, every2 => 0, every3 => 0, >+ whenmorethan1 => 11, whenmorethan2 => 0, whenmorethan3 => 0, >+ setto1 => 0, setto2 => 0, setto3 => 0, >+ numberingmethod => 'X: {X}', >+ numbering1 => 'monthname', >+ numbering2 => '', >+ numbering3 => '', >+}; >+ >+$publisheddate = $subscription->{firstacquidate}; >+ >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: March' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: September' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: January' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: March' ); >+$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 >+$subscription = { >+ periodicity => $id, >+ firstacquidate => '1970-01-01', >+ lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1, >+ innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, >+ skip_serialseq => 1, >+ irregularity => '3;4;6', >+ countissuesperunit => 1, >+ locale => 'C', >+ translations => { seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ] }, >+}; >+$pattern = { >+ add1 => 1, add2 => 0, add3 => 0, >+ every1 => 1, every2 => 0, every3 => 0, >+ whenmorethan1 => 3, whenmorethan2 => 0, whenmorethan3 => 0, >+ setto1 => 0, setto2 => 0, setto3 => 0, >+ numberingmethod => 'X: {X}', >+ numbering1 => 'season', >+ numbering2 => '', >+ numbering3 => '', >+}; >+ >+$publisheddate = $subscription->{firstacquidate}; >+ >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Summer' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Spring' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Fall' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'X: Winter' ); >+$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 >+$subscription = { >+ periodicity => $id, >+ firstacquidate => '1970-01-01', >+ lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, >+ innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, >+ skip_serialseq => 1, >+ irregularity => '3;4;6', >+ countissuesperunit => 1, >+ locale => 'C', >+}; >+$pattern = { >+ add1 => 1, add2 => 1, add3 => 0, >+ every1 => 1, every2 => 4, every3 => 0, >+ whenmorethan1 => 4, whenmorethan2 => 12, whenmorethan3 => 0, >+ setto1 => 1, setto2 => 1, setto3 => 0, >+ numberingmethod => 'Y: {Y}, X: {X}', >+ numbering1 => '', >+ numbering2 => '', >+ numbering3 => '', >+}; >+ >+$publisheddate = $subscription->{firstacquidate}; >+ >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Y: 1, X: 2' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Y: 2, X: 1' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Y: 2, X: 3' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Y: 2, X: 4' ); >+$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 >+$subscription = { >+ periodicity => $id, >+ firstacquidate => '1970-01-01', >+ lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, >+ innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, >+ skip_serialseq => 1, >+ irregularity => '3;4;6;110', >+ countissuesperunit => 1, >+ locale => 'C', >+}; >+$pattern = { >+ add1 => 1, add2 => 1, add3 => 1, >+ every1 => 1, every2 => 4, every3 => 32, >+ whenmorethan1 => 4, whenmorethan2 => 8, whenmorethan3 => 12, >+ setto1 => 1, setto2 => 1, setto3 => 1, >+ numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}', >+ numbering1 => '', >+ numbering2 => '', >+ numbering3 => '', >+}; >+ >+$publisheddate = $subscription->{firstacquidate}; >+ >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Z: 1, Y: 1, X: 2' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Z: 1, Y: 2, X: 1' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Z: 1, Y: 2, X: 3' ); >+$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, $frequency ); >+ $seq = _next_seq( $subscription, $pattern, $frequency, $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, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Z: 4, Y: 4, X: 3' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Z: 4, Y: 4, X: 4' ); >+$publisheddate = GetNextDate( $subscription, $publisheddate, $frequency ); >+$seq = _next_seq( $subscription, $pattern, $frequency, $publisheddate ); >+is( $seq, 'Z: 4, Y: 5, X: 1' ); >+ >+sub _next_seq { >+ my ( $subscription, $pattern, $frequency, $publisheddate ) = @_; >+ my $seq; >+ ( >+ $seq, $subscription->{lastvalue1}, $subscription->{lastvalue2}, >+ $subscription->{lastvalue3}, $subscription->{innerloop1}, >+ $subscription->{innerloop2}, $subscription->{innerloop3} >+ ) = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate ); >+ return $seq; >+} >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35590
:
159981
|
159982
|
160003
|
160004
|
161272
|
169441
|
170119
|
171032
|
176562
|
176563