Bug 12533: (follow-up) Add CSS to preview display of authority MARC
[koha.git] / acqui / lateorders-export.pl
blob57a080dbd31468d5c2dbe585267732307b4e3270
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 = CGI->new;
28 my ($template, $loggedinuser, $cookie) = get_template_and_user({
29 template_name => "acqui/csv/lateorders.tt",
30 query => $input,
31 type => "intranet",
32 flagsrequired => {acquisition => 'order_receive'},
33 });
34 my @ordernumbers = $input->multi_param('ordernumber');
36 my $csv_profile_id = $input->param('csv_profile');
38 unless ( $csv_profile_id ) {
39 my @orders;
40 for my $ordernumber ( @ordernumbers ) {
41 my $order = GetOrder $ordernumber;
42 my $order_object = Koha::Acquisition::Orders->find($ordernumber);
43 my $claims = $order_object->claims;
44 push @orders, {
45 orderdate => $order->{orderdate},
46 latesince => $order->{latesince},
47 estimateddeliverydate => $order->{estimateddeliverydate},
48 supplier => $order->{supplier},
49 supplierid => $order->{supplierid},
50 title => $order->{title},
51 author => $order->{author},
52 publisher => $order->{publisher},
53 unitpricesupplier => $order->{unitpricesupplier},
54 quantity_to_receive => $order->{quantity_to_receive},
55 subtotal => $order->{subtotal},
56 budget => $order->{budget},
57 basketname => $order->{basketname},
58 basketno => $order->{basketno},
59 claims_count => $claims->count,
60 claimed_date => $claims->count ? $claims->last->claimed_on : undef,
61 internalnote => $order->{order_internalnote},
62 vendornote => $order->{order_vendornote},
63 isbn => $order->{isbn},
68 # We want to export using the default profile, using the template acqui/csv/lateorders.tt
69 print $input->header(
70 -type => 'text/csv',
71 -attachment => 'lateorders.csv',
73 $template->param( orders => \@orders );
74 for my $line ( split '\n', $template->output ) {
75 print "$line\n" unless $line =~ m|^\s*$|;
77 exit;
78 } else {
79 my $csv_profile = Koha::CsvProfiles->find($csv_profile_id);
80 my $content = '[% SET separator = "'.$csv_profile->csv_separator.'" ~%]' . $csv_profile->content;
82 my $csv = C4::Letters::_process_tt({
83 content => $content,
84 loops => { aqorders => \@ordernumbers },
85 });
87 print $input->header(
88 -type => 'text/csv',
89 -attachment => 'lateorders.csv',
90 -charset => 'UTF-8',
92 print Encode::encode_utf8($csv);
93 exit;