Bug 32779: Add tests
[koha.git] / acqui / moddeliverydate.pl
1 #!/usr/bin/perl
2
3 # Copyright 2021 Aleisha Amohia <aleisha@catalyst.net.nz>
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 moddeliverydate.pl
23
24 =head1 DESCRIPTION
25
26 Modify just the estimated delivery date of an individual order when
27 its basket is closed.
28
29 =cut
30
31 use Modern::Perl;
32
33 use CGI qw ( -utf8 );
34 use C4::Auth qw( get_template_and_user );
35 use C4::Output qw( output_html_with_http_headers );
36 use C4::Acquisition qw( GetOrder GetBasket ModOrder );
37
38 use Koha::Acquisition::Booksellers;
39 use Koha::DateUtils qw( dt_from_string );
40
41 my $input = CGI->new;
42 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
43     template_name   => 'acqui/moddeliverydate.tt',
44     query           => $input,
45     type            => 'intranet',
46     flagsrequired   => { 'acquisition' => 'order_manage' },
47 } );
48
49 my $op = $input->param('op');
50 my $ordernumber = $input->param('ordernumber');
51 my $referrer = $input->param('referrer') || $input->referer();
52 my $order = GetOrder($ordernumber);
53 my $basket = GetBasket($order->{basketno});
54 my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
55
56 if($op and $op eq 'save') {
57     my $estimated_delivery_date = $input->param('estimated_delivery_date');
58     $order->{'estimated_delivery_date'} = $estimated_delivery_date ? dt_from_string( $estimated_delivery_date ) : undef;
59     ModOrder($order);
60     print $input->redirect($referrer);
61     exit;
62 } else {
63     $template->param(
64         estimated_delivery_date => $order->{'estimated_delivery_date'}
65     );
66 }
67
68 if($op) {
69     $template->param($op => 1);
70 }
71
72 $template->param(
73     basketname           => $basket->{'basketname'},
74     basketno             => $order->{basketno},
75     booksellerid         => $bookseller->id,
76     booksellername       => $bookseller->name,
77     ordernumber => $ordernumber,
78     referrer => $referrer,
79 );
80
81
82 output_html_with_http_headers $input, $cookie, $template->output;