|
Lines 301-307
$cgi parameter is needed for column name translation
Link Here
|
| 301 |
=cut |
301 |
=cut |
| 302 |
|
302 |
|
| 303 |
sub GetBasketAsCSV { |
303 |
sub GetBasketAsCSV { |
| 304 |
my ($basketno, $cgi) = @_; |
304 |
my ($basketno, $cgi, $csv_profile_id) = @_; |
| 305 |
my $basket = GetBasket($basketno); |
305 |
my $basket = GetBasket($basketno); |
| 306 |
my @orders = GetOrders($basketno); |
306 |
my @orders = GetOrders($basketno); |
| 307 |
my $contract = GetContract({ |
307 |
my $contract = GetContract({ |
|
Lines 309-353
sub GetBasketAsCSV {
Link Here
|
| 309 |
}); |
309 |
}); |
| 310 |
|
310 |
|
| 311 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); |
311 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); |
| 312 |
|
|
|
| 313 |
my @rows; |
312 |
my @rows; |
| 314 |
foreach my $order (@orders) { |
313 |
if ($csv_profile_id) { |
| 315 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
314 |
my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id ); |
| 316 |
my $row = { |
315 |
die "There is no valid csv profile given" unless $csv_profile; |
| 317 |
contractname => $contract->{'contractname'}, |
316 |
|
| 318 |
ordernumber => $order->{'ordernumber'}, |
317 |
my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1}); |
| 319 |
entrydate => $order->{'entrydate'}, |
318 |
my $csv_profile_content = $csv_profile->{content}; |
| 320 |
isbn => $order->{'isbn'}, |
319 |
my ( @headers, @fields ); |
| 321 |
author => $bd->{'author'}, |
320 |
while ( $csv_profile_content =~ / |
| 322 |
title => $bd->{'title'}, |
321 |
([^=]+) # header |
| 323 |
publicationyear => $bd->{'publicationyear'}, |
322 |
= |
| 324 |
publishercode => $bd->{'publishercode'}, |
323 |
([^\|]+) # fieldname (table.row or row) |
| 325 |
collectiontitle => $bd->{'collectiontitle'}, |
324 |
\|? /gxms |
| 326 |
notes => $order->{'order_vendornote'}, |
325 |
) { |
| 327 |
quantity => $order->{'quantity'}, |
326 |
push @headers, $1; |
| 328 |
rrp => $order->{'rrp'}, |
327 |
my $field = $2; |
| 329 |
deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ), |
328 |
$field =~ s/[^\.]*\.?//; # Remove the table name if exists. |
| 330 |
billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ), |
329 |
push @fields, $field; |
| 331 |
}; |
330 |
} |
| 332 |
foreach(qw( |
331 |
for my $order (@orders) { |
| 333 |
contractname author title publishercode collectiontitle notes |
332 |
my @row; |
| 334 |
deliveryplace billingplace |
333 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
| 335 |
) ) { |
334 |
my @biblioitems = GetBiblioItemByBiblioNumber( $order->{'biblionumber'}); |
| 336 |
# Double the quotes to not be interpreted as a field end |
335 |
for my $biblioitem (@biblioitems) { |
| 337 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
336 |
if ($biblioitem->{isbn} eq $order->{isbn}) { |
|
|
337 |
$order = {%$order, %$biblioitem}; |
| 338 |
} |
| 339 |
} |
| 340 |
if ($contract) { |
| 341 |
$order = {%$order, %$contract}; |
| 342 |
} |
| 343 |
$order = {%$order, %$basket, %$bd}; |
| 344 |
for my $field (@fields) { |
| 345 |
push @row, $order->{$field}; |
| 346 |
} |
| 347 |
push @rows, \@row; |
| 338 |
} |
348 |
} |
| 339 |
push @rows, $row; |
349 |
my $content = join( $csv_profile->{csv_separator}, @headers ) . "\n"; |
|
|
350 |
for my $row ( @rows ) { |
| 351 |
$csv->combine(@$row); |
| 352 |
my $string = $csv->string; |
| 353 |
$content .= $string . "\n"; |
| 354 |
} |
| 355 |
return $content; |
| 340 |
} |
356 |
} |
|
|
357 |
else { |
| 358 |
foreach my $order (@orders) { |
| 359 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
| 360 |
my $row = { |
| 361 |
contractname => $contract->{'contractname'}, |
| 362 |
ordernumber => $order->{'ordernumber'}, |
| 363 |
entrydate => $order->{'entrydate'}, |
| 364 |
isbn => $order->{'isbn'}, |
| 365 |
author => $bd->{'author'}, |
| 366 |
title => $bd->{'title'}, |
| 367 |
publicationyear => $bd->{'publicationyear'}, |
| 368 |
publishercode => $bd->{'publishercode'}, |
| 369 |
collectiontitle => $bd->{'collectiontitle'}, |
| 370 |
notes => $order->{'order_vendornote'}, |
| 371 |
quantity => $order->{'quantity'}, |
| 372 |
rrp => $order->{'rrp'}, |
| 373 |
deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ), |
| 374 |
billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ), |
| 375 |
}; |
| 376 |
foreach(qw( |
| 377 |
contractname author title publishercode collectiontitle notes |
| 378 |
deliveryplace billingplace |
| 379 |
) ) { |
| 380 |
# Double the quotes to not be interpreted as a field end |
| 381 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
| 382 |
} |
| 383 |
push @rows, $row; |
| 384 |
} |
| 341 |
|
385 |
|
| 342 |
@rows = sort { |
386 |
@rows = sort { |
| 343 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
387 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
| 344 |
$a->{publishercode} cmp $b->{publishercode}; |
388 |
$a->{publishercode} cmp $b->{publishercode}; |
| 345 |
} |
389 |
} |
| 346 |
} @rows; |
390 |
} @rows; |
| 347 |
|
391 |
|
| 348 |
$template->param(rows => \@rows); |
392 |
$template->param(rows => \@rows); |
| 349 |
|
393 |
|
| 350 |
return $template->output; |
394 |
return $template->output; |
|
|
395 |
} |
| 351 |
} |
396 |
} |
| 352 |
|
397 |
|
| 353 |
|
398 |
|