Bug 24405: Compiled CSS
[koha.git] / acqui / lateorders-export.pl
blob397535428c1b16f8dbcf70a5c6965679a1591674
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
19 use CGI qw ( -utf8 );
20 use Encode;
22 use C4::Auth;
23 use C4::Acquisition;
24 use C4::Output;
25 use C4::Context;
27 my $input = new CGI;
28 my ($template, $loggedinuser, $cookie) = get_template_and_user({
29 template_name => "acqui/csv/lateorders.tt",
30 query => $input,
31 type => "intranet",
32 authnotrequired => 0,
33 flagsrequired => {acquisition => 'order_receive'},
34 });
35 my @ordernumbers = $input->multi_param('ordernumber');
37 my $csv_profile_id = $input->param('csv_profile');
39 unless ( $csv_profile_id ) {
40 my @orders;
41 for my $ordernumber ( @ordernumbers ) {
42 my $order = GetOrder $ordernumber;
43 my $order_object = Koha::Acquisition::Orders->find($ordernumber);
44 my $claims = $order_object->claims;
45 push @orders, {
46 orderdate => $order->{orderdate},
47 latesince => $order->{latesince},
48 estimateddeliverydate => $order->{estimateddeliverydate},
49 supplier => $order->{supplier},
50 supplierid => $order->{supplierid},
51 title => $order->{title},
52 author => $order->{author},
53 publisher => $order->{publisher},
54 unitpricesupplier => $order->{unitpricesupplier},
55 quantity_to_receive => $order->{quantity_to_receive},
56 subtotal => $order->{subtotal},
57 budget => $order->{budget},
58 basketname => $order->{basketname},
59 basketno => $order->{basketno},
60 claims_count => $claims->count,
61 claimed_date => $claims->count ? $claims->last->claimed_on : undef,
62 internalnote => $order->{order_internalnote},
63 vendornote => $order->{order_vendornote},
64 isbn => $order->{isbn},
69 # We want to export using the default profile, using the template acqui/csv/lateorders.tt
70 print $input->header(
71 -type => 'text/csv',
72 -attachment => 'lateorders.csv',
74 $template->param( orders => \@orders );
75 for my $line ( split '\n', $template->output ) {
76 print "$line\n" unless $line =~ m|^\s*$|;
78 exit;
79 } else {
80 my $csv_profile = Koha::CsvProfiles->find($csv_profile_id);
81 my $content = '[% SET separator = "'.$csv_profile->csv_separator.'" ~%]' . $csv_profile->content;
83 my $csv = C4::Letters::_process_tt({
84 content => $content,
85 loops => { aqorders => \@ordernumbers },
86 });
88 print $input->header(
89 -type => 'text/csv',
90 -attachment => 'lateorders.csv',
91 -charset => 'UTF-8',
93 print Encode::encode_utf8($csv);
94 exit;