From 529897bbf14241a8dcd482c683fe06e6ffb8782b Mon Sep 17 00:00:00 2001 From: Alex Arnaud 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 monthly, daily or weekly 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 --- C4/Serials.pm | 102 ++++++++------------- Koha/DateUtils.pm | 31 ++++++- Koha/Subscription.pm | 24 +++++ .../Bug_17656-add-permanent-irregularities.sql | 1 + koha-tmpl/intranet-tmpl/prog/css/staff-global.css | 6 ++ .../includes/serials/subscription_daily_choice.inc | 29 ++++++ .../serials/subscription_monthly_choice.inc | 34 +++++++ .../serials/subscription_weekly_choice.inc | 28 ++++++ .../en/modules/serials/showpredictionpattern.tt | 46 ++++++---- serials/showpredictionpattern.pl | 15 ++- serials/subscription-add.pl | 13 ++- t/db_dependent/Serials/SubscriptionIrregularity.pm | 35 +++++++ 12 files changed, 268 insertions(+), 96 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.sql 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 t/db_dependent/Serials/SubscriptionIrregularity.pm diff --git a/C4/Serials.pm b/C4/Serials.pm index d79c0a5..635b9da 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1301,37 +1301,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. @@ -1342,23 +1311,23 @@ 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, - $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, - $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype + $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 ) = @_; my $dbh = C4::Context->dbh; my $query = "UPDATE subscription SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?, startdate=?, periodicity=?, firstacquidate=?, irregularity=?, - numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?, - lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?, - lastvalue3=?, innerloop3=?, status=?, biblionumber=?, - callnumber=?, notes=?, letter=?, manualhistory=?, + 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=?, skip_serialseq=?, itemtype=?, previousitemtype=? @@ -1366,17 +1335,19 @@ sub ModSubscription { my $sth = $dbh->prepare($query); $sth->execute( - $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 ? $manualhistory : 0), - $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, - $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype, - $subscriptionid + $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 ? $manualhistory : 0), + $internalnotes, $serialsadditems, $staffdisplaycount, + $opacdisplaycount, $graceperiod, $location, + $enddate, $skip_serialseq, $itemtype, + $previousitemtype, $subscriptionid ); my $rows = $sth->rows; @@ -1407,9 +1378,10 @@ 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, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype + $permanent_irregularity, $numberpattern, $locale, $callnumber, + $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, + $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, + $itemtype, $previousitemtype ) = @_; my $dbh = C4::Context->dbh; @@ -1420,11 +1392,11 @@ sub NewSubscription { 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) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + irregularity, permanent_irregularity, numberpattern, locale, + callnumber, manualhistory, internalnotes, serialsadditems, + staffdisplaycount, opacdisplaycount, graceperiod, location, + enddate, skip_serialseq, itemtype, previousitemtype) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |; my $sth = $dbh->prepare($query); $sth->execute( @@ -1432,10 +1404,10 @@ 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, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype + $firstacquidate, $irregularity, $permanent_irregularity, + $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, + $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype ); my $subscriptionid = $dbh->{'mysql_insertid'}; diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index af5ce7e..e373fc6 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -18,13 +18,14 @@ package Koha::DateUtils; use Modern::Perl; use DateTime; +use Date::Calc qw( Day_of_Week ); use C4::Context; use Koha::Exceptions; use base 'Exporter'; our @EXPORT = ( - qw( dt_from_string output_pref format_sqldatetime ) + qw( dt_from_string output_pref format_sqldatetime issue_number ) ); =head1 DateUtils @@ -297,4 +298,32 @@ sub format_sqldatetime { return q{}; } +=head2 issue_number + +my $week_number = issue_number('2017-01-01', '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 Day_of_Week(split /-/, $date->ymd); + } + + if ($issue_type eq 'week') { + return $date->week_number; + } + + if ($issue_type eq 'month') { + return $date->month; + } + + return 0; +} + 1; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 2a793e5..839f17a 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -48,6 +48,30 @@ sub biblio { return scalar Koha::Biblios->find($self->biblionumber); } +=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 type =cut diff --git a/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.sql b/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.sql new file mode 100644 index 0000000..cb9cd1d --- /dev/null +++ b/installer/data/mysql/atomicupdate/Bug_17656-add-permanent-irregularities.sql @@ -0,0 +1 @@ +ALTER TABLE `subscription` ADD permanent_irregularity text AFTER irregularity; diff --git a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css index 86bea4d..3f4c210 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css @@ -3028,3 +3028,9 @@ fieldset.rows + fieldset.action { #patron_search #filters { display: none; } + +.week-columns{ + -moz-column-count: 2; /* Firefox */ + -webkit-column-count: 2; /* Safari and Chrome */ + column-count: 3; +} 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 0000000..d39f0a4 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_daily_choice.inc @@ -0,0 +1,29 @@ +

+ If there is a day (or more) in the week where issues are never + published, you can check corresponding boxes below. +

+[% daily_choice = [ + {name => 'monday', desc => 'Monday', value => 1}, + {name => 'tuesday', desc => 'Tuesday', value => 2}, + {name => 'wednesday', desc => 'Wednesday', value => 3}, + {name => 'thursday', desc => 'Thursday', value => 4}, + {name => 'friday', desc => 'Friday', value => 5}, + {name => 'saturday', desc => 'Saturday', value => 6}, + {name => 'sunday', desc => 'Sunday', value => 7} +] %] + +[% FOREACH day IN daily_choice %] + [% IF permanent_irreg.grep( day.value ).0 == day.value %] + + [% ELSE %] + + [% END %] + +[% 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 0000000..f28308f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_monthly_choice.inc @@ -0,0 +1,34 @@ +

+ If there is a month (or more) in the year where issues are never + published, you can check corresponding boxes below. +

+[% monthly_choice = [ + {name => 'january', desc => 'January', value => 1}, + {name => 'february', desc => 'February', value => 2}, + {name => 'march', desc => 'March', value => 3}, + {name => 'april', desc => 'April', value => 4}, + {name => 'may', desc => 'May', value => 5}, + {name => 'june', desc => 'June', value => 6}, + {name => 'july', desc => 'July', value => 7} + {name => 'august', desc => 'August', value => 8} + {name => 'september', desc => 'September', value => 9} + {name => 'october', desc => 'October', value => 10} + {name => 'november', desc => 'November', value => 11} + {name => 'december', desc => 'December', value =>12} +] %] + +[% FOREACH month IN monthly_choice %] + [% IF permanent_irreg.grep( month.value ).0 == month.value %] + + [% ELSE %] + + [% END %] + +[% 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 0000000..594243e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials/subscription_weekly_choice.inc @@ -0,0 +1,28 @@ +
+ +
+

+ Choice the week(s) in the year where issues are never + published. +

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 0df881a..dd1fa98 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt @@ -6,7 +6,7 @@ [% END %] [% IF (ask_for_irregularities) %]

Please check issues that are NOT published (irregularities)

- [% IF (daily_options) %] + [% IF (show_irregularity_options) %] -

- If there is a day (or more) in the week where issues are never - published, you can check corresponding boxes below. -

- - - - - - - - - - - - - - + [% 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/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl index 6986b5e..ba64466 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -112,15 +112,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; } @@ -139,7 +143,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 @@ -175,8 +179,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 16d397b..bb04ecd 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -294,6 +294,7 @@ sub redirect_add_subscription { my $aqbudgetid = $query->param('aqbudgetid'); my $periodicity = $query->param('frequency'); my @irregularity = $query->multi_param('irregularity'); + my @permanent_irregularity = $query->multi_param('permanent_irregularity'); my $numberpattern = $query->param('numbering_pattern'); my $locale = $query->param('locale'); my $graceperiod = $query->param('graceperiod') || 0; @@ -341,10 +342,10 @@ sub redirect_add_subscription { $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 + join(";",@irregularity), join(';', @permanent_irregularity), + $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, + $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, + $location, $enddate, $skip_serialseq ); my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); @@ -357,6 +358,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'); @@ -423,7 +425,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/t/db_dependent/Serials/SubscriptionIrregularity.pm b/t/db_dependent/Serials/SubscriptionIrregularity.pm new file mode 100644 index 0000000..2e81d0f --- /dev/null +++ b/t/db_dependent/Serials/SubscriptionIrregularity.pm @@ -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.7.4