From 9be876c27b726ad9613c36566e4bfc818afbe882 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 Signed-off-by: Owen Leonard Signed-off-by: David Nind --- C4/Serials.pm | 10 ++++--- 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 | 22 +++++++------- 9 files changed, 117 insertions(+), 15 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug-29996.pl diff --git a/C4/Serials.pm b/C4/Serials.pm index 18f7318e50..c8edbfaee0 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1346,8 +1346,8 @@ sub ModSubscription { $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, - $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template + $graceperiod, $warn_when_late, $location, $enddate, $subscriptionid, $skip_serialseq, + $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template ) = @_; my $subscription = Koha::Subscriptions->find($subscriptionid); @@ -1384,6 +1384,7 @@ sub ModSubscription { staffdisplaycount => $staffdisplaycount, opacdisplaycount => $opacdisplaycount, graceperiod => $graceperiod, + warn_when_late => $warn_when_late // 0, location => $location, enddate => $enddate, skip_serialseq => $skip_serialseq, @@ -1429,8 +1430,8 @@ sub NewSubscription { $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, - $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, + $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $warn_when_late, + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, ) = @_; my $dbh = C4::Context->dbh; @@ -1468,6 +1469,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 4ed0c4507a..76c3987ee3 100644 --- a/Koha/Serial.pm +++ b/Koha/Serial.pm @@ -20,6 +20,7 @@ package Koha::Serial; use Modern::Perl; use Koha::Database; +use Koha::Subscription; use base qw(Koha::Object); @@ -33,6 +34,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 5d7139383c..8d44238539 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -6179,6 +6179,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 91172dac2a..c045d943b2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -182,7 +182,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 ) || self_registered_count %] + [% 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 ) || self_registered_count || late_subscriptions %]
[% IF pending_article_requests %]
@@ -294,6 +294,23 @@ [% END %]
[% 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 1e62a1108e..7d1db72f8b 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 @@ -262,6 +262,15 @@ 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 6d25533f1a..8484dc2a7a 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 @@ -138,6 +138,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 87f784631f..9cb91ef540 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; @@ -153,6 +155,32 @@ if ( C4::Context->preference('PatronSelfRegistrationAlert') ) { ); } +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, @@ -160,6 +188,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 8dff969978..d93bdbfc39 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -322,6 +322,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'); @@ -369,14 +370,14 @@ sub redirect_add_subscription { } } my $subscriptionid = NewSubscription( - $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, - $startdate, $periodicity, $numberlength, $weeklength, - $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, - $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, - join( ";", @irregularity ), $numberpattern, $locale, $callnumber, - $manualhistory, $internalnotes, $serialsadditems, - $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, - $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template + $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, + $startdate, $periodicity, $numberlength, $weeklength, + $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, + $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, + join( ";", @irregularity ), $numberpattern, $locale, $callnumber, + $manualhistory, $internalnotes, $serialsadditems, + $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') ) ) ) @@ -452,6 +453,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'); @@ -493,8 +495,8 @@ sub redirect_mod_subscription { $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, - $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, - $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template + $opacdisplaycount, $graceperiod, $warn_when_late, $location, $enddate, $subscriptionid, + $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template ); my @additional_fields = -- 2.39.5