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

(-)a/C4/Acquisition.pm (-34 / +79 lines)
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
(-)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 490-549 sub get_order_infos { Link Here
490
    return \%line;
476
    return \%line;
491
}
477
}
492
478
493
sub get_basket_DB_info{
494
    my ( $basketno ) = @_;
495
    return () unless $basketno;
496
    my $dbh   = C4::Context->dbh;
497
    my $query  ="
498
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
499
                aqorders.*,
500
                aqbudgets.*
501
        FROM    aqorders
502
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
503
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
504
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
505
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
506
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
507
        WHERE   aqorders.basketno=?
508
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
509
            ORDER BY biblioitems.publishercode,biblio.title
510
    ";
511
    my $result_set =
512
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
513
    return @{$result_set};
514
}
515
516
sub get_basket_csv_profile_info{
517
    my ($csv_profile_content,$basketno) = @_;
518
519
    my ( @headers, @fields );
520
    while ( $csv_profile_content =~ /
521
        ([^=]+) # header
522
        =
523
        ([^\|]+) # fieldname (table.row or row)
524
        \|? /gxms
525
    ) {
526
        push @headers, $1;
527
        my $field = $2;
528
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
529
        push @fields, $field;
530
    }
531
532
    my @rows;
533
    my @basket_info = get_basket_DB_info($basketno);
534
535
    for my $basket_info ( @basket_info ) {
536
        my @row;
537
        for my $field ( @fields ) {
538
            push @row, $basket_info->{$field};
539
        }
540
        push @rows, \@row;
541
    }
542
    my $hash_ref;
543
    $hash_ref->{ 'headers' } = \@headers;
544
    $hash_ref->{ 'rows' } = \@rows;
545
546
    return $hash_ref;
547
}
548
549
output_html_with_http_headers $query, $cookie, $template->output;
479
output_html_with_http_headers $query, $cookie, $template->output;
550
- 

Return to bug 8612