From dfdad40f8d938fb68988c3affa2317d7f9383bf1 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 4 Feb 2020 03:30:30 +0000 Subject: [PATCH] Bug 20453: Send notice when cancelling a hold from intranet To test: 1) Apply patch 2) Place a reserve for Borrower A 3) Cancel the reserve from reserve/request.pl 4) Go to Borrower A's account page and look at Notices tab 5) Confirm the HOLD_MANUAL_CANCEL notice is pending 6) Place a reserve for Borrower A again 7) Go to Circulation -> Holds to pull 8) Cancel the hold 9) Repeat steps 4 and 5 10) Place a reserve for Borrower A again 11) Go to Borrower A's account page and look at the Holds table (under Check out tab or Details tab) 12) Cancel hold using 'Cancel marked holds' button 13) Repeat steps 4 and 5 Sponsored-by: Waikato Institute of Technology --- C4/Reserves.pm | 38 +++++++++++++++++++++++++++++++++++--- circ/pendingreserves.pl | 32 +++++++++++++++++++++++++++++++- reserve/request.pl | 16 ++++++++++++++++ 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index eb0a4f8925..45607dc8a6 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1004,9 +1004,24 @@ sub ModReserve { $hold ||= Koha::Holds->find($reserve_id); if ( $rank eq "del" ) { + my $hold_branchcode = $hold->branchcode; + my $hold_biblionumber = $hold->biblionumber; + my $hold_borrowernumber = $hold->borrowernumber; + my $hold_borrower = Koha::Patrons->find( $hold_borrowernumber ); $hold->cancel; - } - elsif ($rank =~ /^\d+/ and $rank > 0) { + + # send notice to user that their hold has been cancelled + my $letter = C4::Letters::GetPreparedLetter ( + module => 'reserves', + letter_code => 'HOLD_MANUAL_CANCEL', + branchcode => $hold_branchcode, + tables => { + 'biblio', $hold_biblionumber, + 'borrowers', $hold_borrowernumber + } + ); + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + } elsif ($rank =~ /^\d+/ and $rank > 0) { logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) if C4::Context->preference('HoldsLog'); @@ -1188,7 +1203,24 @@ sub ModReserveCancelAll { #step 1 : cancel the reservation my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber }); return unless $holds->count; - $holds->next->cancel; + my $hold = $holds->next; + my $hold_branchcode = $hold->branchcode; + my $hold_biblionumber = $hold->biblionumber; + my $hold_borrowernumber = $hold->borrowernumber; + my $hold_borrower = Koha::Patrons->find( $hold_borrowernumber ); + $hold->cancel; + + # send notice to user that their hold has been cancelled + my $letter = C4::Letters::GetPreparedLetter ( + module => 'reserves', + letter_code => 'HOLD_MANUAL_CANCEL', + branchcode => $hold_branchcode, + tables => { + 'biblio', $hold_biblionumber, + 'borrowers', $hold_borrowernumber + } + ); + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); #step 2 launch the subroutine of the others reserves ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 7f2062942a..40ea41ba14 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -56,15 +56,34 @@ my @messages; if ( $op eq 'cancel_reserve' and $reserve_id ) { my $hold = Koha::Holds->find( $reserve_id ); if ( $hold ) { + my $hold_branchcode = $hold->branchcode; + my $hold_biblionumber = $hold->biblionumber; + my $hold_borrowernumber = $hold->borrowernumber; + my $hold_borrower = Koha::Patrons->find( $hold_borrowernumber ); $hold->cancel; push @messages, { type => 'message', code => 'hold_cancelled' }; + + # send notice to user that their hold has been cancelled + my $letter = C4::Letters::GetPreparedLetter ( + module => 'reserves', + letter_code => 'HOLD_MANUAL_CANCEL', + branchcode => $hold_branchcode, + tables => { + 'biblio', $hold_biblionumber, + 'borrowers', $hold_borrowernumber + } + ); + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); } } elsif ( $op =~ m|^mark_as_lost| ) { my $hold = Koha::Holds->find( $reserve_id ); + my $hold_branchcode = $hold->branchcode; + my $hold_biblionumber = $hold->biblionumber; + my $hold_borrowernumber = $hold->borrowernumber; + my $patron = $hold->borrower; die "wrong reserve_id" unless $hold; # This is a bit rude, but we are not supposed to get a wrong reserve_id my $item = $hold->item; if ( $item and C4::Context->preference('CanMarkHoldsToPullAsLost') =~ m|^allow| ) { - my $patron = $hold->borrower; C4::Circulation::LostItem( $item->itemnumber, "pendingreserves" ); if ( $op eq 'mark_as_lost_and_notify' and C4::Context->preference('CanMarkHoldsToPullAsLost') eq 'allow_and_notify' ) { my $library = $hold->branch; @@ -123,6 +142,17 @@ if ( $op eq 'cancel_reserve' and $reserve_id ) { } } + # send notice to user that their hold has been cancelled + my $letter = C4::Letters::GetPreparedLetter ( + module => 'reserves', + letter_code => 'HOLD_MANUAL_CANCEL', + branchcode => $hold_branchcode, + tables => { + 'biblio', $hold_biblionumber, + 'borrowers', $hold_borrowernumber + } + ); + C4::Message->enqueue($letter, $patron->unblessed, 'email'); } elsif ( not $item ) { push @messages, { type => 'alert', code => 'hold_placed_at_biblio_level'}; } # else the url parameters have been modified and the user is not allowed to continue diff --git a/reserve/request.pl b/reserve/request.pl index 23bd88e2b9..1612d2405c 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -107,7 +107,23 @@ if ( $action eq 'move' ) { } elsif ( $action eq 'cancel' ) { my $reserve_id = $input->param('reserve_id'); my $hold = Koha::Holds->find( $reserve_id ); + my $hold_branchcode = $hold->branchcode; + my $hold_biblionumber = $hold->biblionumber; + my $hold_borrowernumber = $hold->borrowernumber; + my $hold_borrower = Koha::Patrons->find( $hold_borrowernumber ); $hold->cancel if $hold; + + # send notice to user that their hold has been cancelled + my $letter = C4::Letters::GetPreparedLetter ( + module => 'reserves', + letter_code => 'HOLD_MANUAL_CANCEL', + branchcode => $hold_branchcode, + tables => { + 'biblio', $hold_biblionumber, + 'borrowers', $hold_borrowernumber + } + ); + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); } elsif ( $action eq 'setLowestPriority' ) { my $reserve_id = $input->param('reserve_id'); ToggleLowestPriority( $reserve_id ); -- 2.11.0