Lines 33-38
use Koha::Acquisition::Booksellers;
Link Here
|
33 |
use Koha::Biblios; |
33 |
use Koha::Biblios; |
34 |
use Koha::Number::Price; |
34 |
use Koha::Number::Price; |
35 |
use Koha::Libraries; |
35 |
use Koha::Libraries; |
|
|
36 |
use Koha::CsvProfiles; |
36 |
|
37 |
|
37 |
use C4::Koha; |
38 |
use C4::Koha; |
38 |
|
39 |
|
Lines 277-283
$cgi parameter is needed for column name translation
Link Here
|
277 |
=cut |
278 |
=cut |
278 |
|
279 |
|
279 |
sub GetBasketAsCSV { |
280 |
sub GetBasketAsCSV { |
280 |
my ($basketno, $cgi) = @_; |
281 |
my ($basketno, $cgi, $csv_profile_id) = @_; |
281 |
my $basket = GetBasket($basketno); |
282 |
my $basket = GetBasket($basketno); |
282 |
my @orders = GetOrders($basketno); |
283 |
my @orders = GetOrders($basketno); |
283 |
my $contract = GetContract({ |
284 |
my $contract = GetContract({ |
Lines 285-332
sub GetBasketAsCSV {
Link Here
|
285 |
}); |
286 |
}); |
286 |
|
287 |
|
287 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); |
288 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); |
288 |
|
|
|
289 |
my @rows; |
289 |
my @rows; |
290 |
foreach my $order (@orders) { |
290 |
if ($csv_profile_id) { |
291 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
291 |
my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id ); |
292 |
my $row = { |
292 |
die "There is no valid csv profile given" unless $csv_profile; |
293 |
contractname => $contract->{'contractname'}, |
293 |
|
294 |
ordernumber => $order->{'ordernumber'}, |
294 |
my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1}); |
295 |
entrydate => $order->{'entrydate'}, |
295 |
my $csv_profile_content = $csv_profile->content; |
296 |
isbn => $order->{'isbn'}, |
296 |
my ( @headers, @fields ); |
297 |
author => $bd->{'author'}, |
297 |
while ( $csv_profile_content =~ / |
298 |
title => $bd->{'title'}, |
298 |
([^=]+) # header |
299 |
publicationyear => $bd->{'publicationyear'}, |
299 |
= |
300 |
publishercode => $bd->{'publishercode'}, |
300 |
([^\|]+) # fieldname (table.row or row) |
301 |
collectiontitle => $bd->{'collectiontitle'}, |
301 |
\|? /gxms |
302 |
notes => $order->{'order_vendornote'}, |
302 |
) { |
303 |
quantity => $order->{'quantity'}, |
303 |
push @headers, $1; |
304 |
rrp => $order->{'rrp'}, |
304 |
my $field = $2; |
305 |
}; |
305 |
$field =~ s/[^\.]*\.?//; # Remove the table name if exists. |
306 |
for my $place ( qw( deliveryplace billingplace ) ) { |
306 |
push @fields, $field; |
307 |
if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) { |
307 |
} |
308 |
$row->{$place} = $library->branchname |
308 |
for my $order (@orders) { |
|
|
309 |
my @row; |
310 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
311 |
my @biblioitems = GetBiblioItemByBiblioNumber( $order->{'biblionumber'}); |
312 |
for my $biblioitem (@biblioitems) { |
313 |
if ($biblioitem->{isbn} eq $order->{isbn}) { |
314 |
$order = {%$order, %$biblioitem}; |
315 |
} |
316 |
} |
317 |
if ($contract) { |
318 |
$order = {%$order, %$contract}; |
319 |
} |
320 |
$order = {%$order, %$basket, %$bd}; |
321 |
for my $field (@fields) { |
322 |
push @row, $order->{$field}; |
309 |
} |
323 |
} |
|
|
324 |
push @rows, \@row; |
310 |
} |
325 |
} |
311 |
foreach(qw( |
326 |
my $content = join( $csv_profile->csv_separator, @headers ) . "\n"; |
312 |
contractname author title publishercode collectiontitle notes |
327 |
for my $row ( @rows ) { |
313 |
deliveryplace billingplace |
328 |
$csv->combine(@$row); |
314 |
) ) { |
329 |
my $string = $csv->string; |
315 |
# Double the quotes to not be interpreted as a field end |
330 |
$content .= $string . "\n"; |
316 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
|
|
317 |
} |
331 |
} |
318 |
push @rows, $row; |
332 |
return $content; |
319 |
} |
333 |
} |
|
|
334 |
else { |
335 |
foreach my $order (@orders) { |
336 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
337 |
my $row = { |
338 |
contractname => $contract->{'contractname'}, |
339 |
ordernumber => $order->{'ordernumber'}, |
340 |
entrydate => $order->{'entrydate'}, |
341 |
isbn => $order->{'isbn'}, |
342 |
author => $bd->{'author'}, |
343 |
title => $bd->{'title'}, |
344 |
publicationyear => $bd->{'publicationyear'}, |
345 |
publishercode => $bd->{'publishercode'}, |
346 |
collectiontitle => $bd->{'collectiontitle'}, |
347 |
notes => $order->{'order_vendornote'}, |
348 |
quantity => $order->{'quantity'}, |
349 |
rrp => $order->{'rrp'}, |
350 |
}; |
351 |
for my $place ( qw( deliveryplace billingplace ) ) { |
352 |
if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) { |
353 |
$row->{$place} = $library->branchname |
354 |
} |
355 |
} |
356 |
foreach(qw( |
357 |
contractname author title publishercode collectiontitle notes |
358 |
deliveryplace billingplace |
359 |
) ) { |
360 |
# Double the quotes to not be interpreted as a field end |
361 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
362 |
} |
363 |
push @rows, $row; |
364 |
} |
320 |
|
365 |
|
321 |
@rows = sort { |
366 |
@rows = sort { |
322 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
367 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
323 |
$a->{publishercode} cmp $b->{publishercode}; |
368 |
$a->{publishercode} cmp $b->{publishercode}; |
324 |
} |
369 |
} |
325 |
} @rows; |
370 |
} @rows; |
326 |
|
371 |
|
327 |
$template->param(rows => \@rows); |
372 |
$template->param(rows => \@rows); |
328 |
|
373 |
|
329 |
return $template->output; |
374 |
return $template->output; |
|
|
375 |
} |
330 |
} |
376 |
} |
331 |
|
377 |
|
332 |
|
378 |
|