From 2631be384592c68d3c5e939f4e5c9297e17c8138 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 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. The automatically generated serial issue should have the status "Expected". Change it to "Late". 4. Go back to the main page. You should see an alert with a link to your subscription 5. Change your library using the menu in the upper right corner of the screen. Now the alert should not appear. 6. Set your library back to its original value to make the alert reappear. 7. Edit your subscription and disable "Warn when late". Verify that the alert does not appear. --- C4/Serials.pm | 6 ++-- Koha/Serial.pm | 7 ++++ .../data/mysql/atomicupdate/bug-29996.pl | 17 ++++++++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/intranet-main.tt | 18 ++++++++++- .../en/modules/serials/subscription-add.tt | 9 ++++++ mainpage.pl | 32 ++++++++++++++++++- serials/subscription-add.pl | 6 ++-- 8 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-29996.pl diff --git a/C4/Serials.pm b/C4/Serials.pm index 75c9d7f19f..8f3c9b82f2 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1285,7 +1285,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 ) = @_; @@ -1323,6 +1323,7 @@ sub ModSubscription { staffdisplaycount => $staffdisplaycount, opacdisplaycount => $opacdisplaycount, graceperiod => $graceperiod, + warn_when_late => $warn_when_late, location => $location, enddate => $enddate, skip_serialseq => $skip_serialseq, @@ -1366,7 +1367,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 ) = @_; my $dbh = C4::Context->dbh; @@ -1404,6 +1405,7 @@ sub NewSubscription { staffdisplaycount => $staffdisplaycount, opacdisplaycount => $opacdisplaycount, graceperiod => $graceperiod, + warn_when_late => $warn_when_late, location => $location, enddate => $enddate, skip_serialseq => $skip_serialseq, diff --git a/Koha/Serial.pm b/Koha/Serial.pm index 052290ed46..36c56d7b27 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,12 @@ Koha::Serial - Koha Serial Object class =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 100644 index 0000000000..4132bc76c5 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-29996.pl @@ -0,0 +1,17 @@ +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 54ed708304..7dde46b642 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -5342,6 +5342,7 @@ CREATE TABLE `subscription` ( `staffdisplaycount` INT(11) NULL DEFAULT NULL COMMENT 'how many issues to show to the staff', `opacdisplaycount` INT(11) NULL 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 028ae1f2b8..5a26feb9a0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -177,7 +177,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('OPACReportProblem') && CAN_user_problem_reports && pending_problem_reports.count ) || already_ran_jobs || new_curbside_pickups.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('OPACReportProblem') && CAN_user_problem_reports && pending_problem_reports.count ) || already_ran_jobs || new_curbside_pickups.count || late_subscriptions %]
[% IF pending_article_requests %]
@@ -259,6 +259,22 @@
[% 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 45354977f7..ad0972470b 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 @@ -255,6 +255,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/mainpage.pl b/mainpage.pl index f5872e65bb..a66b12bcc0 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; @@ -32,6 +33,7 @@ use Koha::Reviews; use Koha::ArticleRequests; use Koha::ProblemReports; use Koha::Quotes; +use Koha::Serials; use Koha::Suggestions; use Koha::BackgroundJobs; use Koha::CurbsidePickups; @@ -119,13 +121,41 @@ 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, pending_borrower_modifications => $pending_borrower_modifications, pending_discharge_requests => $pending_discharge_requests, pending_article_requests => $pending_article_requests, - pending_problem_reports => $pending_problem_reports + 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 c08142b897..4c617d8029 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -303,6 +303,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'); @@ -355,7 +356,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 ); if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){ @@ -440,6 +441,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'); @@ -479,7 +481,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 ); -- 2.30.2