3 # Copyright 2014 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 Ask confirmation for cancelling an order line
27 and add possibility to indicate a reason for cancellation
28 (saved in aqorders.notes)
35 use C4::Auth qw( get_template_and_user );
36 use C4::Output qw( output_html_with_http_headers );
37 use C4::Log qw(logaction);
38 use Koha::Acquisition::Baskets;
41 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
42 template_name => 'acqui/cancelorder.tt',
45 flagsrequired => { 'acquisition' => 'order_manage' },
48 my $op = $input->param('op') || q{};
49 my $ordernumber = $input->param('ordernumber');
50 my $biblionumber = $input->param('biblionumber');
51 my $basketno = $input->param('basketno');
52 my $basket = Koha::Acquisition::Baskets->find({ basketno => $basketno }, { prefetch => 'booksellerid' });
53 my $referrer = $input->param('referrer') || $input->referer;
54 my $delete_biblio = $input->param('del_biblio') ? 1 : 0;
56 if( $op eq "cud-confirmcancel" ) {
57 my $reason = $input->param('reason');
58 my $order = Koha::Acquisition::Orders->find($ordernumber);
61 push @messages, Koha::Object::Message->new({ message => 'error_order_not_found', type => 'error' });
62 $template->param( error_order_not_found => 1 );
63 } elsif( $order->datecancellationprinted ) {
64 push @messages, Koha::Object::Message->new({ message => 'error_order_already_cancelled', type => 'error' });
65 $template->param( error_order_already_cancelled => 1 );
67 $order->cancel({ reason => $reason, delete_biblio => $delete_biblio });
68 @messages = @{ $order->object_messages };
71 if ( scalar @messages > 0 ) {
72 $template->param( error_delitem => 1 )
73 if $messages[0]->message eq 'error_delitem';
74 $template->param( error_delbiblio => 1 )
75 if $messages[0]->message eq 'error_delbiblio';
77 # Log the cancellation of the order
78 if (C4::Context->preference("AcquisitionLog")) {
79 logaction('ACQUISITIONS', 'CANCEL_ORDER', $ordernumber);
81 $template->param(success_cancelorder => 1);
83 $template->param(confirmcancel => 1);
87 ordernumber => $ordernumber,
88 biblionumber => $biblionumber,
90 referrer => $referrer,
91 del_biblio => $delete_biblio,
94 output_html_with_http_headers $input, $cookie, $template->output;