Bugzilla – Attachment 121296 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), 61.39 KB, created by
Victor Grousset/tuxayo
on 2021-05-23 20:34:37 UTC
(
hide
)
Description:
Bug 17656: Keep irregularities during subscription renewals
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2021-05-23 20:34:37 UTC
Size:
61.39 KB
patch
obsolete
>From fd7e37d58bd7c9158253e71060efe218f2bd9629 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> >--- > C4/Serials.pm | 142 +++++++------- > Koha/Subscription.pm | 131 ++++++++++++- > ...ug_17656-add-permanent-irregularities.perl | 9 + > installer/data/mysql/kohastructure.sql | 1 + > .../prog/css/src/staff-global.scss | 10 + > .../serials/subscription_daily_choice.inc | 33 ++++ > .../serials/subscription_monthly_choice.inc | 38 ++++ > .../serials/subscription_weekly_choice.inc | 28 +++ > .../modules/serials/showpredictionpattern.tt | 34 ++-- > .../en/modules/serials/subscription-add.tt | 1 + > .../en/modules/serials/subscription-renew.tt | 41 ++++ > .../prog/js/showpredictionpattern.js | 21 ++- > .../intranet-tmpl/prog/js/subscription-add.js | 77 +------- > .../intranet-tmpl/prog/js/subscription.js | 78 ++++++++ > serials/showpredictionpattern.pl | 15 +- > serials/subscription-add.pl | 69 ++++--- > serials/subscription-renew.pl | 53 +++++- > t/Serials/IssueNumber.t | 47 +++++ > t/db_dependent/Koha/Subscription.t | 39 +++- > .../Koha/Subscription/GuessEnddate.t | 148 +++++++++++++++ > .../Koha/Subscription/Irregularities.t | 175 ++++++++++++++++++ > .../Serials/SubscriptionIrregularity.t | 35 ++++ > 22 files changed, 1014 insertions(+), 211 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 709a24315a..221e4f11fc 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -87,6 +87,7 @@ BEGIN { > &CountIssues > HasItems > &subscriptionCurrentlyOnOrder >+ &issue_number > > ); > } >@@ -1263,37 +1264,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. >@@ -1304,7 +1274,7 @@ returns the number of rows affected > sub ModSubscription { > my ( > $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, >- $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale, >+ $periodicity, $firstacquidate, $irregularity, $permanent_irregularity, $numberpattern, $locale, > $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1, > $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, > $biblionumber, $callnumber, $notes, $letter, $manualhistory, >@@ -1338,6 +1308,7 @@ sub ModSubscription { > letter => $letter, > firstacquidate => $firstacquidate, > irregularity => $irregularity, >+ permanent_irregularity => $permanent_irregularity, > numberpattern => $numberpattern, > locale => $locale, > callnumber => $callnumber, >@@ -1388,51 +1359,52 @@ sub NewSubscription { > $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, >+ $permanent_irregularity, $numberpattern, $locale, $callnumber, $manualhistory, >+ $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, > $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id > ) = @_; > 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, >+ 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, > } > )->store; > $subscription->discard_changes; >@@ -2687,6 +2659,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 07ab168177..39a3da2a8c 100644 >--- a/Koha/Subscription.pm >+++ b/Koha/Subscription.pm >@@ -21,6 +21,9 @@ use Modern::Perl; > > use Carp; > >+use C4::Serials::Frequency; >+use C4::Serials qw(issue_number); >+ > use Koha::Database; > use Koha::Biblios; > use Koha::Acquisition::Booksellers; >@@ -28,7 +31,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); > >@@ -197,7 +202,131 @@ sub get_sharable_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 0000000000..fb6314dc82 >--- /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"; >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 4896b9dcee..b3da1dde8a 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -4779,6 +4779,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 COLLATE utf8mb4_unicode_ci 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) COLLATE utf8mb4_unicode_ci DEFAULT NULL, > `numberpattern` int(11) DEFAULT NULL COMMENT 'the numbering pattern used links to subscription_numberpatterns.id', >diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >index 6d9db96973..0a313e6300 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >@@ -4426,6 +4426,16 @@ div .suggestion_note { > } > } > >+.week-columns{ >+ -moz-column-count: 2; /* Firefox */ >+ -webkit-column-count: 2; /* Safari and Chrome */ >+ column-count: 3; >+} >+ >+fieldset.rows label.inline { >+ float: none; >+} >+ > @media (min-width: 200px) { > > } >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 0000000000..6a7fc42da0 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc >@@ -0,0 +1,33 @@ >+<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 0000000000..6ba98e33a3 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc >@@ -0,0 +1,38 @@ >+<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 0000000000..594243e336 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc >@@ -0,0 +1,28 @@ >+<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 c684348deb..f9373b3446 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt >@@ -5,25 +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 789596e4ec..2673c6e83e 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 >@@ -587,6 +587,7 @@ fieldset.rows table { clear: none; margin: 0; } > > var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | $raw %]; > </script> >+ [% Asset.js("js/subscription.js") | $raw %] > [% Asset.js("js/subscription-add.js") | $raw %] > [% Asset.js("js/showpredictionpattern.js") | $raw %] > [% END %] >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 7d570fe8ab..e79ea3ab14 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 >@@ -1,5 +1,6 @@ > [% USE Koha %] > [% USE Branches %] >+[% USE Asset %] > [% SET footerjs = 1 %] > [% INCLUDE 'doc-head-open.inc' %] > [% IF subscription %] >@@ -30,6 +31,36 @@ > <form name="f" action="/cgi-bin/koha/serials/subscription-renew.pl" method="post"> > <input type="hidden" name="op" value="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> > <li> >@@ -78,6 +109,8 @@ > <textarea name="note" id="note" rows="5" cols="50"></textarea> > </li> > [% END %] >+ >+ <li id="displayexample"></li> > </ol> > </fieldset> > <fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset> >@@ -87,7 +120,13 @@ > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'calendar.inc' %] > <script> >+ 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); >@@ -95,6 +134,8 @@ > }); > }); > </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 f5c38a09d3..6ab01c0b0a 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 297756b59e..bfc84b29b8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >@@ -266,76 +266,6 @@ function restoreAdvancedPattern() { > advancedpatternlocked = 1; > } > >-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.length > 0) >- ajaxData[param] = value; >- } >- >- $.ajax({ >- url:"/cgi-bin/koha/serials/showpredictionpattern.pl", >- data: ajaxData, >- success: function(data) { >- showPredictionPatternTest( data ); >- patternneedtobetested = 0; >- } >- }); >-} >- > function saveAdvancedPattern() { > if ($("#patternname").val().length == 0) { > alert( MSG_PATTERN_NAME ); >@@ -530,18 +460,13 @@ function mana_comment_close(){ > $("#new_mana_comment").hide(); > } > >-function showPredictionPatternTest( data ){ >- $("#displayexample").html(data).show(); >- $("#page_2 > div").attr("class","col-xs-6"); >-} >- > function hidePredcitionPatternTest(){ > $("#displayexample").hide(); > $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2"); > } > > $(document).ready(function() { >- if ( mana_enabled == 1 ) { >+ if ( typeof mana_enabled !== 'undefined'&& mana_enabled == 1 ) { > mana_search(); > } > $("#displayexample").hide(); >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 0000000000..3638bcf90f >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/subscription.js >@@ -0,0 +1,78 @@ >+ >+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) { >+console.log(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 d6bcfc7918..0866b225d7 100755 >--- a/serials/showpredictionpattern.pl >+++ b/serials/showpredictionpattern.pl >@@ -124,15 +124,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 @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; > } >@@ -151,7 +155,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 >@@ -187,8 +191,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 8e55ce05af..22085420ec 100755 >--- a/serials/subscription-add.pl >+++ b/serials/subscription-add.pl >@@ -255,32 +255,14 @@ 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 _get_sub_length { >+ my ($type, $length) = @_; >+ return >+ ( >+ $type eq 'issues' ? $length : 0, >+ $type eq 'weeks' ? $length : 0, >+ $type eq 'months' ? $length : 0, >+ ); > } > > sub redirect_add_subscription { >@@ -304,6 +286,7 @@ sub redirect_add_subscription { > 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; > >@@ -344,19 +327,26 @@ sub redirect_add_subscription { > my $firstacquidate = 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, >+ join(";",@irregularity), join(';', @permanent_irregularity), $numberpattern, $locale, >+ $callnumber, $manualhistory, $internalnotes, $serialsadditems, > $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, > $skip_serialseq, $itemtype, $previousitemtype, $mana_id > ); >@@ -390,6 +380,7 @@ sub redirect_add_subscription { > sub redirect_mod_subscription { > 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'); >@@ -457,11 +448,18 @@ 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); >@@ -475,7 +473,8 @@ sub redirect_mod_subscription { > ModSubscription( > $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, > $periodicity, $firstacquidate, join(";",@irregularity), >- $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1, >+ join(';', @permanent_irregularity), $numberpattern, $locale, >+ $numberlength, $weeklength, $monthlength, $lastvalue1, > $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, > $status, $biblionumber, $callnumber, $notes, $letter, > $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, >diff --git a/serials/subscription-renew.pl b/serials/subscription-renew.pl >index 80727da866..af32c90c9d 100755 >--- a/serials/subscription-renew.pl >+++ b/serials/subscription-renew.pl >@@ -53,6 +53,9 @@ use C4::Context; > use C4::Auth; > use C4::Output; > use C4::Serials; >+use C4::Serials::Frequency; >+use C4::Serials::Numberpattern; >+use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM); > use Koha::DateUtils; > > my $query = CGI->new; >@@ -82,6 +85,9 @@ if ( $op eq "renew" ) { > # Make sure the subscription exists > my $subscription = GetSubscription( $subscriptionid ); > output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription; >+ >+ 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( >@@ -96,6 +102,11 @@ if ( $op eq "renew" ) { > branchcode => $branchcode > } > ); >+ >+ $subscription = Koha::Subscriptions->find($subscriptionid); >+ $subscription->permanent_irregularity(join(';', @permanent_irregularities)); >+ $subscription->irregularity(join(';', @irregularities)); >+ $subscription->store; > } elsif ( $op eq 'multi_renew' ) { > for my $subscriptionid ( @subscriptionids ) { > my $subscription = GetSubscription( $subscriptionid ); >@@ -110,6 +121,10 @@ if ( $op eq "renew" ) { > monthlength => $subscription->{monthlength}, > } > ); >+ >+ $subscription = Koha::Subscriptions->find( $subscriptionid ); >+ my @irregularities = $subscription->guess_irregularities; >+ $subscription->irregularity( join(';', @irregularities) )->store; > } > } else { > my $subscriptionid = $subscriptionids[0]; >@@ -123,14 +138,48 @@ if ( $op eq "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, >+ 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 0000000000..da07f7a755 >--- /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 6765640d38..a55db6a331 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; >@@ -106,6 +106,43 @@ subtest 'Koha::Subscription->frequency' => sub { > is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' ); > }; > >+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 0000000000..c16fb322ee >--- /dev/null >+++ b/t/db_dependent/Koha/Subscription/GuessEnddate.t >@@ -0,0 +1,148 @@ >+#!/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 0000000000..a5b34c377b >--- /dev/null >+++ b/t/db_dependent/Koha/Subscription/Irregularities.t >@@ -0,0 +1,175 @@ >+#!/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; >\ No newline at end of file >diff --git a/t/db_dependent/Serials/SubscriptionIrregularity.t b/t/db_dependent/Serials/SubscriptionIrregularity.t >new file mode 100644 >index 0000000000..2e81d0fc0d >--- /dev/null >+++ b/t/db_dependent/Serials/SubscriptionIrregularity.t >@@ -0,0 +1,35 @@ >+#!/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.31.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