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

(-)a/C4/Acquisition.pm (-35 / +80 lines)
Lines 276-282 $cgi parameter is needed for column name translation Link Here
276
=cut
276
=cut
277
277
278
sub GetBasketAsCSV {
278
sub GetBasketAsCSV {
279
    my ($basketno, $cgi) = @_;
279
    my ($basketno, $cgi, $csv_profile_id) = @_;
280
    my $basket = GetBasket($basketno);
280
    my $basket = GetBasket($basketno);
281
    my @orders = GetOrders($basketno);
281
    my @orders = GetOrders($basketno);
282
    my $contract = GetContract({
282
    my $contract = GetContract({
Lines 284-331 sub GetBasketAsCSV { Link Here
284
    });
284
    });
285
285
286
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi);
286
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi);
287
288
    my @rows;
287
    my @rows;
289
    foreach my $order (@orders) {
288
    if ($csv_profile_id) {
290
        my $bd = GetBiblioData( $order->{'biblionumber'} );
289
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
291
        my $row = {
290
        die "There is no valid csv profile given" unless $csv_profile;
292
            contractname => $contract->{'contractname'},
291
293
            ordernumber => $order->{'ordernumber'},
292
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
294
            entrydate => $order->{'entrydate'},
293
        my $csv_profile_content = $csv_profile->{content};
295
            isbn => $order->{'isbn'},
294
        my ( @headers, @fields );
296
            author => $bd->{'author'},
295
        while ( $csv_profile_content =~ /
297
            title => $bd->{'title'},
296
            ([^=]+) # header
298
            publicationyear => $bd->{'publicationyear'},
297
            =
299
            publishercode => $bd->{'publishercode'},
298
            ([^\|]+) # fieldname (table.row or row)
300
            collectiontitle => $bd->{'collectiontitle'},
299
            \|? /gxms
301
            notes => $order->{'order_vendornote'},
300
        ) {
302
            quantity => $order->{'quantity'},
301
            push @headers, $1;
303
            rrp => $order->{'rrp'},
302
            my $field = $2;
304
        };
303
            $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
305
        for my $place ( qw( deliveryplace billingplace ) ) {
304
            push @fields, $field;
306
            if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) {
305
        }
307
                $row->{$place} = $library->branchname
306
        for my $order (@orders) {
307
            my @row;
308
            my $bd = GetBiblioData( $order->{'biblionumber'} );
309
            my @biblioitems = GetBiblioItemByBiblioNumber( $order->{'biblionumber'});
310
            for my $biblioitem (@biblioitems) {
311
                if ($biblioitem->{isbn} eq $order->{isbn}) {
312
                    $order = {%$order, %$biblioitem};
313
                }
314
            }
315
            if ($contract) {
316
                $order = {%$order, %$contract};
317
            }
318
            $order = {%$order, %$basket, %$bd};
319
            for my $field (@fields) {
320
                push @row, $order->{$field};
308
            }
321
            }
322
            push @rows, \@row;
309
        }
323
        }
310
        foreach(qw(
324
        my $content = join( $csv_profile->{csv_separator}, @headers ) . "\n";
311
            contractname author title publishercode collectiontitle notes
325
        for my $row ( @rows ) {
312
            deliveryplace billingplace
326
            $csv->combine(@$row);
313
        ) ) {
327
            my $string = $csv->string;
314
            # Double the quotes to not be interpreted as a field end
328
            $content .= $string . "\n";
315
            $row->{$_} =~ s/"/""/g if $row->{$_};
316
        }
329
        }
317
        push @rows, $row;
330
        return $content;
318
    }
331
    }
332
    else {
333
        foreach my $order (@orders) {
334
            my $bd = GetBiblioData( $order->{'biblionumber'} );
335
            my $row = {
336
                contractname => $contract->{'contractname'},
337
                ordernumber => $order->{'ordernumber'},
338
                entrydate => $order->{'entrydate'},
339
                isbn => $order->{'isbn'},
340
                author => $bd->{'author'},
341
                title => $bd->{'title'},
342
                publicationyear => $bd->{'publicationyear'},
343
                publishercode => $bd->{'publishercode'},
344
                collectiontitle => $bd->{'collectiontitle'},
345
                notes => $order->{'order_vendornote'},
346
                quantity => $order->{'quantity'},
347
                rrp => $order->{'rrp'},
348
            };
349
            for my $place ( qw( deliveryplace billingplace ) ) {
350
                if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) {
351
                    $row->{$place} = $library->branchname
352
                }
353
            }
354
            foreach(qw(
355
                contractname author title publishercode collectiontitle notes
356
                deliveryplace billingplace
357
            ) ) {
358
                # Double the quotes to not be interpreted as a field end
359
                $row->{$_} =~ s/"/""/g if $row->{$_};
360
            }
361
            push @rows, $row;
362
         }
319
363
320
    @rows = sort {
364
        @rows = sort {
321
        if(defined $a->{publishercode} and defined $b->{publishercode}) {
365
            if(defined $a->{publishercode} and defined $b->{publishercode}) {
322
            $a->{publishercode} cmp $b->{publishercode};
366
                $a->{publishercode} cmp $b->{publishercode};
323
        }
367
            }
324
    } @rows;
368
        } @rows;
325
369
326
    $template->param(rows => \@rows);
370
        $template->param(rows => \@rows);
327
371
328
    return $template->output;
372
        return $template->output;
373
    }
329
}
374
}
330
375
331
376
(-)a/acqui/basket.pl (-72 / +1 lines)
Lines 168-188 if ( $op eq 'delete_confirm' ) { Link Here
168
        print GetBasketAsCSV($query->param('basketno'), $query);
168
        print GetBasketAsCSV($query->param('basketno'), $query);
169
    } else {
169
    } else {
170
        my $csv_profile_id = $query->param('csv_profile');
170
        my $csv_profile_id = $query->param('csv_profile');
171
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
171
        print  GetBasketAsCSV($query->param('basketno'), $query, $csv_profile_id);
172
        die "There is no valid csv profile given" unless $csv_profile;
173
174
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
175
        my $csv_profile_content = $csv_profile->{content};
176
177
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
178
179
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
180
181
        for my $row ( @{$basket_info->{rows}} ) {
182
            $csv->combine(@$row);
183
            my $string = $csv->string;
184
            print $string, "\n";
185
        }
186
    }
172
    }
187
    exit;
173
    exit;
188
} elsif ($op eq 'close') {
174
} elsif ($op eq 'close') {
Lines 502-563 sub get_order_infos { Link Here
502
    return \%line;
488
    return \%line;
503
}
489
}
504
490
505
sub get_basket_DB_info{
506
    my ( $basketno ) = @_;
507
    return () unless $basketno;
508
    my $dbh   = C4::Context->dbh;
509
    my $query  ="
510
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
511
                aqorders.*,
512
                aqbudgets.*
513
        FROM    aqorders
514
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
515
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
516
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
517
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
518
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
519
        WHERE   aqorders.basketno=?
520
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
521
            ORDER BY biblioitems.publishercode,biblio.title
522
    ";
523
    my $result_set =
524
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
525
    return @{$result_set};
526
}
527
528
sub get_basket_csv_profile_info{
529
    my ($csv_profile_content,$basketno) = @_;
530
531
    my ( @headers, @fields );
532
    while ( $csv_profile_content =~ /
533
        ([^=]+) # header
534
        =
535
        ([^\|]+) # fieldname (table.row or row)
536
        \|? /gxms
537
    ) {
538
        push @headers, $1;
539
        my $field = $2;
540
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
541
        push @fields, $field;
542
    }
543
544
    my @rows;
545
    my @basket_info = get_basket_DB_info($basketno);
546
547
    for my $basket_info ( @basket_info ) {
548
        my @row;
549
        for my $field ( @fields ) {
550
            push @row, $basket_info->{$field};
551
        }
552
        push @rows, \@row;
553
    }
554
    my $hash_ref;
555
    $hash_ref->{ 'headers' } = \@headers;
556
    $hash_ref->{ 'rows' } = \@rows;
557
558
    return $hash_ref;
559
}
560
561
output_html_with_http_headers $query, $cookie, $template->output;
491
output_html_with_http_headers $query, $cookie, $template->output;
562
492
563
493
564
- 

Return to bug 8612