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>.
28 my ($template, $loggedinuser, $cookie) = get_template_and_user({
29 template_name => "acqui/csv/lateorders.tt",
32 flagsrequired => {acquisition => 'order_receive'},
34 my @ordernumbers = $input->multi_param('ordernumber');
36 my $csv_profile_id = $input->param('csv_profile');
38 unless ( $csv_profile_id ) {
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;
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
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*$|;
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({
84 loops => { aqorders => \@ordernumbers },
89 -attachment => 'lateorders.csv',
92 print Encode::encode_utf8($csv);