From de798994b2e386b2d197063e03deeace4d111a24 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 1 Oct 2021 11:42:10 +0200 Subject: [PATCH] Bug 23678: Include file for batch_hold_cancel Use additional_report to retrieve patron and biblio's info. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- Koha/BackgroundJob/BatchCancelHold.pm | 31 ++++++++---- .../background_jobs/batch_hold_cancel.inc | 47 +++++++++++++++++++ 2 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_hold_cancel.inc diff --git a/Koha/BackgroundJob/BatchCancelHold.pm b/Koha/BackgroundJob/BatchCancelHold.pm index fb009483f6..cc9ec6ad3c 100644 --- a/Koha/BackgroundJob/BatchCancelHold.pm +++ b/Koha/BackgroundJob/BatchCancelHold.pm @@ -21,6 +21,8 @@ use JSON qw( encode_json decode_json ); use Koha::BackgroundJobs; use Koha::DateUtils qw( dt_from_string ); use Koha::Holds; +use Koha::Patrons; +use Koha::Holds; use base 'Koha::BackgroundJob'; @@ -89,16 +91,11 @@ sub process { type => 'error', code => 'hold_not_cancelled', patron_id => defined $patron ? $patron->borrowernumber : '', - patron_name => defined $patron - ? ( $patron->firstname ? $patron->firstname . ', ' : '' ) - . $patron->surname - : '', biblio_id => defined $biblio ? $biblio->biblionumber : '', - biblio_title => defined $biblio ? $biblio->title : '', hold_id => $hold_id, error => defined $hold ? ( $@ ? $@ : 0 ) - : 'No hold with id ' . $hold_id . ' found', + : 'hold_not_found', }; } else { @@ -107,11 +104,7 @@ sub process { type => 'success', code => 'hold_cancelled', patron_id => $patron->borrowernumber, - patron_name => - ( $patron->firstname ? $patron->firstname . ', ' : '' ) - . $patron->surname, biblio_id => $biblio->biblionumber, - biblio_title => $biblio->title, hold_id => $hold_id, }; $report->{total_success}++; @@ -151,4 +144,22 @@ sub enqueue { ); } +=head3 additional_report + +Pass the biblio's title and patron's name + +=cut + +sub additional_report { + my ( $self, $args ) = @_; + + my $job = Koha::BackgroundJobs->find( $args->{job_id} ); + my $messages = $job->messages; + for my $m ( @$messages ) { + $m->{patron} = Koha::Patrons->find($m->{patron_id}); + $m->{biblio} = Koha::Biblios->find($m->{biblio_id}); + } + return { report_messages => $messages }; +} + 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_hold_cancel.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_hold_cancel.inc new file mode 100644 index 0000000000..655ca32c15 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_hold_cancel.inc @@ -0,0 +1,47 @@ +[% BLOCK report %] + [% SET report = job.report %] + [% IF report %] + [% IF report.total_holds == report.total_success %] +
+ All holds have successfully been cancelled! +
+ [% ELSE %] +
+ [% report.total_success | html %] / [% report.total_holds | html %] holds have successfully been modified. Some errors occurred. + [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] +
+ [% END %] + [% END %] + +[% END %] + +[% BLOCK detail %] + [% FOR m IN report_messages %] +
+ [% IF m.type == 'success' %] + + [% ELSIF m.type == 'warning' %] + + [% ELSIF m.type == 'error' %] + + [% END %] + [% SWITCH m.code %] + [% CASE 'hold_not_cancelled' %] + [% IF m.biblio && m.patron %] + Hold on [% m.biblio.title | html %] for [% INCLUDE 'patron-title.inc' patron=m.patron %] has not been cancelled. + [% END %] + An error occurred on cancelling. + [% SWITCH m.error %] + [% CASE 'hold_not_found' %] + No hold with id [% m.hold_id | html %] found. + [% CASE %]Unknown error '[% m.error | html %]'. + [% END %] + [% CASE 'hold_cancelled' %] + Hold on [% m.biblio.title | html %] for [% INCLUDE 'patron-title.inc' patron=m.patron %] has successfully been cancelled. + [% END %] +
+ [% END %] +[% END %] + +[% BLOCK js %] +[% END %] -- 2.39.5