From 269173e83db655a2267fdc2ed8e4eb2443e69ea1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 23 Nov 2021 15:38:39 +0000 Subject: [PATCH] Bug 29996: Show an alert on main page when serial issues are late MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The alert is disabled by default and can be enabled for each subscription individually. Alerts are shown on the main page only for subscriptions that have this feature enabled and that are of the same library than the connection library Test plan: 1. Run `installer/data/mysql/updatedatabase.pl` and `misc/devel/update_dbix_class_files.pl --koha-conf`. Restart Koha if needed. 2. Create a subscription, set its library to your connection library and enable "Warn when late" 3. Verify that you can see the value of "warn when late" setting on subscription-detail.pl 4. The automatically generated serial issue should have the status "Expected". Change it to "Late". 5. Go back to the main page. You should see an alert with a link to your subscription 6. Change your library using the menu in the upper right corner of the screen. Now the alert should not appear. 7. Set your library back to its original value to make the alert reappear. 8. Edit your subscription and disable "Warn when late". Verify that the alert does not appear. Sponsored-by: Écoles Nationales Supérieures d'Architecture --- C4/Serials.pm | 6 ++-- Koha/Serial.pm | 15 ++++++++++ .../data/mysql/atomicupdate/bug-29996.pl | 19 ++++++++++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/intranet-main.tt | 19 +++++++++++- .../en/modules/serials/subscription-add.tt | 9 ++++++ .../en/modules/serials/subscription-detail.tt | 8 +++++ mainpage.pl | 29 +++++++++++++++++++ serials/subscription-add.pl | 6 ++-- 9 files changed, 107 insertions(+), 5 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug-29996.pl diff --git a/C4/Serials.pm b/C4/Serials.pm index 4421bf35b0..373a31a0f5 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1323,7 +1323,7 @@ sub ModSubscription { $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, - $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, + $graceperiod, $warn_when_late, $location, $enddate, $subscriptionid, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template ) = @_; @@ -1361,6 +1361,7 @@ sub ModSubscription { staffdisplaycount => $staffdisplaycount, opacdisplaycount => $opacdisplaycount, graceperiod => $graceperiod, + warn_when_late => $warn_when_late // 0, location => $location, enddate => $enddate, skip_serialseq => $skip_serialseq, @@ -1405,7 +1406,7 @@ sub NewSubscription { $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, - $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, + $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $warn_when_late, $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, ) = @_; @@ -1444,6 +1445,7 @@ sub NewSubscription { staffdisplaycount => $staffdisplaycount, opacdisplaycount => $opacdisplaycount, graceperiod => $graceperiod, + warn_when_late => $warn_when_late // 0, location => $location, enddate => $enddate, skip_serialseq => $skip_serialseq, diff --git a/Koha/Serial.pm b/Koha/Serial.pm index 052290ed46..5512825ffa 100644 --- a/Koha/Serial.pm +++ b/Koha/Serial.pm @@ -21,6 +21,7 @@ use Modern::Perl; use Koha::Database; +use Koha::Subscription; use base qw(Koha::Object); @@ -34,6 +35,20 @@ Koha::Serial - Koha Serial Object class =cut +=head3 subscription + +Returns the subscription this serial belongs to + + $subscription = $serial->subscription() + +=cut + +sub subscription { + my ($self) = @_; + + return Koha::Subscription->_new_from_dbic( $self->_result->subscriptionid ); +} + =head3 type =cut diff --git a/installer/data/mysql/atomicupdate/bug-29996.pl b/installer/data/mysql/atomicupdate/bug-29996.pl new file mode 100755 index 0000000000..9b1617d15d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-29996.pl @@ -0,0 +1,19 @@ +use Modern::Perl; + +return { + bug_number => '29996', + description => 'Add subscription.warn_when_late', + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + unless ( column_exists( 'subscription', 'warn_when_late' ) ) { + $dbh->do( + q{ + ALTER TABLE subscription + ADD COLUMN warn_when_late INT NOT NULL DEFAULT 0 COMMENT 'if enabled, late issues will be shown on main page' AFTER graceperiod + } + ); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3bf15c1007..892ce2cdda 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -6136,6 +6136,7 @@ CREATE TABLE `subscription` ( `staffdisplaycount` int(11) DEFAULT NULL COMMENT 'how many issues to show to the staff', `opacdisplaycount` int(11) DEFAULT NULL COMMENT 'how many issues to show to the public', `graceperiod` int(11) NOT NULL DEFAULT 0 COMMENT 'grace period in days', + `warn_when_late` INT NOT NULL DEFAULT 0 COMMENT 'if enabled, late issues will be shown on main page', `enddate` date DEFAULT NULL COMMENT 'subscription end date', `closed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'yes / no if the subscription is closed', `reneweddate` date DEFAULT NULL COMMENT 'date of last renewal for the subscription', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt index c32de6ab9b..fbbc2ccfd3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -180,7 +180,7 @@
[%# Following statement must be in one line for translatability %] - [% IF ( CAN_user_tools_moderate_comments && pendingcomments ) || ( CAN_user_tools_moderate_tags && pendingtags ) || ( CAN_user_borrowers_edit_borrowers && pending_borrower_modifications ) || ( CAN_user_suggestions_suggestions_manage && ( pendingsuggestions || all_pendingsuggestions )) || ( CAN_user_borrowers_edit_borrowers && pending_discharge_requests ) || pending_article_requests || ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes.count ) || ( ( Koha.Preference('OpacCatalogConcerns') || Koha.Preference('CatalogConcerns') ) && pending_biblio_tickets && CAN_user_editcatalogue_edit_catalogue ) || ( Koha.Preference('OPACReportProblem') && CAN_user_problem_reports && pending_problem_reports.count ) || already_ran_jobs || new_curbside_pickups.count || ( holds_with_cancellation_requests && CAN_user_circulate_circulate_remaining_permissions ) %] + [% IF ( CAN_user_tools_moderate_comments && pendingcomments ) || ( CAN_user_tools_moderate_tags && pendingtags ) || ( CAN_user_borrowers_edit_borrowers && pending_borrower_modifications ) || ( CAN_user_suggestions_suggestions_manage && ( pendingsuggestions || all_pendingsuggestions )) || ( CAN_user_borrowers_edit_borrowers && pending_discharge_requests ) || pending_article_requests || ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes.count ) || ( ( Koha.Preference('OpacCatalogConcerns') || Koha.Preference('CatalogConcerns') ) && pending_biblio_tickets && CAN_user_editcatalogue_edit_catalogue ) || ( Koha.Preference('OPACReportProblem') && CAN_user_problem_reports && pending_problem_reports.count ) || already_ran_jobs || new_curbside_pickups.count || ( holds_with_cancellation_requests && CAN_user_circulate_circulate_remaining_permissions ) || late_subscriptions %]
[% IF pending_article_requests %]
@@ -275,6 +275,23 @@ [% holds_with_cancellation_requests | html %]
[% END %] + + [% IF late_subscriptions %] +
+ The following serials are late: +
    + [% FOREACH s IN late_subscriptions %] +
  • + [% s.subscription.biblio.title | html %]: + [% FOREACH serial IN s.serials %] + [% serial.serialseq | html %] + [% "," UNLESS loop.last %] + [% END %] +
  • + [% END %] +
+
+ [% END %]
[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index 6f6c5a86b3..0052853d43 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 @@ -247,6 +247,15 @@ fieldset.rows table { clear: none; margin: 0; } day(s) +
  • + + [% IF warn_when_late %] + + [% ELSE %] + + [% END %] +
    Show an alert on main page when issues are late
    +
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index 5c70b04238..1e31e52bc8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -139,6 +139,14 @@ [% END %]
  • Grace period: [% graceperiod | html %]
  • +
  • + Warn when late: + [% IF warn_when_late %] + Yes + [% ELSE %] + No + [% END %] +
  • diff --git a/mainpage.pl b/mainpage.pl index d84408538e..0e4f5cfc6e 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -25,6 +25,7 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); use C4::Koha; use C4::Tags qw( get_count_by_tag_status ); +use C4::Serials; use Koha::AdditionalContents; use Koha::Patron::Modifications; use Koha::Patron::Discharge; @@ -33,6 +34,7 @@ use Koha::ArticleRequests; use Koha::BiblioFrameworks; use Koha::ProblemReports; use Koha::Quotes; +use Koha::Serials; use Koha::Suggestions; use Koha::BackgroundJobs; use Koha::CurbsidePickups; @@ -138,6 +140,32 @@ if ( C4::Context->preference('CurbsidePickup') ) { ); } +my @late_serials = Koha::Serials->search( + { + 'me.status' => C4::Serials::LATE, + 'subscriptionid.warn_when_late' => 1, + 'subscriptionid.branchcode' => C4::Context->userenv->{branch}, + }, + { + join => 'subscriptionid', + prefetch => { + subscriptionid => 'biblionumber', + }, + } +)->as_list; + +my %late_serials_grouped_by_subscription; +foreach my $serial (@late_serials) { + my $subscriptionid = $serial->subscriptionid; + $late_serials_grouped_by_subscription{$subscriptionid} //= { + subscription => $serial->subscription, + serials => [], + }; + push @{ $late_serials_grouped_by_subscription{$subscriptionid}->{serials} }, $serial; +} +my @late_subscriptions = sort { $a->{subscription}->subscriptionid <=> $b->{subscription}->subscriptionid } + values %late_serials_grouped_by_subscription; + $template->param( pendingcomments => $pendingcomments, pendingtags => $pendingtags, @@ -145,6 +173,7 @@ $template->param( pending_discharge_requests => $pending_discharge_requests, pending_article_requests => $pending_article_requests, pending_problem_reports => $pending_problem_reports, + late_subscriptions => \@late_subscriptions, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index 35ba10e05f..04a03605a3 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -298,6 +298,7 @@ sub redirect_add_subscription { my @irregularity = $query->multi_param('irregularity'); my $locale = $query->param('locale'); my $graceperiod = $query->param('graceperiod') || 0; + my $warn_when_late = $query->param('warn_when_late'); my $subtype = $query->param('subtype'); my $sublength = $query->param('sublength'); @@ -351,7 +352,7 @@ sub redirect_add_subscription { $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, join(";",@irregularity), $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, - $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, + $staffdisplaycount, $opacdisplaycount, $graceperiod, $warn_when_late, $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'))) ){ @@ -421,6 +422,7 @@ sub redirect_mod_subscription { my $staffdisplaycount = $query->param('staffdisplaycount'); my $opacdisplaycount = $query->param('opacdisplaycount'); my $graceperiod = $query->param('graceperiod') || 0; + my $warn_when_late = $query->param('warn_when_late'); my $location = $query->param('location'); my $itemtype = $query->param('itemtype'); my $previousitemtype = $query->param('previousitemtype'); @@ -461,7 +463,7 @@ sub redirect_mod_subscription { $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, - $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, + $opacdisplaycount, $graceperiod, $warn_when_late, $location, $enddate, $subscriptionid, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template ); -- 2.39.2