Bug 24161: Keep tracks of late orders claims
[koha.git] / acqui / lateorders-export.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19 use CGI qw ( -utf8 );
20
21 use C4::Auth;
22 use C4::Acquisition;
23 use C4::Output;
24 use C4::Context;
25
26 my $input = new CGI;
27 my ($template, $loggedinuser, $cookie) = get_template_and_user({
28     template_name => "acqui/csv/lateorders.tt",
29     query => $input,
30     type => "intranet",
31     authnotrequired => 0,
32     flagsrequired => {acquisition => 'order_receive'},
33 });
34 my @ordernumbers = $input->multi_param('ordernumber');
35
36 my @orders;
37 for my $ordernumber ( @ordernumbers ) {
38     my $order = GetOrder $ordernumber;
39     my $order_object = Koha::Acquisition::Orders->find($ordernumber);
40     my $claims = $order_object->claims;
41     push @orders, {
42             orderdate => $order->{orderdate},
43             latesince => $order->{latesince},
44             estimateddeliverydate => $order->{estimateddeliverydate},
45             supplier => $order->{supplier},
46             supplierid => $order->{supplierid},
47             title => $order->{title},
48             author => $order->{author},
49             publisher => $order->{publisher},
50             unitpricesupplier => $order->{unitpricesupplier},
51             quantity_to_receive => $order->{quantity_to_receive},
52             subtotal => $order->{subtotal},
53             budget => $order->{budget},
54             basketname => $order->{basketname},
55             basketno => $order->{basketno},
56             claims_count => $claims->count,
57             claimed_date => $claims->count ? $claims->last->claimed_on : undef,
58             internalnote => $order->{order_internalnote},
59             vendornote   => $order->{order_vendornote},
60             isbn => $order->{isbn},
61         }
62     ;
63 }
64
65 print $input->header(
66     -type       => 'text/csv',
67     -attachment => 'lateorders.csv',
68 );
69 $template->param( orders => \@orders );
70 for my $line ( split '\n', $template->output ) {
71     print "$line\n" unless $line =~ m|^\s*$|;
72 }