Bug 7162; Factorize code for order cancellation (QA fixes)
[koha.git] / acqui / cancelorder.pl
blobc45b8da4d66cd58a770a8956449824b35cfc5c51
1 #!/usr/bin/perl
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
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.
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.
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.
19 =head1 NAME
21 cancelorder.pl
23 =head1 DESCRIPTION
25 Ask confirmation for cancelling an order line
26 and add possibility to indicate a reason for cancellation
27 (saved in aqorders.notes)
29 =cut
31 use Modern::Perl;
33 use CGI;
34 use C4::Auth;
35 use C4::Output;
36 use C4::Acquisition;
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 } );
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;
54 if($action and $action eq "confirmcancel") {
55 my $reason = $input->param('reason');
56 my $error = DelOrder($biblionumber, $ordernumber, $del_biblio, $reason);
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);
64 $template->param(confirmcancel => 1);
67 $template->param(
68 ordernumber => $ordernumber,
69 biblionumber => $biblionumber,
70 referrer => $referrer,
71 del_biblio => $del_biblio,
74 output_html_with_http_headers $input, $cookie, $template->output;