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 167-187 if ( $op eq 'delete_confirm' ) { Link Here
167
        print GetBasketAsCSV($query->param('basketno'), $query);
167
        print GetBasketAsCSV($query->param('basketno'), $query);
168
    } else {
168
    } else {
169
        my $csv_profile_id = $query->param('csv_profile');
169
        my $csv_profile_id = $query->param('csv_profile');
170
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
170
        print  GetBasketAsCSV($query->param('basketno'), $query, $csv_profile_id);
171
        die "There is no valid csv profile given" unless $csv_profile;
172
173
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
174
        my $csv_profile_content = $csv_profile->{content};
175
176
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
177
178
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
179
180
        for my $row ( @{$basket_info->{rows}} ) {
181
            $csv->combine(@$row);
182
            my $string = $csv->string;
183
            print $string, "\n";
184
        }
185
    }
171
    }
186
    exit;
172
    exit;
187
} elsif ($op eq 'email') {
173
} elsif ($op eq 'email') {
Lines 525-586 sub get_order_infos { Link Here
525
    return \%line;
511
    return \%line;
526
}
512
}
527
513
528
sub get_basket_DB_info{
529
    my ( $basketno ) = @_;
530
    return () unless $basketno;
531
    my $dbh   = C4::Context->dbh;
532
    my $query  ="
533
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
534
                aqorders.*,
535
                aqbudgets.*
536
        FROM    aqorders
537
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
538
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
539
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
540
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
541
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
542
        WHERE   aqorders.basketno=?
543
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
544
            ORDER BY biblioitems.publishercode,biblio.title
545
    ";
546
    my $result_set =
547
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
548
    return @{$result_set};
549
}
550
551
sub get_basket_csv_profile_info{
552
    my ($csv_profile_content,$basketno) = @_;
553
554
    my ( @headers, @fields );
555
    while ( $csv_profile_content =~ /
556
        ([^=]+) # header
557
        =
558
        ([^\|]+) # fieldname (table.row or row)
559
        \|? /gxms
560
    ) {
561
        push @headers, $1;
562
        my $field = $2;
563
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
564
        push @fields, $field;
565
    }
566
567
    my @rows;
568
    my @basket_info = get_basket_DB_info($basketno);
569
570
    for my $basket_info ( @basket_info ) {
571
        my @row;
572
        for my $field ( @fields ) {
573
            push @row, $basket_info->{$field};
574
        }
575
        push @rows, \@row;
576
    }
577
    my $hash_ref;
578
    $hash_ref->{ 'headers' } = \@headers;
579
    $hash_ref->{ 'rows' } = \@rows;
580
581
    return $hash_ref;
582
}
583
584
sub edi_close_and_order {
514
sub edi_close_and_order {
585
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
515
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
586
    if ($confirm) {
516
    if ($confirm) {
587
- 

Return to bug 8612