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