Bug 7162; Factorize code for order cancellation (QA fixes)
[koha.git] / acqui / cancelorder.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 =head1 NAME
20
21 cancelorder.pl
22
23 =head1 DESCRIPTION
24
25 Ask confirmation for cancelling an order line
26 and add possibility to indicate a reason for cancellation
27 (saved in aqorders.notes)
28
29 =cut
30
31 use Modern::Perl;
32
33 use CGI;
34 use C4::Auth;
35 use C4::Output;
36 use C4::Acquisition;
37
38 my $input = new CGI;
39 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
40     template_name   => 'acqui/cancelorder.tt',
41     query           => $input,
42     type            => 'intranet',
43     authnotrequired => 0,
44     flagsrequired   => { 'acquisition' => 'order_manage' },
45     debug           => 1,
46 } );
47
48 my $action = $input->param('action');
49 my $ordernumber = $input->param('ordernumber');
50 my $biblionumber = $input->param('biblionumber');
51 my $referrer = $input->param('referrer') || $input->referer;
52 my $del_biblio = $input->param('del_biblio') ? 1 : 0;
53
54 if($action and $action eq "confirmcancel") {
55     my $reason = $input->param('reason');
56     my $error = DelOrder($biblionumber, $ordernumber, $del_biblio, $reason);
57
58     if($error) {
59         $template->param(error_delitem => 1) if $error->{'delitem'};
60         $template->param(error_delbiblio => 1) if $error->{'delbiblio'};
61     } else {
62         $template->param(success_cancelorder => 1);
63     }
64     $template->param(confirmcancel => 1);
65 }
66
67 $template->param(
68     ordernumber => $ordernumber,
69     biblionumber => $biblionumber,
70     referrer => $referrer,
71     del_biblio => $del_biblio,
72 );
73
74 output_html_with_http_headers $input, $cookie, $template->output;