Browse Source

Bug 23678: Include file for batch_hold_cancel

Use additional_report to retrieve patron and biblio's info.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.11.x
Jonathan Druart 3 years ago
parent
commit
de798994b2
  1. 31
      Koha/BackgroundJob/BatchCancelHold.pm
  2. 47
      koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_hold_cancel.inc

31
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;

47
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 %]
<div class="dialog message">
All holds have successfully been cancelled!
</div>
[% ELSE %]
<div class="dialog message">
[% 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 %]
</div>
[% END %]
[% END %]
[% END %]
[% BLOCK detail %]
[% FOR m IN report_messages %]
<div class="dialog message">
[% IF m.type == 'success' %]
<i class="fa fa-check success"></i>
[% ELSIF m.type == 'warning' %]
<i class="fa fa-warning warn"></i>
[% ELSIF m.type == 'error' %]
<i class="fa fa-exclamation error"></i>
[% END %]
[% SWITCH m.code %]
[% CASE 'hold_not_cancelled' %]
[% IF m.biblio && m.patron %]
Hold on <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% m.biblio.biblionumber | uri %]">[% m.biblio.title | html %]</a> for <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% m.patron.borrowernumber | uri %]">[% INCLUDE 'patron-title.inc' patron=m.patron %]</a> 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 <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% m.biblio_id | uri %]">[% m.biblio.title | html %]</a> for <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% m.patron_id | uri %]">[% INCLUDE 'patron-title.inc' patron=m.patron %]</a> has successfully been cancelled.
[% END %]
</div>
[% END %]
[% END %]
[% BLOCK js %]
[% END %]
Loading…
Cancel
Save