Bug 15348: Add estimated delivery date field to individual orders
[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;
35 use C4::Output;
36 use C4::Acquisition;
37
38 use Koha::Acquisition::Booksellers;
39 use Koha::DateUtils;
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' => '*' },
47     debug           => 1,
48 } );
49
50 my $op = $input->param('op');
51 my $ordernumber = $input->param('ordernumber');
52 my $referrer = $input->param('referrer') || $input->referer();
53 my $order = GetOrder($ordernumber);
54 my $basket = GetBasket($order->{basketno});
55 my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
56
57 if($op and $op eq 'save') {
58     my $estimated_delivery_date = $input->param('estimated_delivery_date');
59     $order->{'estimated_delivery_date'} = dt_from_string( $estimated_delivery_date );
60     ModOrder($order);
61     print $input->redirect($referrer);
62     exit;
63 } else {
64     $template->param(
65         estimated_delivery_date => $order->{'estimated_delivery_date'}
66     );
67 }
68
69 if($op) {
70     $template->param($op => 1);
71 }
72
73 $template->param(
74     basketname           => $basket->{'basketname'},
75     basketno             => $order->{basketno},
76     booksellerid         => $bookseller->id,
77     booksellername       => $bookseller->name,
78     ordernumber => $ordernumber,
79     referrer => $referrer,
80 );
81
82
83 output_html_with_http_headers $input, $cookie, $template->output;