View | Details | Raw Unified | Return to bug 8612
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-34 / +79 lines)
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
(-)a/acqui/basket.pl (-72 / +1 lines)
Lines 161-181 if ( $op eq 'delete_confirm' ) { Link Here
161
        print GetBasketAsCSV($query->param('basketno'), $query);
161
        print GetBasketAsCSV($query->param('basketno'), $query);
162
    } else {
162
    } else {
163
        my $csv_profile_id = $query->param('csv_profile');
163
        my $csv_profile_id = $query->param('csv_profile');
164
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
164
        print  GetBasketAsCSV($query->param('basketno'), $query, $csv_profile_id);
165
        die "There is no valid csv profile given" unless $csv_profile;
166
167
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
168
        my $csv_profile_content = $csv_profile->{content};
169
170
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
171
172
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
173
174
        for my $row ( @{$basket_info->{rows}} ) {
175
            $csv->combine(@$row);
176
            my $string = $csv->string;
177
            print $string, "\n";
178
        }
179
    }
165
    }
180
    exit;
166
    exit;
181
} elsif ($op eq 'close') {
167
} elsif ($op eq 'close') {
Lines 492-551 sub get_order_infos { Link Here
492
    return \%line;
478
    return \%line;
493
}
479
}
494
480
495
sub get_basket_DB_info{
496
    my ( $basketno ) = @_;
497
    return () unless $basketno;
498
    my $dbh   = C4::Context->dbh;
499
    my $query  ="
500
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
501
                aqorders.*,
502
                aqbudgets.*
503
        FROM    aqorders
504
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
505
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
506
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
507
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
508
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
509
        WHERE   aqorders.basketno=?
510
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
511
            ORDER BY biblioitems.publishercode,biblio.title
512
    ";
513
    my $result_set =
514
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
515
    return @{$result_set};
516
}
517
518
sub get_basket_csv_profile_info{
519
    my ($csv_profile_content,$basketno) = @_;
520
521
    my ( @headers, @fields );
522
    while ( $csv_profile_content =~ /
523
        ([^=]+) # header
524
        =
525
        ([^\|]+) # fieldname (table.row or row)
526
        \|? /gxms
527
    ) {
528
        push @headers, $1;
529
        my $field = $2;
530
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
531
        push @fields, $field;
532
    }
533
534
    my @rows;
535
    my @basket_info = get_basket_DB_info($basketno);
536
537
    for my $basket_info ( @basket_info ) {
538
        my @row;
539
        for my $field ( @fields ) {
540
            push @row, $basket_info->{$field};
541
        }
542
        push @rows, \@row;
543
    }
544
    my $hash_ref;
545
    $hash_ref->{ 'headers' } = \@headers;
546
    $hash_ref->{ 'rows' } = \@rows;
547
548
    return $hash_ref;
549
}
550
551
output_html_with_http_headers $query, $cookie, $template->output;
481
output_html_with_http_headers $query, $cookie, $template->output;
552
- 

Return to bug 8612