|
Lines 20-25
use Modern::Perl;
Link Here
|
| 20 |
use Mojo::Base 'Mojolicious::Controller'; |
20 |
use Mojo::Base 'Mojolicious::Controller'; |
| 21 |
|
21 |
|
| 22 |
use Koha::Bookings; |
22 |
use Koha::Bookings; |
|
|
23 |
use Koha::Items; |
| 24 |
use Koha::Patrons; |
| 25 |
use Koha::Libraries; |
| 26 |
|
| 27 |
use C4::Letters; |
| 23 |
|
28 |
|
| 24 |
use Try::Tiny qw( catch try ); |
29 |
use Try::Tiny qw( catch try ); |
| 25 |
|
30 |
|
|
Lines 134-145
sub delete {
Link Here
|
| 134 |
my $c = shift->openapi->valid_input or return; |
139 |
my $c = shift->openapi->valid_input or return; |
| 135 |
|
140 |
|
| 136 |
my $booking = Koha::Bookings->find( $c->param('booking_id') ); |
141 |
my $booking = Koha::Bookings->find( $c->param('booking_id') ); |
|
|
142 |
my $patron = Koha::Patrons->find( $booking->patron_id ); |
| 143 |
my $item = Koha::Items->find( $booking->item_id ); |
| 144 |
my $library = Koha::Libraries->find( $booking->pickup_library_id ); |
| 137 |
|
145 |
|
|
|
146 |
|
| 138 |
return $c->render_resource_not_found("Booking") |
147 |
return $c->render_resource_not_found("Booking") |
| 139 |
unless $booking; |
148 |
unless $booking; |
| 140 |
|
149 |
|
| 141 |
return try { |
150 |
return try { |
| 142 |
$booking->delete; |
151 |
$booking->delete; |
|
|
152 |
my $letter = C4::Letters::GetPreparedLetter( |
| 153 |
module => 'bookings', |
| 154 |
letter_code => 'BOOKING_CANCELLATION', |
| 155 |
message_transport_type => 'email', |
| 156 |
branchcode => $patron->branchcode, |
| 157 |
lang => $patron->lang, |
| 158 |
tables => { |
| 159 |
branches => $library->branchcode, |
| 160 |
borrowers => $patron->borrowernumber, |
| 161 |
items => $item->itemnumber, |
| 162 |
biblio => $item->biblionumber, |
| 163 |
biblioitems => $item->biblionumber, |
| 164 |
bookings => $booking->unblessed, |
| 165 |
} |
| 166 |
); |
| 167 |
|
| 168 |
if ($letter) { |
| 169 |
C4::Letters::EnqueueLetter( |
| 170 |
{ |
| 171 |
letter => $letter, |
| 172 |
borrowernumber => $patron->borrowernumber, |
| 173 |
message_transport_type => 'email', |
| 174 |
} |
| 175 |
); |
| 176 |
} |
| 177 |
|
| 143 |
return $c->render_resource_deleted; |
178 |
return $c->render_resource_deleted; |
| 144 |
} catch { |
179 |
} catch { |
| 145 |
$c->unhandled_exception($_); |
180 |
$c->unhandled_exception($_); |