Bugzilla – Attachment 177831 Details for
Bug 17656
Irregularities in serial prediction pattern are planned only for current subscription
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17656: Keep irregularities during subscription renewals
Bug-17656-Keep-irregularities-during-subscription-.patch (text/plain), 72.75 KB, created by
Jonathan Druart
on 2025-02-12 10:41:56 UTC
(
hide
)
Description:
Bug 17656: Keep irregularities during subscription renewals
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-02-12 10:41:56 UTC
Size:
72.75 KB
patch
obsolete
>From efd4eee54931f0e9338c64cc024b3eb199aa0131 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Wed, 18 Oct 2017 14:52:34 +0000 >Subject: [PATCH] Bug 17656: Keep irregularities during subscription renewals > >When renewing a subscription, irregularities are lost. This patch >allows to keep them for daily, weekly and monthly serials (1 unit >per issue only). > >Test plan: > - Apply this patch, > - Launch installer/data/mysql/updatedatabase.pl > - Launch misc/devel/update_dbix_class_files.pl > > - Create a daily subscription. i.e: > - From: 2017-10-09, To: 2017-10-15, > - Frequency: 1/day, > - 7 issues, > - test prediction pattern > - check Wednesday and Thursday as irregularity, > - save > - Edit subscription, > - Check that Wednesday and Thursday are still checked > - Renew subscription from 2017-10-16 > - Edit subscription, > - Make sure that Wednesday and Thursday are still checked > with corresponding serials > > - Do the same for a monthly and weekly subscription > >Rebased - 2017-12-15 - Alex Arnaud <alex.arnaud@biblibre.com> > >Signed-off-by: David Nind <david@davidnind.com> > >Rebased - 2021-03-04 - Alex Arnaud <alex.arnaud@biblibre.com> > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >Signed-off-by: David Nind <david@davidnind.com> >--- > C4/Serials.pm | 251 +++++++++--------- > Koha/Subscription.pm | 144 +++++++++- > ...ug_17656-add-permanent-irregularities.perl | 9 + > installer/data/mysql/kohastructure.sql | 3 +- > .../serials/subscription_daily_choice.inc | 30 +++ > .../serials/subscription_monthly_choice.inc | 40 +++ > .../serials/subscription_weekly_choice.inc | 27 ++ > .../modules/serials/showpredictionpattern.tt | 31 ++- > .../en/modules/serials/subscription-add.tt | 3 +- > .../en/modules/serials/subscription-renew.tt | 45 +++- > .../prog/js/showpredictionpattern.js | 21 +- > .../intranet-tmpl/prog/js/subscription-add.js | 2 +- > .../intranet-tmpl/prog/js/subscription.js | 99 +++++++ > serials/showpredictionpattern.pl | 25 +- > serials/subscription-add.pl | 133 ++++------ > serials/subscription-renew.pl | 60 ++++- > t/Serials/IssueNumber.t | 47 ++++ > t/db_dependent/Koha/Subscription.t | 45 +++- > .../Koha/Subscription/GuessEnddate.t | 172 ++++++++++++ > .../Koha/Subscription/Irregularities.t | 195 ++++++++++++++ > .../Serials/SubscriptionIrregularity.t | 37 +++ > 21 files changed, 1177 insertions(+), 242 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.perl > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/subscription.js > create mode 100644 t/Serials/IssueNumber.t > create mode 100644 t/db_dependent/Koha/Subscription/GuessEnddate.t > create mode 100644 t/db_dependent/Koha/Subscription/Irregularities.t > create mode 100644 t/db_dependent/Serials/SubscriptionIrregularity.t > >diff --git a/C4/Serials.pm b/C4/Serials.pm >index da29ddbe307..ccebd87f334 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -20,7 +20,7 @@ package C4::Serials; > > use Modern::Perl; > >-use Carp qw( croak ); >+use Carp qw( croak ); > use Date::Calc qw( > Add_Delta_Days > Add_Delta_YM >@@ -30,14 +30,14 @@ use Date::Calc qw( > Today > ); > use DateTime; >-use POSIX qw( strftime ); >+use POSIX qw( strftime ); > use Scalar::Util qw( looks_like_number ); > use Try::Tiny; > >-use C4::Auth qw( haspermission ); >+use C4::Auth qw( haspermission ); > use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); > use C4::Context; >-use C4::Log qw( logaction ); # logaction >+use C4::Log qw( logaction ); # logaction > use C4::Serials::Frequency qw( GetSubscriptionFrequency ); > use C4::Serials::Numberpattern; > use Koha::AdditionalFieldValues; >@@ -107,6 +107,8 @@ BEGIN { > HasItems > > findSerialsByStatus >+ &subscriptionCurrentlyOnOrder >+ &issue_number > > ); > } >@@ -1300,37 +1302,6 @@ sub ModNextExpected { > > } > >-=head2 GetSubscriptionIrregularities >- >-=over 4 >- >-=item @irreg = &GetSubscriptionIrregularities($subscriptionid); >-get the list of irregularities for a subscription >- >-=back >- >-=cut >- >-sub GetSubscriptionIrregularities { >- my $subscriptionid = shift; >- >- return unless $subscriptionid; >- >- my $dbh = C4::Context->dbh; >- my $query = qq{ >- SELECT irregularity >- FROM subscription >- WHERE subscriptionid = ? >- }; >- my $sth = $dbh->prepare($query); >- $sth->execute($subscriptionid); >- >- my ($result) = $sth->fetchrow_array; >- my @irreg = split /;/, $result; >- >- return @irreg; >-} >- > =head2 ModSubscription > > this function modifies a subscription. Put all new values on input args. >@@ -1340,11 +1311,11 @@ returns the number of rows affected > > sub ModSubscription { > my ( >- $auser, $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, >+ $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, >+ $periodicity, $firstacquidate, $irregularity, $permanent_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 >@@ -1353,45 +1324,46 @@ sub ModSubscription { > my $subscription = Koha::Subscriptions->find($subscriptionid); > $subscription->set( > { >- librarian => $auser, >- branchcode => $branchcode, >- aqbooksellerid => $aqbooksellerid, >- cost => $cost, >- aqbudgetid => $aqbudgetid, >- biblionumber => $biblionumber, >- startdate => $startdate, >- periodicity => $periodicity, >- numberlength => $numberlength, >- weeklength => $weeklength, >- monthlength => $monthlength, >- lastvalue1 => $lastvalue1, >- innerloop1 => $innerloop1, >- lastvalue2 => $lastvalue2, >- innerloop2 => $innerloop2, >- lastvalue3 => $lastvalue3, >- innerloop3 => $innerloop3, >- status => $status, >- notes => $notes, >- letter => $letter, >- firstacquidate => $firstacquidate, >- irregularity => $irregularity, >- numberpattern => $numberpattern, >- locale => $locale, >- callnumber => $callnumber, >- manualhistory => $manualhistory, >- internalnotes => $internalnotes, >- serialsadditems => $serialsadditems, >- staffdisplaycount => $staffdisplaycount, >- opacdisplaycount => $opacdisplaycount, >- graceperiod => $graceperiod, >- location => $location, >- enddate => $enddate, >- skip_serialseq => $skip_serialseq, >- itemtype => $itemtype, >- previousitemtype => $previousitemtype, >- mana_id => $mana_id, >- ccode => $ccode, >- published_on_template => $published_on_template, >+ librarian => $auser, >+ branchcode => $branchcode, >+ aqbooksellerid => $aqbooksellerid, >+ cost => $cost, >+ aqbudgetid => $aqbudgetid, >+ biblionumber => $biblionumber, >+ startdate => $startdate, >+ periodicity => $periodicity, >+ numberlength => $numberlength, >+ weeklength => $weeklength, >+ monthlength => $monthlength, >+ lastvalue1 => $lastvalue1, >+ innerloop1 => $innerloop1, >+ lastvalue2 => $lastvalue2, >+ innerloop2 => $innerloop2, >+ lastvalue3 => $lastvalue3, >+ innerloop3 => $innerloop3, >+ status => $status, >+ notes => $notes, >+ letter => $letter, >+ firstacquidate => $firstacquidate, >+ irregularity => $irregularity, >+ permanent_irregularity => $permanent_irregularity, >+ numberpattern => $numberpattern, >+ locale => $locale, >+ callnumber => $callnumber, >+ manualhistory => $manualhistory, >+ internalnotes => $internalnotes, >+ serialsadditems => $serialsadditems, >+ staffdisplaycount => $staffdisplaycount, >+ opacdisplaycount => $opacdisplaycount, >+ graceperiod => $graceperiod, >+ location => $location, >+ enddate => $enddate, >+ skip_serialseq => $skip_serialseq, >+ itemtype => $itemtype, >+ previousitemtype => $previousitemtype, >+ mana_id => $mana_id, >+ ccode => $ccode, >+ published_on_template => $published_on_template, > } > )->store; > >@@ -1424,58 +1396,59 @@ the id of this new subscription > > sub NewSubscription { > my ( >- $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, >- $startdate, $periodicity, $numberlength, $weeklength, $monthlength, >- $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, >- $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, >- $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, >- $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, >- $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, >+ $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, >+ $startdate, $periodicity, $numberlength, $weeklength, $monthlength, >+ $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, >+ $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, >+ $permanent_irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, >+ $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, >+ $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, > $published_on_template, > ) = @_; > my $dbh = C4::Context->dbh; > > my $subscription = Koha::Subscription->new( > { >- librarian => $auser, >- branchcode => $branchcode, >- aqbooksellerid => $aqbooksellerid, >- cost => $cost, >- aqbudgetid => $aqbudgetid, >- biblionumber => $biblionumber, >- startdate => $startdate, >- periodicity => $periodicity, >- numberlength => $numberlength, >- weeklength => $weeklength, >- monthlength => $monthlength, >- lastvalue1 => $lastvalue1, >- innerloop1 => $innerloop1, >- lastvalue2 => $lastvalue2, >- innerloop2 => $innerloop2, >- lastvalue3 => $lastvalue3, >- innerloop3 => $innerloop3, >- status => $status, >- notes => $notes, >- letter => $letter, >- firstacquidate => $firstacquidate, >- irregularity => $irregularity, >- numberpattern => $numberpattern, >- locale => $locale, >- callnumber => $callnumber, >- manualhistory => $manualhistory, >- internalnotes => $internalnotes, >- serialsadditems => $serialsadditems, >- staffdisplaycount => $staffdisplaycount, >- opacdisplaycount => $opacdisplaycount, >- graceperiod => $graceperiod, >- location => $location, >- enddate => $enddate, >- skip_serialseq => $skip_serialseq, >- itemtype => $itemtype, >- previousitemtype => $previousitemtype, >- mana_id => $mana_id, >- ccode => $ccode, >- published_on_template => $published_on_template, >+ librarian => $auser, >+ branchcode => $branchcode, >+ aqbooksellerid => $aqbooksellerid, >+ cost => $cost, >+ aqbudgetid => $aqbudgetid, >+ biblionumber => $biblionumber, >+ startdate => $startdate, >+ periodicity => $periodicity, >+ numberlength => $numberlength, >+ weeklength => $weeklength, >+ monthlength => $monthlength, >+ lastvalue1 => $lastvalue1, >+ innerloop1 => $innerloop1, >+ lastvalue2 => $lastvalue2, >+ innerloop2 => $innerloop2, >+ lastvalue3 => $lastvalue3, >+ innerloop3 => $innerloop3, >+ status => $status, >+ notes => $notes, >+ letter => $letter, >+ firstacquidate => $firstacquidate, >+ irregularity => $irregularity, >+ permanent_irregularity => $permanent_irregularity, >+ numberpattern => $numberpattern, >+ locale => $locale, >+ callnumber => $callnumber, >+ manualhistory => $manualhistory, >+ internalnotes => $internalnotes, >+ serialsadditems => $serialsadditems, >+ staffdisplaycount => $staffdisplaycount, >+ opacdisplaycount => $opacdisplaycount, >+ graceperiod => $graceperiod, >+ location => $location, >+ enddate => $enddate, >+ skip_serialseq => $skip_serialseq, >+ itemtype => $itemtype, >+ previousitemtype => $previousitemtype, >+ mana_id => $mana_id, >+ ccode => $ccode, >+ published_on_template => $published_on_template, > } > )->store; > $subscription->discard_changes; >@@ -2820,6 +2793,34 @@ sub findSerialsByStatus { > return @$serials; > } > >+=head2 issue_number >+ >+ my $week_number = issue_number($dt, 'week'); >+ >+=cut >+ >+sub issue_number { >+ my ( $date, $issue_type ) = @_; >+ >+ unless ( ref($date) eq 'DateTime' ) { >+ Koha::Exceptions::WrongParameter->throw("Date passed to issue_number is not a valid DateTime object"); >+ } >+ >+ if ( $issue_type eq 'day' ) { >+ return $date->dow; >+ } >+ >+ if ( $issue_type eq 'week' ) { >+ return $date->week_number; >+ } >+ >+ if ( $issue_type eq 'month' ) { >+ return $date->month; >+ } >+ >+ return 0; >+} >+ > 1; > __END__ > >diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm >index c401cb89a25..0ad06feacce 100644 >--- a/Koha/Subscription.pm >+++ b/Koha/Subscription.pm >@@ -19,6 +19,9 @@ package Koha::Subscription; > > use Modern::Perl; > >+use C4::Serials::Frequency; >+use C4::Serials qw(issue_number); >+ > use Koha::Database; > use Koha::Biblios; > use Koha::Acquisition::Booksellers; >@@ -26,6 +29,9 @@ use Koha::Biblioitems; > use Koha::Subscriptions; > use Koha::Subscription::Frequencies; > use Koha::Subscription::Numberpatterns; >+use Koha::DateUtils; >+use JSON; >+use Date::Calc qw( Delta_Days Add_Delta_Days Add_Delta_YM ); > > use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields); > >@@ -191,7 +197,143 @@ sub get_sharable_info { > return $sub_mana_info; > } > >-=head3 _type >+=head2 irregularities >+ >+Returns an array containing irregularities >+ >+=cut >+ >+sub irregularities { >+ my ($self) = @_; >+ >+ return split( ';', $self->irregularity ); >+} >+ >+=head2 permanent_irregularities >+ >+Returns an array containing permanent irregularities >+ >+=cut >+ >+sub permanent_irregularities { >+ my ($self) = @_; >+ >+ return split( ';', $self->permanent_irregularity ); >+} >+ >+=head3 lengthtype >+ >+Return the length type (issues, weeks, months) >+ >+=cut >+ >+sub lengthtype { >+ my ($self) = @_; >+ >+ if ( $self->numberlength ) { >+ return 'issues'; >+ } >+ >+ if ( $self->weeklength ) { >+ return 'weeks'; >+ } >+ >+ if ( $self->monthlength ) { >+ return 'months'; >+ } >+} >+ >+=head3 guess_irregularities >+ >+my @irregularities = $subscription->guess_irregularities >+ >+=cut >+ >+sub guess_irregularities { >+ my ($self) = @_; >+ >+ my @irregularities; >+ my %permanent_irregularities = map { $_ => 1 } $self->permanent_irregularities; >+ >+ my $schema = Koha::Database->new->schema; >+ my $frequency = $schema->resultset('SubscriptionFrequency')->find( $self->periodicity ); >+ >+ my $enddate = $self->enddate; >+ my $nextexpected = C4::Serials::GetNextExpected( $self->id ); >+ my $date = $nextexpected->{planneddate}; >+ >+ my ($issuenumber) = C4::Serials::GetFictiveIssueNumber( $self->unblessed, $date ); >+ my $dow = issue_number( dt_from_string($date), $frequency->unit ); >+ >+ if ( defined( $permanent_irregularities{$dow} ) ) { >+ push @irregularities, $issuenumber; >+ } >+ >+ while ( Delta_Days( split( /-/, $date ), split( /-/, $enddate ) ) >= 0 ) { >+ $issuenumber++; >+ $date = C4::Serials::GetNextDate( $self->unblessed, $date ); >+ $dow = issue_number( dt_from_string($date), $frequency->unit ); >+ >+ if ( defined( $permanent_irregularities{$dow} ) ) { >+ push @irregularities, $issuenumber; >+ } >+ } >+ >+ return @irregularities; >+} >+ >+=head2 guess_enddate >+ >+my $enddate = $subscription->guess_enddate; >+ >+=cut >+ >+sub guess_enddate { >+ my ($self) = @_; >+ >+ my ( $year, $month, $day, $enddate ); >+ my $startdate = $self->startdate; >+ my $numberlength = $self->numberlength; >+ my $weeklength = $self->weeklength; >+ my $monthlength = $self->monthlength; >+ >+ if ( $numberlength != 0 ) { >+ my $frequency = GetSubscriptionFrequency( $self->periodicity ); >+ if ( $frequency->{'unit'} eq 'day' ) { >+ ( $year, $month, $day ) = Add_Delta_Days( >+ split( /-/, $startdate ), >+ $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'} >+ ); >+ } elsif ( $frequency->{'unit'} eq 'week' ) { >+ ( $year, $month, $day ) = Add_Delta_Days( >+ split( /-/, $startdate ), >+ $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'} >+ ); >+ } elsif ( $frequency->{'unit'} eq 'month' ) { >+ ( $year, $month, $day ) = Add_Delta_YM( >+ split( /-/, $startdate ), 0, >+ $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'} >+ ); >+ } elsif ( $frequency->{'unit'} eq 'year' ) { >+ ( $year, $month, $day ) = Add_Delta_YM( >+ split( /-/, $startdate ), >+ $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0 >+ ); >+ } >+ } elsif ( $weeklength != 0 ) { >+ ( $year, $month, $day ) = Add_Delta_Days( split( /-/, $startdate ), $weeklength * 7 ); >+ } elsif ( $monthlength != 0 ) { >+ ( $year, $month, $day ) = Add_Delta_YM( split( /-/, $startdate ), 0, $monthlength ); >+ } >+ if ( defined $year ) { >+ $enddate = sprintf( "%04d-%02d-%02d", $year, $month, $day ); >+ } else { >+ undef $enddate; >+ } >+ return $enddate; >+} >+ >+=head3 type > > =cut > >diff --git a/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.perl b/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.perl >new file mode 100644 >index 00000000000..739f7e33ff2 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.perl >@@ -0,0 +1,9 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ if( !column_exists( 'subscription', 'permanent_irregularity' ) ) { >+ $dbh->do( "ALTER TABLE `subscription` ADD permanent_irregularity MEDIUMTEXT AFTER irregularity" ); >+ } >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 17656 - Irregularities in serial prediction pattern are planned only for current subscription)\n"; >+} >\ No newline at end of file >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 3bf15c1007d..27e15105a17 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -6122,6 +6122,7 @@ CREATE TABLE `subscription` ( > `firstacquidate` date DEFAULT NULL COMMENT 'first issue received date', > `manualhistory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes or no to managing the history manually', > `irregularity` mediumtext DEFAULT NULL COMMENT 'any irregularities in the subscription', >+ `permanent_irregularity` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permanent irregularities for renewal', > `skip_serialseq` tinyint(1) NOT NULL DEFAULT 0, > `letter` varchar(20) DEFAULT NULL, > `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id', >@@ -6755,4 +6756,4 @@ CREATE TABLE `zebraqueue` ( > /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; > /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; > >--- Dump completed on 2024-11-25 12:13:27 >+-- Dump completed on 2024-11-25 12:13:27 >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc >new file mode 100644 >index 00000000000..6525718988d >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc >@@ -0,0 +1,30 @@ >+<p><em> If there is a day (or more) in the week where issues are never published, you can check corresponding boxes below. </em></p> >+[% daily_choice = [ {name => 'monday', value => 1}, {name => 'tuesday', value => 2}, {name => 'wednesday', value => 3}, {name => 'thursday', value => 4}, {name => 'friday', value => 5}, {name => 'saturday', value => 6}, {name => 'sunday', value => 7} ] %] >+ >+[% BLOCK days %] >+ [% SWITCH d %] >+ [% CASE 'monday' %] >+ Monday >+ [% CASE 'tuesday' %] >+ Tuesday >+ [% CASE 'wednesday' %] >+ Wednesday >+ [% CASE 'thursday' %] >+ Thursday >+ [% CASE 'friday' %] >+ Friday >+ [% CASE 'saturday' %] >+ Saturday >+ [% CASE 'sunday' %] >+ Sunday >+ [% END %] >+[% END %] >+ >+[% FOREACH day IN daily_choice %] >+ [% IF permanent_irreg.grep( day.value ).0 == day.value %] >+ <input type="checkbox" name="permanent_irregularity" id="[% day.name %]" data-dow="[% day.value %]" value="[% day.value %]" class="skip" checked="checked" /> >+ [% ELSE %] >+ <input type="checkbox" name="permanent_irregularity" id="[% day.name %]" data-dow="[% day.value %]" value="[% day.value %]" class="skip" /> >+ [% END %] >+ <label for="[% day.name | html %]" class="inline">[% PROCESS days d=day.name %]</label> >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc >new file mode 100644 >index 00000000000..bb4eb58d759 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc >@@ -0,0 +1,40 @@ >+<p><em> If there is a month (or more) in the year where issues are never published, you can check corresponding boxes below. </em></p> >+[% monthly_choice = [ {name => 'january', value => 1}, {name => 'february', value => 2}, {name => 'march', value => 3}, {name => 'april', value => 4}, {name => 'may', value => 5}, {name => 'june', value => 6}, {name => 'july', value => 7}, {name => 'august', value => 8}, {name => 'september', value => 9}, {name => 'october', value => 10}, {name => 'november', value => 11}, {name => 'december', value =>12} ] %] >+ >+[% BLOCK months %] >+ [% SWITCH m %] >+ [% CASE 'january' %] >+ January >+ [% CASE 'february' %] >+ February >+ [% CASE 'march' %] >+ March >+ [% CASE 'april' %] >+ April >+ [% CASE 'may' %] >+ May >+ [% CASE 'june' %] >+ June >+ [% CASE 'july' %] >+ July >+ [% CASE 'august' %] >+ August >+ [% CASE 'september' %] >+ September >+ [% CASE 'october' %] >+ October >+ [% CASE 'november' %] >+ November >+ [% CASE 'december' %] >+ December >+ [% END %] >+[% END %] >+ >+[% FOREACH month IN monthly_choice %] >+ [% IF permanent_irreg.grep( month.value ).0 == month.value %] >+ <input type="checkbox" name="permanent_irregularity" id="[% month.name %]" data-dow="[% month.value %]" value="[% month.value %]" class="skip" checked="checked" /> >+ [% ELSE %] >+ <input type="checkbox" name="permanent_irregularity" id="[% month.name %]" data-dow="[% month.value %]" value="[% month.value %]" class="skip" /> >+ [% END %] >+ <label for="[% month.name | html %]" class="inline">[% PROCESS months m=month.name %]</label> >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc >new file mode 100644 >index 00000000000..1817d66371c >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc >@@ -0,0 +1,27 @@ >+<div class="row select-weeks"> >+ <div class="col-lg-12"> >+ <div class="button-group"> >+ <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"> >+ Week(s) not published >+ <span class="caret"></span> >+ </button> >+ <ul class="dropdown-menu week-columns"> >+ [% FOREACH p IN predictions_loop %] >+ <li> >+ <a href="#" class="small"> >+ [% IF permanent_irreg.grep( p.dow ).0 == p.dow %] >+ <input type="checkbox" name="permanent_irregularity" value="[% p.dow %]" data-dow="[% p.dow %]" class="skip" checked="checked" /> >+ [% ELSE %] >+ <input type="checkbox" name="permanent_irregularity" value="[% p.dow %]" data-dow="[% p.dow %]" class="skip" /> >+ [% END %] >+ Week <b>#[% p.dow %]</b> ([% p.publicationdate | $KohaDates %]) >+ </a> >+ </li> >+ [% END %] >+ </ul> >+ </div> >+ </div> >+</div> >+<p> >+ <em>Choice the week(s) in the year where issues are never published.</em> >+</p> >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 7522a9d7fcc..ce2dc3ab426 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >@@ -5,22 +5,21 @@ > [% END %] > [% IF (ask_for_irregularities) %] > <p><em>Please check issues that are NOT published (irregularities)</em></p> >- [% IF (daily_options) %] >- <p><em> If there is a day (or more) in the week where issues are never published, you can check corresponding boxes below. </em></p> >- <input type="checkbox" id="monday" data-dow="1" class="skipday" /> >- <label for="monday">Monday</label> >- <input type="checkbox" id="tuesday" data-dow="2" class="skipday" /> >- <label for="tuesday">Tuesday</label> >- <input type="checkbox" id="wednesday" data-dow="3" class="skipday" /> >- <label for="wednesday">Wednesday</label> >- <input type="checkbox" id="thursday" data-dow="4" class="skipday" /> >- <label for="thursday">Thursday</label> >- <input type="checkbox" id="friday" data-dow="5" class="skipday" /> >- <label for="friday">Friday</label> >- <input type="checkbox" id="saturday" data-dow="6" class="skipday" /> >- <label for="saturday">Saturday</label> >- <input type="checkbox" id="sunday" data-dow="7" class="skipday" /> >- <label for="sunday">Sunday</label> >+ [% IF (show_irregularity_options) %] >+ <script> >+ //<![CDATA[ >+ $(document).ready(function () { >+ Check_permanent_irregularities(); >+ }); >+ //]]> >+ </script> >+ [% IF (show_irregularity_options == 'day') %] >+ [% INCLUDE 'serials/subscription_daily_choice.inc' %] >+ [% ELSIF (show_irregularity_options == 'month') %] >+ [% INCLUDE 'serials/subscription_monthly_choice.inc' %] >+ [% ELSIF (show_irregularity_options == 'week') %] >+ [% INCLUDE 'serials/subscription_weekly_choice.inc' %] >+ [% END %] > [% END %] > [% END %] > [% IF (predictions_loop) %] >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 1e62a1108e4..e2ad9252767 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 >@@ -379,7 +379,7 @@ > <select name="numbering_pattern" id="numberpattern" class="required" required="required"> > <option value="">-- please choose --</option> > [% FOREACH numberpattern IN numberpatterns %] >- <option value="[% numberpattern.id | html %]" [% IF numberpattern.selected %]selected="selected"[% END %]> [% numberpattern.label | html %] </option> >+ <option value="[% numberpattern.id | html %]" [% IF numberpattern.selected %]selected="selected"[% END %]> </option> > [% END %] > </select> > <span class="required">Required</span> >@@ -602,6 +602,7 @@ > [%- END -%] > var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | html %]; > </script> >+ [% Asset.js("js/subscription.js") | $raw %] > [% Asset.js("js/subscription-add.js") | $raw %] > [% Asset.js("js/showpredictionpattern.js") | $raw %] > [% Asset.js("js/additional-fields-entry.js") | $raw %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt >index dd29862a466..8d5a03e6568 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt >@@ -2,6 +2,7 @@ > [% USE Koha %] > [% USE Branches %] > [% PROCESS 'i18n.inc' %] >+[% USE Asset %] > [% SET footerjs = 1 %] > [% INCLUDE 'doc-head-open.inc' %] > <title >@@ -60,6 +61,36 @@ > [% INCLUDE 'csrf-token.inc' %] > <input type="hidden" name="op" value="cud-renew" /> > <input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" /> >+ <input type="hidden" id="frequency" value="[% subscription.periodicity | html %]" /> >+ <input type="hidden" id="acqui_date" value="[% subscription.firstacquidate | html %]" /> >+ <input type="hidden" id="nextacquidate" value="[% nextacquidate | html %]" /> >+ >+ <input type="hidden" id="to" value="[% enddate | html %]" /> >+ <input type="hidden" id="subtype" value="[% lengthtype | html %]" /> >+ <input type="hidden" id="sublength" value="[% sublength | html %]" /> >+ <input type="hidden" id="numberingmethod" value="[% numberpattern.numberingmethod | html %]" /> >+ <input type="hidden" id="lastvalue1" value="[% subscription.lastvalue1 | html %]" /> >+ <input type="hidden" id="lastvalue2" value="[% subscription.lastvalue2 | html %]" /> >+ <input type="hidden" id="lastvalue3" value="[% subscription.lastvalue3 | html %]" /> >+ <input type="hidden" id="add1" value="[% numberpattern.add1 | html %]" /> >+ <input type="hidden" id="add2" value="[% numberpattern.add2 | html %]" /> >+ <input type="hidden" id="add3" value="[% numberpattern.add3 | html %]" /> >+ <input type="hidden" id="every1" value="[% numberpattern.every1 | html %]" /> >+ <input type="hidden" id="every2" value="[% numberpattern.every2 | html %]" /> >+ <input type="hidden" id="every3" value="[% numberpattern.every3 | html %]" /> >+ <input type="hidden" id="innerloop1" value="[% subscription.innerloop1 | html %]" /> >+ <input type="hidden" id="innerloop2" value="[% subscription.innerloop2 | html %]" /> >+ <input type="hidden" id="innerloop3" value="[% subscription.innerloop3 | html %]" /> >+ <input type="hidden" id="setto1" value="[% numberpattern.setto1 | html %]" /> >+ <input type="hidden" id="setto2" value="[% numberpattern.setto2 | html %]" /> >+ <input type="hidden" id="setto3" value="[% numberpattern.setto3 | html %]" /> >+ <input type="hidden" id="numbering1" value="[% numberpattern.numbering1 | html %]" /> >+ <input type="hidden" id="numbering2" value="[% numberpattern.numbering2 | html %]" /> >+ <input type="hidden" id="numbering3" value="[% numberpattern.numbering3 | html %]" /> >+ <input type="hidden" id="whenmorethan1" value="[% numberpattern.whenmorethan1 | html %]" /> >+ <input type="hidden" id="whenmorethan2" value="[% numberpattern.whenmorethan2 | html %]" /> >+ <input type="hidden" id="whenmorethan3" value="[% numberpattern.whenmorethan3 | html %]" /> >+ <input type="hidden" id="locale" value="[% subscription.locale | html %]" /> > <fieldset class="rows" > ><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend> > <ol> >@@ -109,6 +140,8 @@ > <textarea name="note" id="note" rows="5" cols="50"></textarea> > </li> > [% END %] >+ >+ <li id="displayexample"></li> > </ol> > </fieldset> > <nav class="navbar navbar-default fixed-bottom"> >@@ -125,14 +158,22 @@ > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'calendar.inc' %] > <script> >- $(document).ready(function () { >- $(".close").on("click", function (e) { >+ var subscriptionid = "[% subscription.subscriptionid %]"; >+ var irregularity = "[% subscription.irregularity %]"; >+ var more_than_one_serial = "[% more_than_one_serial %]"; >+ $(document).ready(function(){ >+ if (subscriptionid) { >+ testPredictionPattern(); >+ } >+ $(".close").on("click", function(e){ > e.preventDefault(); > window.opener.location.reload(false); > self.close(); > }); > }); > </script> >+ [% Asset.js("js/subscription.js") | $raw %] >+ [% Asset.js("js/showpredictionpattern.js") | $raw %] > [% END %] > > [% INCLUDE 'intranet-bottom.inc' popup_window=1 %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js b/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js >index 0b92ec67431..767be0049cd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js >@@ -8,9 +8,28 @@ function Check_boxes(dow) { > $(this).prop("checked", false); > }); > } >+ return false; >+} >+function Check_permanent_irregularities() { >+ nothing_checked = 1; >+ $("input[name='irregularity']").each(function () { >+ if ($(this).is(":checked")) { >+ nothing_checked = 0; >+ } >+ }); >+ >+ // No day/month/week are checked, could be after a renewal. >+ // So check them according to permanent irregularity >+ if (nothing_checked) { >+ $(".skip").each(function () { >+ if ($(this).is(":checked")) { >+ Check_boxes($(this).data("dow")); >+ } >+ }); >+ } > } > $(document).ready(function () { >- $("#displayexample").on("change", ".skipday", function () { >+ $("#displayexample").on("change", ".skip", function () { > Check_boxes($(this).data("dow")); > }); > }); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >index dbd0942bc0f..58fc66f3e83 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >@@ -699,7 +699,7 @@ function showPredictionPatternTest(data) { > $("#page_2 > div").attr("class", "col-sm-6"); > } > >-function hidePredcitionPatternTest() { >+function hidePredictionPatternTest() { > $("#displayexample").hide(); > $("#page_2 > div").attr( > "class", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription.js b/koha-tmpl/intranet-tmpl/prog/js/subscription.js >new file mode 100644 >index 00000000000..3022ba8d5ad >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/subscription.js >@@ -0,0 +1,99 @@ >+var advancedpatternlocked; >+ >+function testPredictionPattern() { >+ var frequencyid = $("#frequency").val(); >+ var acquidate; >+ var error = 0; >+ var error_msg = ""; >+ if (frequencyid == undefined || frequencyid == "") { >+ error_msg += "- " + MSG_FREQUENCY_UNDEFINED + "\n"; >+ error++; >+ } >+ acquidate = $("#acqui_date").val(); >+ if (acquidate == undefined || acquidate == "") { >+ error_msg += "-" + MSG_PUB_DATE_UNDEFINED + "\n"; >+ error++; >+ } >+ if (more_than_one_serial !== "") { >+ var nextacquidate = $("#nextacquidate").val(); >+ if (nextacquidate == undefined || nextacquidate == "") { >+ error_msg += "-" + MSG_NEXT_ISSUE_UNDEFINED + "\n"; >+ error++; >+ } >+ } >+ >+ if (error) { >+ alert(MSG_PATTERN_TEST_FAILED.format(error_msg)); >+ return false; >+ } >+ >+ var custompattern = 0; >+ if (advancedpatternlocked == 0) { >+ custompattern = 1; >+ } >+ >+ var ajaxData = { >+ custompattern: custompattern, >+ firstacquidate: acquidate, >+ }; >+ >+ if (subscriptionid !== "") { >+ ajaxData.subscriptionid = subscriptionid; >+ } >+ if (more_than_one_serial !== "") { >+ ajaxData.nextacquidate = nextacquidate; >+ } >+ >+ var ajaxParams = [ >+ "to", >+ "subtype", >+ "sublength", >+ "frequency", >+ "numberingmethod", >+ "lastvalue1", >+ "lastvalue2", >+ "lastvalue3", >+ "add1", >+ "add2", >+ "add3", >+ "every1", >+ "every2", >+ "every3", >+ "innerloop1", >+ "innerloop2", >+ "innerloop3", >+ "setto1", >+ "setto2", >+ "setto3", >+ "numbering1", >+ "numbering2", >+ "numbering3", >+ "whenmorethan1", >+ "whenmorethan2", >+ "whenmorethan3", >+ "locale", >+ "sfdescription", >+ "unitsperissue", >+ "issuesperunit", >+ "unit", >+ ]; >+ for (i in ajaxParams) { >+ var param = ajaxParams[i]; >+ var value = $("#" + param).val(); >+ if (value && value.length > 0) ajaxData[param] = value; >+ } >+ >+ $.ajax({ >+ url: "/cgi-bin/koha/serials/showpredictionpattern.pl", >+ data: ajaxData, >+ success: function (data) { >+ showPredictionPatternTest(data); >+ patternneedtobetested = 0; >+ }, >+ }); >+} >+ >+function showPredictionPatternTest(data) { >+ $("#displayexample").html(data).show(); >+ $("#page_2 > div").attr("class", "col-xs-6"); >+} >diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl >index 19d414ccba0..e3652fb494d 100755 >--- a/serials/showpredictionpattern.pl >+++ b/serials/showpredictionpattern.pl >@@ -30,10 +30,10 @@ publication date, based on frequency and first publication date. > > 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 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::Frequency; > use Koha::DateUtils qw( dt_from_string ); >@@ -119,15 +119,19 @@ if ( defined $subscriptionid ) { > > my @predictions_loop; > my ($calculated) = GetSeq( \%subscription, \%pattern ); >+my $dow = issue_number( dt_from_string($date), $frequency->{unit} ); > push @predictions_loop, { > number => $calculated, > publicationdate => $date, > issuenumber => $issuenumber, >- dow => Day_of_Week( split /-/, $date ), >+ dow => $dow, > }; >-my @irreg = (); >+my @irreg = (); >+my @permanent_irreg = (); > if ( defined $subscriptionid ) { >- @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid); >+ my $subscription_o = Koha::Subscriptions->find($subscriptionid); >+ @irreg = $subscription_o->irregularities; >+ @permanent_irreg = $subscription_o->permanent_irregularities; > while ( @irreg && $issuenumber > $irreg[0] ) { > shift @irreg; > } >@@ -146,7 +150,7 @@ while ( $i < 1000 ) { > } > if ( defined $date ) { > $line{'publicationdate'} = $date; >- $line{'dow'} = Day_of_Week( split /-/, $date ); >+ $line{dow} = issue_number( dt_from_string($date), $frequency->{unit} ); > } > > # Check if we don't have exceed end date >@@ -193,8 +197,9 @@ $template->param( > > 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 ( $frequency->{unit} =~ /^(day|month|week)$/ and $frequency->{unitsperissue} == 1 ) { >+ $template->param( show_irregularity_options => $frequency->{unit} ); >+ $template->param( permanent_irreg => \@permanent_irreg ); > } > } > >diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl >index 8dff9699782..f3ea5f69e08 100755 >--- a/serials/subscription-add.pl >+++ b/serials/subscription-add.pl >@@ -17,10 +17,10 @@ > > use Modern::Perl; > >-use CGI qw ( -utf8 ); >+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::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 >@@ -259,46 +259,6 @@ sub get_letter_loop { > ]; > } > >-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' ) { >@@ -314,14 +274,15 @@ sub redirect_add_subscription { > } > 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 $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 @permanent_irregularity = $query->multi_param('permanent_irregularity'); >+ my $locale = $query->param('locale'); >+ my $graceperiod = $query->param('graceperiod') || 0; > > my $subtype = $query->param('subtype'); > my $sublength = $query->param('sublength'); >@@ -362,21 +323,30 @@ sub redirect_add_subscription { > output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } ); > > if ( !defined $enddate || $enddate eq '' ) { >+ my $subscription = Koha::Subscriptions->new( >+ { >+ startdate => $startdate, >+ periodicity => $periodicity, >+ weeklength => $weeklength, >+ monthlength => $monthlength, >+ numberlength => $numberlength >+ } >+ ); >+ > if ( $subtype eq "issues" ) { >- $enddate = _guess_enddate( $firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength ); >- } else { >- $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength ); >+ $subscription->startdate($firstacquidate); > } >+ $enddate = $subscription->guess_enddate; > } > 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 >+ $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, >+ $startdate, $periodicity, $numberlength, $weeklength, >+ $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, >+ $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, >+ join( ";", @irregularity ), join( ';', @permanent_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') ) ) ) >@@ -397,9 +367,10 @@ sub redirect_add_subscription { > } > > sub redirect_mod_subscription { >- my $subscriptionid = $query->param('subscriptionid'); >- my @irregularity = $query->multi_param('irregularity'); >- my $auser = $query->param('user'); >+ my $subscriptionid = $query->param('subscriptionid'); >+ my @irregularity = $query->multi_param('irregularity'); >+ my @permanent_irregularity = $query->multi_param('permanent_irregularity'); >+ my $auser = $query->param('user'); > my $librarian => scalar $query->param('librarian'), > my $branchcode = $query->param('branchcode'); > my $cost = $query->param('cost'); >@@ -469,11 +440,20 @@ sub redirect_mod_subscription { > > # Guess end date > if ( !defined $enddate || $enddate eq '' ) { >+ my $subscription = Koha::Subscriptions->new( >+ { >+ startdate => $startdate, >+ periodicity => $periodicity, >+ weeklength => $weeklength, >+ monthlength => $monthlength, >+ numberlength => $numberlength >+ } >+ ); >+ > if ( $subtype eq "issues" ) { >- $enddate = _guess_enddate( $nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength ); >- } else { >- $enddate = _guess_enddate( $startdate, $periodicity, $numberlength, $weeklength, $monthlength ); >+ $subscription->startdate($nextacquidate); > } >+ $enddate = $subscription->guess_enddate; > } > > my $nextexpected = GetNextExpected($subscriptionid); >@@ -487,14 +467,15 @@ sub redirect_mod_subscription { > } > > 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 >+ $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, >+ $periodicity, $firstacquidate, join( ";", @irregularity ), >+ join( ';', @permanent_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 = >diff --git a/serials/subscription-renew.pl b/serials/subscription-renew.pl >index a4bb787ac2f..765a8b88304 100755 >--- a/serials/subscription-renew.pl >+++ b/serials/subscription-renew.pl >@@ -44,15 +44,18 @@ Id of the subscription this script has to renew > > use Modern::Perl; > >-use CGI qw ( -utf8 ); >+use CGI qw ( -utf8 ); > use Carp qw( carp ); > use C4::Koha; > use C4::Auth qw( get_template_and_user ); > use C4::Context; >-use C4::Auth qw( get_template_and_user ); >-use C4::Output qw( output_and_exit output_html_with_http_headers ); >-use C4::Serials qw( GetSubscription GetSubscriptionLength NewSubscription ReNewSubscription ); >+use C4::Auth qw( get_template_and_user ); >+use C4::Output qw( output_and_exit output_html_with_http_headers ); >+use C4::Serials qw( GetSubscription GetSubscriptionLength NewSubscription ReNewSubscription ); >+use C4::Serials::Frequency; >+use C4::Serials::Numberpattern; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM); > > my $query = CGI->new; > my $dbh = C4::Context->dbh; >@@ -86,6 +89,8 @@ if ( $op eq "cud-renew" ) { > print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); > } > >+ my @permanent_irregularities = $query->param('permanent_irregularity'); >+ my @irregularities = $query->param('irregularity'); > my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } ); > ( $numberlength, $weeklength, $monthlength ) = GetSubscriptionLength( $subtype, $sublength ); > ReNewSubscription( >@@ -115,6 +120,11 @@ if ( $op eq "cud-renew" ) { > monthlength => $subscription->{monthlength}, > } > ); >+ >+ $subscription = Koha::Subscriptions->find($subscriptionid); >+ my @irregularities = $subscription->guess_irregularities; >+ $subscription->permanent_irregularity( join( ';', @permanent_irregularities ) ); >+ $subscription->irregularity( join( ';', @irregularities ) ) $subscription->store; > } > } elsif ( $op eq 'multi_renew' ) { > my @subscriptions; >@@ -140,14 +150,50 @@ if ( $op eq "cud-renew" ) { > my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } ) > or output_pref( { dt => dt_from_string, dateonly => 1 } ); > >+ my ($serials_number) = GetSerials($subscriptionid); >+ if ( $serials_number > 1 ) { >+ $template->param( more_than_one_serial => 1 ); >+ } >+ >+ my $subscription_o = Koha::Subscriptions->find( $subscription->{subscriptionid} ); >+ my $lengthtype = $subscription_o->lengthtype; >+ my $nextexpected = GetNextExpected($subscriptionid); >+ $subscription_o->update( >+ { >+ startdate => $subscription->{enddate}, >+ periodicity => $subscription->{periodicity}, >+ weeklength => $subscription->{weeklength}, >+ monthlength => $subscription->{monthlength}, >+ numberlength => $subscription->{numberlength} >+ } >+ ); >+ my $enddate = $subscription_o->guess_enddate; >+ >+ my $sub_length; >+ foreach my $length_unit (qw(numberlength weeklength monthlength)) { >+ if ( $subscription->{$length_unit} ) { >+ $sub_length = $subscription->{$length_unit}; >+ last; >+ } >+ } >+ >+ my $numberpattern = GetSubscriptionNumberpattern( $subscription->{numberpattern} ); >+ > $template->param( >- startdate => $newstartdate, >- subscription => $subscription, >+ startdate => $newstartdate, >+ subscription => $subscription, >+ numberpattern => $numberpattern, >+ startdate => $newstartdate, >+ nextacquidate => $nextexpected->{planneddate}, >+ enddate => $enddate, >+ lengthtype => $lengthtype, >+ sublength => $sub_length, > ); > } > > $template->param( >- op => $op, >+ op => $op, >+ popup => ( $mode eq 'popup' ), > ); > > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/t/Serials/IssueNumber.t b/t/Serials/IssueNumber.t >new file mode 100644 >index 00000000000..d9cd65331bd >--- /dev/null >+++ b/t/Serials/IssueNumber.t >@@ -0,0 +1,47 @@ >+#!/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 Test::More tests => 10; >+use Test::Warn; >+ >+BEGIN { >+ use_ok('C4::Serials'); >+} >+ >+my $dt = DateTime->new( year => 2017, month => 1, day => 1 ); >+ >+eval { issue_number( '2017', 'day' ); }; >+is( ref($@), 'Koha::Exceptions::WrongParameter' ); >+is( $@, 'Date passed to issue_number is not a valid DateTime object' ); >+ >+is( issue_number( $dt, 'day' ), 7, '2017-01-01 is the seventh day of week' ); >+ >+is( issue_number( $dt, 'week' ), 52, '2017-01-01 is the week #52 of the year' ); >+ >+is( issue_number( $dt, 'month' ), 1, '2017-01-01 is the first month of the year' ); >+ >+$dt = DateTime->new( year => 2022, month => 9, day => 17 ); >+ >+is( issue_number( $dt, 'day' ), 6, '2022-09-17 is the sixth day of week' ); >+ >+is( issue_number( $dt, 'week' ), 37, '2022-09-17 is the week #37 of the year' ); >+ >+is( issue_number( $dt, 'month' ), 9, '2022-09-17 is the ninth month of the year' ); >+ >+is( issue_number( $dt, 'foo' ), 0, 'issue_number return 0 for others issue type' ); >diff --git a/t/db_dependent/Koha/Subscription.t b/t/db_dependent/Koha/Subscription.t >index c5c98dffc9d..871ffaafb10 100755 >--- a/t/db_dependent/Koha/Subscription.t >+++ b/t/db_dependent/Koha/Subscription.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 10; >+use Test::More tests => 11; > > use Koha::Database; > use Koha::Subscription; >@@ -125,6 +125,49 @@ subtest 'Koha::Subscription->frequency' => sub { > ); > }; > >+subtest 'Koha::Subscription::lengthtype' => sub { >+ plan tests => 3; >+ >+ my $subs = $builder->build( >+ { >+ source => 'Subscription', >+ value => { >+ numberlength => 7, >+ weeklength => 0, >+ monthlength => 0, >+ } >+ } >+ ); >+ my $subscription = Koha::Subscriptions->find( $subs->{subscriptionid} ); >+ is( $subscription->lengthtype, 'issues', 'Subscription with numberlength has issues type' ); >+ >+ my $subs2 = $builder->build( >+ { >+ source => 'Subscription', >+ value => { >+ numberlength => 0, >+ weeklength => 52, >+ monthlength => 0, >+ } >+ } >+ ); >+ my $subscription2 = Koha::Subscriptions->find( $subs2->{subscriptionid} ); >+ is( $subscription2->lengthtype, 'weeks', 'Subscription with weeklength has weeks type' ); >+ >+ my $subs3 = $builder->build( >+ { >+ source => 'Subscription', >+ value => { >+ numberlength => 0, >+ weeklength => 0, >+ monthlength => 12, >+ } >+ } >+ ); >+ my $subscription3 = Koha::Subscriptions->find( $subs3->{subscriptionid} ); >+ is( $subscription3->lengthtype, 'months', 'Subscription with monthlength has months type' ); >+}; >+ > my $nb_of_subs = Koha::Subscriptions->search->count; > my $biblio_1 = $builder->build_sample_biblio; > my $bi_1 = $biblio_1->biblioitem; >diff --git a/t/db_dependent/Koha/Subscription/GuessEnddate.t b/t/db_dependent/Koha/Subscription/GuessEnddate.t >new file mode 100644 >index 00000000000..35958675347 >--- /dev/null >+++ b/t/db_dependent/Koha/Subscription/GuessEnddate.t >@@ -0,0 +1,172 @@ >+#!/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 >+# WIT HOUT 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 Test::More tests => 15; >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+use Koha::Subscriptions; >+ >+BEGIN { >+ use_ok('Koha::Subscriptions'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+$schema->storage->txn_begin; >+ >+my $frequency = $builder->build( >+ { >+ source => 'SubscriptionFrequency', >+ value => { >+ unit => 'day', >+ unitsperissue => 1, >+ issuesperunit => 1 >+ } >+ } >+); >+ >+my $subscription = $builder->build( >+ { >+ source => 'Subscription', >+ value => { >+ startdate => '2018-01-01', >+ weeklength => 0, >+ monthlength => 0, >+ numberlength => 7, >+ periodicity => $frequency->{id}, >+ } >+ } >+); >+ >+$subscription = Koha::Subscriptions->find( $subscription->{subscriptionid} ); >+$frequency = $schema->resultset('SubscriptionFrequency')->find( $frequency->{id} ); >+is( $subscription->guess_enddate, '2018-01-08' ); >+ >+$frequency->update( >+ { >+ unit => 'day', >+ unitsperissue => 2, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2018-01-15' ); >+ >+$frequency->update( >+ { >+ unit => 'day', >+ unitsperissue => 1, >+ issuesperunit => 2 >+ } >+); >+is( $subscription->guess_enddate, '2018-01-04' ); >+ >+$frequency->update( >+ { >+ unit => 'week', >+ unitsperissue => 1, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2018-02-19' ); >+ >+$frequency->update( >+ { >+ unit => 'week', >+ unitsperissue => 2, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2018-04-09' ); >+ >+$frequency->update( >+ { >+ unit => 'week', >+ unitsperissue => 1, >+ issuesperunit => 2 >+ } >+); >+is( $subscription->guess_enddate, '2018-01-25' ); >+ >+$frequency->update( >+ { >+ unit => 'month', >+ unitsperissue => 1, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2018-08-01' ); >+ >+$frequency->update( >+ { >+ unit => 'month', >+ unitsperissue => 2, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2019-03-01' ); >+ >+$frequency->update( >+ { >+ unit => 'month', >+ unitsperissue => 1, >+ issuesperunit => 2 >+ } >+); >+is( $subscription->guess_enddate, '2018-04-01' ); >+ >+$frequency->update( >+ { >+ unit => 'year', >+ unitsperissue => 1, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2025-01-01' ); >+ >+$frequency->update( >+ { >+ unit => 'year', >+ unitsperissue => 2, >+ issuesperunit => 1 >+ } >+); >+is( $subscription->guess_enddate, '2032-01-01' ); >+ >+$frequency->update( >+ { >+ unit => 'year', >+ unitsperissue => 1, >+ issuesperunit => 2 >+ } >+); >+is( $subscription->guess_enddate, '2021-01-01' ); >+ >+$subscription->numberlength(0); >+$subscription->weeklength(2); >+$subscription->store; >+is( $subscription->guess_enddate, '2018-01-15' ); >+ >+$subscription->weeklength(0); >+$subscription->monthlength(1); >+$subscription->store; >+is( $subscription->guess_enddate, '2018-02-01' ); >+ >+$schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Subscription/Irregularities.t b/t/db_dependent/Koha/Subscription/Irregularities.t >new file mode 100644 >index 00000000000..9e4215d9a21 >--- /dev/null >+++ b/t/db_dependent/Koha/Subscription/Irregularities.t >@@ -0,0 +1,195 @@ >+#!/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 >+# WIT HOUT 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 Test::More tests => 2; >+use t::lib::TestBuilder; >+ >+use C4::Serials; >+ >+use Koha::Database; >+use Koha::Subscriptions; >+ >+BEGIN { >+ use_ok('Koha::Subscriptions'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+$schema->storage->txn_begin; >+ >+my $biblio = $builder->build( >+ { >+ source => 'Biblio', >+ } >+); >+ >+my $frequency = $builder->build( >+ { >+ source => 'SubscriptionFrequency', >+ value => { >+ unit => 'day', >+ unitsperissue => 1, >+ issuesperunit => 1 >+ } >+ } >+); >+ >+my $number_pattern = $builder->build( >+ { >+ source => 'SubscriptionNumberpattern', >+ value => { >+ numberingmethod => 'No.{X}', >+ add1 => 1, >+ every1 => 1, >+ whenmorethan1 => 99999, >+ setto1 => 1 >+ } >+ } >+); >+ >+my $subscription = $builder->build( >+ { >+ source => 'Subscription', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ startdate => '2018-05-07', >+ weeklength => 0, >+ monthlength => 0, >+ numberlength => 7, >+ periodicity => $frequency->{id}, >+ countissuesperunit => 1, >+ status => 1, >+ lastvalue1 => 5, >+ lastvalue2 => 0, >+ innerloop1 => 0, >+ innerloop2 => 0, >+ innerloop3 => 0, >+ lastvalue3 => 0, >+ firstacquidate => '2018-05-07', >+ irregularity => '3;4', >+ permanent_irregularity => '3;4', >+ numberpattern => 7, >+ enddate => '2018-05-13', >+ closed => 0 >+ } >+ } >+); >+ >+$builder->build( >+ { >+ source => 'Serial', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ subscriptionid => $subscription->{subscriptionid}, >+ serialseq => 'No.1', >+ serialseq_x => 1, >+ status => 2, >+ planneddate => '2018-05-07', >+ publisheddate => '2018-05-07', >+ } >+ } >+); >+ >+$builder->build( >+ { >+ source => 'Serial', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ subscriptionid => $subscription->{subscriptionid}, >+ serialseq => 'No.2', >+ serialseq_x => 2, >+ status => 2, >+ planneddate => '2018-05-08', >+ publisheddate => '2018-05-08', >+ } >+ } >+); >+ >+$builder->build( >+ { >+ source => 'Serial', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ subscriptionid => $subscription->{subscriptionid}, >+ serialseq => 'No.3', >+ serialseq_x => 3, >+ status => 2, >+ planneddate => '2018-05-11', >+ publisheddate => '2018-05-11', >+ } >+ } >+); >+ >+$builder->build( >+ { >+ source => 'Serial', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ subscriptionid => $subscription->{subscriptionid}, >+ serialseq => 'No.4', >+ serialseq_x => 4, >+ status => 2, >+ planneddate => '2018-05-12', >+ publisheddate => '2018-05-12', >+ } >+ } >+); >+ >+$builder->build( >+ { >+ source => 'Serial', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ subscriptionid => $subscription->{subscriptionid}, >+ serialseq => 'No.5', >+ serialseq_x => 5, >+ status => 2, >+ planneddate => '2018-05-13', >+ publisheddate => '2018-05-13', >+ } >+ } >+); >+ >+$builder->build( >+ { >+ source => 'Serial', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ subscriptionid => $subscription->{subscriptionid}, >+ serialseq => 'No.6', >+ serialseq_x => 6, >+ status => 1, >+ planneddate => '2018-05-14', >+ publisheddate => '2018-05-14', >+ } >+ } >+); >+ >+ReNewSubscription( >+ $subscription->{subscriptionid}, undef, >+ $subscription->{enddate}, $subscription->{numberlength}, >+ $subscription->{weeklength}, $subscription->{monthlength}, >+); >+ >+my $s = Koha::Subscriptions->find( $subscription->{subscriptionid} ); >+my $irregularities = join( ';', $s->guess_irregularities ); >+is( $irregularities, '10;11', 'Irregularities have been updated' ); >+ >+$schema->storage->txn_rollback; >diff --git a/t/db_dependent/Serials/SubscriptionIrregularity.t b/t/db_dependent/Serials/SubscriptionIrregularity.t >new file mode 100644 >index 00000000000..60f09e809b5 >--- /dev/null >+++ b/t/db_dependent/Serials/SubscriptionIrregularity.t >@@ -0,0 +1,37 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use t::lib::TestBuilder; >+use Test::More tests => 6; >+ >+use Koha::Database; >+ >+use_ok('Koha::Subscription'); >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $subscription = $builder->build( >+ { >+ source => 'Subscription', >+ value => { >+ irregularity => '2;4;7', >+ permanent_irregularity => '1;2' >+ }, >+ } >+); >+ >+my $subscription_o = Koha::Subscriptions->find( $subscription->{subscriptionid} ); >+my @irreg = $subscription_o->irregularities; >+is( $irreg[0], 2, 'First element of irregularities is 2' ); >+is( $irreg[1], 4, 'Second element of irregularities is 4' ); >+is( $irreg[2], 7, 'Third element of irregularities is 7' ); >+ >+my @permanent_irreg = $subscription_o->permanent_irregularities; >+is( $permanent_irreg[0], 1, 'First element of permanent_irregularities is 1' ); >+is( $permanent_irreg[1], 2, 'Second element of permanent_irregularities is 2' ); >+ >+$schema->storage->txn_rollback; >-- >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 17656
:
68259
|
68261
|
68607
|
68608
|
68665
|
69124
|
69207
|
69279
|
69553
|
69814
|
69820
|
69915
|
70335
|
70336
|
70430
|
70619
|
75403
|
75404
|
75405
|
75406
|
75407
|
75408
|
75721
|
75722
|
75723
|
75724
|
75725
|
75726
|
75953
|
102724
|
102725
|
102726
|
102727
|
102728
|
102729
|
102730
|
102860
|
102861
|
102862
|
102863
|
102864
|
102865
|
102866
|
102867
|
102960
|
102961
|
102962
|
102963
|
102964
|
102965
|
102966
|
102967
|
102968
|
103623
|
103624
|
103625
|
103626
|
103627
|
103628
|
103629
|
103630
|
103631
|
103657
|
103658
|
103659
|
103660
|
103661
|
103662
|
103663
|
103664
|
103665
|
103667
|
117789
|
117790
|
117791
|
117792
|
117846
|
117851
|
117852
|
118856
|
119106
|
120863
|
121082
|
121083
|
121084
|
121085
|
121086
|
121087
|
121088
|
121192
|
121193
|
121194
|
121195
|
121196
|
121197
|
121198
|
121296
|
121297
|
121298
|
121299
|
121300
|
121301
|
121302
|
128489
|
128491
|
128492
|
128493
|
128494
|
128495
|
128496
|
128498
|
128499
|
128500
|
128501
|
128502
|
128503
|
128504
|
132412
|
132413
|
132415
|
132416
|
132417
|
132418
|
132447
|
132448
|
132692
|
132779
|
177497
|
177498
|
177499
|
177500
|
177501
|
177502
|
177503
|
177504
|
177505
|
177663
|
177664
|
177665
|
177666
|
177667
|
177668
|
177669
|
177670
|
177671
| 177831 |
177832
|
177833
|
177834
|
177835
|
177836
|
177837
|
177838
|
177839
|
178142