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

(-)a/C4/Acquisition.pm (-30 / +49 lines)
Lines 17-23 package C4::Acquisition; Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
21
use strict;
20
use strict;
22
use warnings;
21
use warnings;
23
use Carp;
22
use Carp;
Lines 34-39 use C4::Templates qw(gettemplate); Link Here
34
33
35
use Time::localtime;
34
use Time::localtime;
36
use HTML::Entities;
35
use HTML::Entities;
36
use Text::CSV::Encoded;
37
37
38
use vars qw($VERSION @ISA @EXPORT);
38
use vars qw($VERSION @ISA @EXPORT);
39
39
Lines 234-284 $cgi parameter is needed for column name translation Link Here
234
=cut
234
=cut
235
235
236
sub GetBasketAsCSV {
236
sub GetBasketAsCSV {
237
    my ($basketno, $cgi) = @_;
237
    my ($basketno, $lh) = @_;
238
    my $basket = GetBasket($basketno);
238
    my $basket = GetBasket($basketno);
239
    my @orders = GetOrders($basketno);
239
    my @orders = GetOrders($basketno);
240
    my $contract = GetContract($basket->{'contractnumber'});
240
    my $contract = GetContract($basket->{'contractnumber'});
241
    my $csv = Text::CSV::Encoded->new();
242
    my $output;
243
244
    my @headers = (
245
        $lh->maketext('Contract name'),
246
        $lh->maketext('Order number'),
247
        $lh->maketext('Entry date'),
248
        $lh->maketext('ISBN'),
249
        $lh->maketext('Author'),
250
        $lh->maketext('Title'),
251
        $lh->maketext('Publication year'),
252
        $lh->maketext('Publisher code'),
253
        $lh->maketext('Collection title'),
254
        $lh->maketext('Notes'),
255
        $lh->maketext('Quantity'),
256
        $lh->maketext('RRP'),
257
        $lh->maketext('Delivery place'),
258
        $lh->maketext('Billing place'),
259
    );
241
260
242
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi);
261
    $csv->combine(@headers);
262
    $output = $csv->string() . "\n";
243
263
244
    my @rows;
264
    my @rows;
245
    foreach my $order (@orders) {
265
    foreach my $order (@orders) {
246
        my $bd = GetBiblioData( $order->{'biblionumber'} );
266
        my $bd = GetBiblioData( $order->{'biblionumber'} );
247
        my $row = {
267
        my @row = (
248
            contractname => $contract->{'contractname'},
268
            $contract->{'contractname'},
249
            ordernumber => $order->{'ordernumber'},
269
            $order->{'ordernumber'},
250
            entrydate => $order->{'entrydate'},
270
            $order->{'entrydate'},
251
            isbn => $order->{'isbn'},
271
            $order->{'isbn'},
252
            author => $bd->{'author'},
272
            $bd->{'author'},
253
            title => $bd->{'title'},
273
            $bd->{'title'},
254
            publicationyear => $bd->{'publicationyear'},
274
            $bd->{'publicationyear'},
255
            publishercode => $bd->{'publishercode'},
275
            $bd->{'publishercode'},
256
            collectiontitle => $bd->{'collectiontitle'},
276
            $bd->{'collectiontitle'},
257
            notes => $order->{'notes'},
277
            $order->{'notes'},
258
            quantity => $order->{'quantity'},
278
            $order->{'quantity'},
259
            rrp => $order->{'rrp'},
279
            $order->{'rrp'},
260
            deliveryplace => $basket->{'deliveryplace'},
280
            $basket->{'deliveryplace'},
261
            billingplace => $basket->{'billingplace'}
281
            $basket->{'billingplace'}
262
        };
282
        );
263
        foreach(qw(
283
        foreach (@row) {
264
            contractname author title publishercode collectiontitle notes
265
            deliveryplace billingplace
266
        ) ) {
267
            # Double the quotes to not be interpreted as a field end
284
            # Double the quotes to not be interpreted as a field end
268
            $row->{$_} =~ s/"/""/g if $row->{$_};
285
            $_ =~ s/"/""/g;
269
        }
286
        }
270
        push @rows, $row;
287
        push @rows, \@row;
271
    }
288
    }
272
289
273
    @rows = sort {
290
    @rows = sort {
274
        if(defined $a->{publishercode} and defined $b->{publishercode}) {
291
        if(defined $a->[7] and defined $b->[7]) {
275
            $a->{publishercode} cmp $b->{publishercode};
292
            $a->[7] cmp $b->[7];
276
        }
293
        }
277
    } @rows;
294
    } @rows;
295
    foreach my $row (@rows) {
296
        $csv->combine(@$row);
297
        $output .= $csv->string . "\n";
298
    }
278
299
279
    $template->param(rows => \@rows);
300
    return $output;
280
281
    return $template->output;
282
}
301
}
283
302
284
303
(-)a/acqui/basket.pl (-1 / +3 lines)
Lines 35-40 use C4::Members qw/GetMember/; #needed for permissions checking for changing ba Link Here
35
use C4::Items;
35
use C4::Items;
36
use C4::Suggestions;
36
use C4::Suggestions;
37
use Date::Calc qw/Add_Delta_Days/;
37
use Date::Calc qw/Add_Delta_Days/;
38
use Koha::I18N;
38
39
39
=head1 NAME
40
=head1 NAME
40
41
Lines 142-152 if ( $op eq 'delete_confirm' ) { Link Here
142
      print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid);
143
      print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid);
143
    # check if we have to "close" a basket before building page
144
    # check if we have to "close" a basket before building page
144
} elsif ($op eq 'export') {
145
} elsif ($op eq 'export') {
146
    my $lh = Koha::I18N->get_handle_from_context($query, 'intranet');
145
    print $query->header(
147
    print $query->header(
146
        -type       => 'text/csv',
148
        -type       => 'text/csv',
147
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
149
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
148
    );
150
    );
149
    print GetBasketAsCSV($query->param('basketno'), $query);
151
    print GetBasketAsCSV($query->param('basketno'), $lh);
150
    exit;
152
    exit;
151
} elsif ($op eq 'close') {
153
} elsif ($op eq 'close') {
152
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
154
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/basket.tt (-4 lines)
Lines 1-3 Link Here
1
Contract name,Order number,Entry date,ISBN,Author,Title,Publication year,Publisher code,Collection title,Notes,Quantity,RRP,Delivery place,Billing place
2
[% FOREACH r IN rows %]"[% r.contractname %]",[% r.ordernumber %],[% r.entrydate %],[% r.isbn %],"[% r.author %]","[% r.title %]",[% r.publicationyear %],"[% r.publishercode %]","[% r.collectiontitle %]","[% r.notes %]",[% r.quantity %],[% r.rrp %],"[% r.deliveryplace %]","[% r.billingplace %]"
3
[% END %]
4
- 

Return to bug 8044