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

Return to bug 8612