--- a/acqui/lateorders-export.pl +++ a/acqui/lateorders-export.pl @@ -33,40 +33,61 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({ }); my @ordernumbers = $input->multi_param('ordernumber'); -my @orders; -for my $ordernumber ( @ordernumbers ) { - my $order = GetOrder $ordernumber; - my $order_object = Koha::Acquisition::Orders->find($ordernumber); - my $claims = $order_object->claims; - push @orders, { - orderdate => $order->{orderdate}, - latesince => $order->{latesince}, - estimateddeliverydate => $order->{estimateddeliverydate}, - supplier => $order->{supplier}, - supplierid => $order->{supplierid}, - title => $order->{title}, - author => $order->{author}, - publisher => $order->{publisher}, - unitpricesupplier => $order->{unitpricesupplier}, - quantity_to_receive => $order->{quantity_to_receive}, - subtotal => $order->{subtotal}, - budget => $order->{budget}, - basketname => $order->{basketname}, - basketno => $order->{basketno}, - claims_count => $claims->count, - claimed_date => $claims->count ? $claims->last->claimed_on : undef, - internalnote => $order->{order_internalnote}, - vendornote => $order->{order_vendornote}, - isbn => $order->{isbn}, - } - ; -} +my $csv_profile_id = $input->param('csv_profile'); + +unless ( $csv_profile_id ) { + my @orders; + for my $ordernumber ( @ordernumbers ) { + my $order = GetOrder $ordernumber; + my $order_object = Koha::Acquisition::Orders->find($ordernumber); + my $claims = $order_object->claims; + push @orders, { + orderdate => $order->{orderdate}, + latesince => $order->{latesince}, + estimateddeliverydate => $order->{estimateddeliverydate}, + supplier => $order->{supplier}, + supplierid => $order->{supplierid}, + title => $order->{title}, + author => $order->{author}, + publisher => $order->{publisher}, + unitpricesupplier => $order->{unitpricesupplier}, + quantity_to_receive => $order->{quantity_to_receive}, + subtotal => $order->{subtotal}, + budget => $order->{budget}, + basketname => $order->{basketname}, + basketno => $order->{basketno}, + claims_count => $claims->count, + claimed_date => $claims->count ? $claims->last->claimed_on : undef, + internalnote => $order->{order_internalnote}, + vendornote => $order->{order_vendornote}, + isbn => $order->{isbn}, + } + ; + } + + # We want to export using the default profile, using the template acqui/csv/lateorders.tt + print $input->header( + -type => 'text/csv', + -attachment => 'lateorders.csv', + ); + $template->param( orders => \@orders ); + for my $line ( split '\n', $template->output ) { + print "$line\n" unless $line =~ m|^\s*$|; + } + exit; +} else { + my $csv_profile = Koha::CsvProfiles->find($csv_profile_id); + my $content = '[% SET separator = "'.$csv_profile->csv_separator.'" ~%]' . $csv_profile->content; + + my $csv = C4::Letters::_process_tt({ + content => $content, + loops => { aqorders => \@ordernumbers }, + }); -print $input->header( - -type => 'text/csv', - -attachment => 'lateorders.csv', -); -$template->param( orders => \@orders ); -for my $line ( split '\n', $template->output ) { - print "$line\n" unless $line =~ m|^\s*$|; + print $input->header( + -type => 'text/csv', + -attachment => 'lateorders.csv', + ); + print $csv; + exit; } --- a/acqui/lateorders.pl +++ a/acqui/lateorders.pl @@ -54,6 +54,7 @@ use C4::Acquisition; use C4::Letters; use Koha::DateUtils; use Koha::Acquisition::Orders; +use Koha::CsvProfiles; my $input = new CGI; my ($template, $loggedinuser, $cookie) = get_template_and_user( @@ -172,5 +173,6 @@ $template->param( estimateddeliverydatefrom => $estimateddeliverydatefrom, estimateddeliverydateto => $estimateddeliverydateto, intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + csv_profiles => [ Koha::CsvProfiles->search({ type => 'sql', used_for => 'late_orders' }) ], ); output_html_with_http_headers $input, $cookie, $template->output; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt @@ -181,9 +181,21 @@
- +
You have to define which fields you want to export, separated by pipes.
You can also use your own headers (instead of the ones from Koha) by prefixing the field name with an header, followed by the equal sign.
Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq
For late issues claims you can use data from following tables: serial, subscription, biblio, biblioitems and aqbookseller.
For basket exports you can use data from following tables: biblio, biblioitems, aqorders, aqbudgets and aqbasket.
+For late orders exports you must provide a Template Toolkit syntax that will generate the whole CSV file..