Bug 29072: Move reference route /cities spec to YAML
[koha.git] / acqui / cancelorder.pl
1 #!/usr/bin/perl
2
3 # Copyright 2014 BibLibre
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 =head1 NAME
21
22 cancelorder.pl
23
24 =head1 DESCRIPTION
25
26 Ask confirmation for cancelling an order line
27 and add possibility to indicate a reason for cancellation
28 (saved in aqorders.notes)
29
30 =cut
31
32 use Modern::Perl;
33
34 use CGI;
35 use C4::Auth qw( get_template_and_user );
36 use C4::Output qw( output_html_with_http_headers );
37 use Koha::Acquisition::Baskets;
38
39 my $input = CGI->new;
40 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41     template_name   => 'acqui/cancelorder.tt',
42     query           => $input,
43     type            => 'intranet',
44     flagsrequired   => { 'acquisition' => 'order_manage' },
45 } );
46
47 my $action = $input->param('action');
48 my $ordernumber = $input->param('ordernumber');
49 my $biblionumber = $input->param('biblionumber');
50 my $basketno = $input->param('basketno');
51 my $basket = Koha::Acquisition::Baskets->find({ basketno => $basketno }, { prefetch => 'booksellerid' });
52 my $referrer = $input->param('referrer') || $input->referer;
53 my $delete_biblio = $input->param('del_biblio') ? 1 : 0;
54
55 if( $action and $action eq "confirmcancel" ) {
56     my $reason = $input->param('reason');
57     my $order  = Koha::Acquisition::Orders->find($ordernumber);
58     $order->cancel({ reason => $reason, delete_biblio => $delete_biblio });
59     my @messages = @{ $order->messages };
60
61     if ( scalar @messages > 0 ) {
62         $template->param( error_delitem => 1 )
63             if $messages[0]->message eq 'error_delitem';
64         $template->param( error_delbiblio => 1 )
65             if $messages[0]->message eq 'error_delbiblio';
66     } else {
67         $template->param(success_cancelorder => 1);
68     }
69     $template->param(confirmcancel => 1);
70 }
71
72 $template->param(
73     ordernumber => $ordernumber,
74     biblionumber => $biblionumber,
75     basket => $basket,
76     referrer => $referrer,
77     del_biblio => $delete_biblio,
78 );
79
80 output_html_with_http_headers $input, $cookie, $template->output;