|
Lines 278-284
$cgi parameter is needed for column name translation
Link Here
|
| 278 |
=cut |
278 |
=cut |
| 279 |
|
279 |
|
| 280 |
sub GetBasketAsCSV { |
280 |
sub GetBasketAsCSV { |
| 281 |
my ($basketno, $cgi) = @_; |
281 |
my ($basketno, $cgi, $csv_profile_id) = @_; |
| 282 |
my $basket = GetBasket($basketno); |
282 |
my $basket = GetBasket($basketno); |
| 283 |
my @orders = GetOrders($basketno); |
283 |
my @orders = GetOrders($basketno); |
| 284 |
my $contract = GetContract({ |
284 |
my $contract = GetContract({ |
|
Lines 286-330
sub GetBasketAsCSV {
Link Here
|
| 286 |
}); |
286 |
}); |
| 287 |
|
287 |
|
| 288 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); |
288 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); |
| 289 |
|
|
|
| 290 |
my @rows; |
289 |
my @rows; |
| 291 |
foreach my $order (@orders) { |
290 |
if ($csv_profile_id) { |
| 292 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
291 |
my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id ); |
| 293 |
my $row = { |
292 |
die "There is no valid csv profile given" unless $csv_profile; |
| 294 |
contractname => $contract->{'contractname'}, |
293 |
|
| 295 |
ordernumber => $order->{'ordernumber'}, |
294 |
my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1}); |
| 296 |
entrydate => $order->{'entrydate'}, |
295 |
my $csv_profile_content = $csv_profile->{content}; |
| 297 |
isbn => $order->{'isbn'}, |
296 |
my ( @headers, @fields ); |
| 298 |
author => $bd->{'author'}, |
297 |
while ( $csv_profile_content =~ / |
| 299 |
title => $bd->{'title'}, |
298 |
([^=]+) # header |
| 300 |
publicationyear => $bd->{'publicationyear'}, |
299 |
= |
| 301 |
publishercode => $bd->{'publishercode'}, |
300 |
([^\|]+) # fieldname (table.row or row) |
| 302 |
collectiontitle => $bd->{'collectiontitle'}, |
301 |
\|? /gxms |
| 303 |
notes => $order->{'order_vendornote'}, |
302 |
) { |
| 304 |
quantity => $order->{'quantity'}, |
303 |
push @headers, $1; |
| 305 |
rrp => $order->{'rrp'}, |
304 |
my $field = $2; |
| 306 |
deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ), |
305 |
$field =~ s/[^\.]*\.?//; # Remove the table name if exists. |
| 307 |
billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ), |
306 |
push @fields, $field; |
| 308 |
}; |
|
|
| 309 |
foreach(qw( |
| 310 |
contractname author title publishercode collectiontitle notes |
| 311 |
deliveryplace billingplace |
| 312 |
) ) { |
| 313 |
# Double the quotes to not be interpreted as a field end |
| 314 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
| 315 |
} |
307 |
} |
| 316 |
push @rows, $row; |
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}; |
| 323 |
} |
| 324 |
push @rows, \@row; |
| 325 |
} |
| 326 |
my $content = join( $csv_profile->{csv_separator}, @headers ) . "\n"; |
| 327 |
for my $row ( @rows ) { |
| 328 |
$csv->combine(@$row); |
| 329 |
my $string = $csv->string; |
| 330 |
$content .= $string . "\n"; |
| 331 |
} |
| 332 |
return $content; |
| 317 |
} |
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 |
deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ), |
| 351 |
billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ), |
| 352 |
}; |
| 353 |
foreach(qw( |
| 354 |
contractname author title publishercode collectiontitle notes |
| 355 |
deliveryplace billingplace |
| 356 |
) ) { |
| 357 |
# Double the quotes to not be interpreted as a field end |
| 358 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
| 359 |
} |
| 360 |
push @rows, $row; |
| 361 |
} |
| 318 |
|
362 |
|
| 319 |
@rows = sort { |
363 |
@rows = sort { |
| 320 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
364 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
| 321 |
$a->{publishercode} cmp $b->{publishercode}; |
365 |
$a->{publishercode} cmp $b->{publishercode}; |
| 322 |
} |
366 |
} |
| 323 |
} @rows; |
367 |
} @rows; |
| 324 |
|
368 |
|
| 325 |
$template->param(rows => \@rows); |
369 |
$template->param(rows => \@rows); |
| 326 |
|
370 |
|
| 327 |
return $template->output; |
371 |
return $template->output; |
|
|
372 |
} |
| 328 |
} |
373 |
} |
| 329 |
|
374 |
|
| 330 |
|
375 |
|