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

(-)a/C4/Acquisition.pm (-34 / +112 lines)
Lines 29-34 use C4::Suggestions; Link Here
29
use C4::Biblio;
29
use C4::Biblio;
30
use C4::Debug;
30
use C4::Debug;
31
use C4::SQLHelper qw(InsertInTable);
31
use C4::SQLHelper qw(InsertInTable);
32
use C4::Bookseller qw(GetBookSellerFromId);
33
use C4::Templates qw(gettemplate);
32
34
33
use Time::localtime;
35
use Time::localtime;
34
use HTML::Entities;
36
use HTML::Entities;
Lines 42-48 BEGIN { Link Here
42
    @ISA    = qw(Exporter);
44
    @ISA    = qw(Exporter);
43
    @EXPORT = qw(
45
    @EXPORT = qw(
44
        &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
46
        &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
45
	&GetBasketAsCSV
47
        &GetBasketAsCSV &GetBasketGroupAsCSV
46
        &GetBasketsByBookseller &GetBasketsByBasketgroup
48
        &GetBasketsByBookseller &GetBasketsByBasketgroup
47
        &GetBasketsInfosByBookseller
49
        &GetBasketsInfosByBookseller
48
50
Lines 227-280 sub CloseBasket { Link Here
227
229
228
Export a basket as CSV
230
Export a basket as CSV
229
231
232
$cgi parameter is needed for column name translation
233
230
=cut
234
=cut
231
235
232
sub GetBasketAsCSV {
236
sub GetBasketAsCSV {
233
    my ($basketno) = @_;
237
    my ($basketno, $cgi) = @_;
234
    my $basket = GetBasket($basketno);
238
    my $basket = GetBasket($basketno);
235
    my @orders = GetOrders($basketno);
239
    my @orders = GetOrders($basketno);
236
    my $contract = GetContract($basket->{'contractnumber'});
240
    my $contract = GetContract($basket->{'contractnumber'});
237
    my $csv = Text::CSV->new();
238
    my $output; 
239
241
240
    # TODO: Translate headers
242
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi);
241
    my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp);
242
243
    $csv->combine(@headers);                                                                                                        
244
    $output = $csv->string() . "\n";	
245
243
246
    my @rows;
244
    my @rows;
247
    foreach my $order (@orders) {
245
    foreach my $order (@orders) {
248
	my @cols;
246
        my $bd = GetBiblioData( $order->{'biblionumber'} );
249
	# newlines are not valid characters for Text::CSV combine()
247
        my $row = {
250
        $order->{'notes'} =~ s/[\r\n]+//g;
248
            contractname => $contract->{'contractname'},
251
	push(@cols,
249
            ordernumber => $order->{'ordernumber'},
252
		$contract->{'contractname'},
250
            entrydate => $order->{'entrydate'},
253
		$order->{'ordernumber'},
251
            isbn => $order->{'isbn'},
254
		$order->{'entrydate'}, 
252
            author => $bd->{'author'},
255
		$order->{'isbn'},
253
            title => $bd->{'title'},
256
		$order->{'author'},
254
            publicationyear => $bd->{'publicationyear'},
257
		$order->{'title'},
255
            publishercode => $bd->{'publishercode'},
258
		$order->{'publishercode'},
256
            collectiontitle => $bd->{'collectiontitle'},
259
		$order->{'collectiontitle'},
257
            notes => $order->{'notes'},
260
		$order->{'notes'},
258
            quantity => $order->{'quantity'},
261
		$order->{'quantity'},
259
            rrp => $order->{'rrp'},
262
		$order->{'rrp'},
260
            deliveryplace => $basket->{'deliveryplace'},
263
	    );
261
            billingplace => $basket->{'billingplace'}
264
	push (@rows, \@cols);
262
        };
263
        foreach(qw(
264
            contractname author title publishercode collectiontitle notes
265
            deliveryplace billingplace
266
        ) ) {
267
            # Double the quotes to not be interpreted as a field end
268
            $row->{$_} =~ s/"/""/g if $row->{$_};
269
        }
270
        push @rows, $row;
265
    }
271
    }
266
272
267
    foreach my $row (@rows) {
273
    @rows = sort {
268
	$csv->combine(@$row);                                                                                                                    
274
        if(defined $a->{publishercode} and defined $b->{publishercode}) {
269
	$output .= $csv->string() . "\n";    
275
            $a->{publishercode} cmp $b->{publishercode};
276
        }
277
    } @rows;
270
278
271
    }
279
    $template->param(rows => \@rows);
272
                                                                                                                                                      
273
    return $output;             
274
280
281
    return $template->output;
275
}
282
}
276
283
277
284
285
=head3 GetBasketGroupAsCSV
286
287
=over 4
288
289
&GetBasketGroupAsCSV($basketgroupid);
290
291
Export a basket group as CSV
292
293
$cgi parameter is needed for column name translation
294
295
=back
296
297
=cut
298
299
sub GetBasketGroupAsCSV {
300
    my ($basketgroupid, $cgi) = @_;
301
    my $baskets = GetBasketsByBasketgroup($basketgroupid);
302
303
    my $template = C4::Templates::gettemplate('acqui/csv/basketgroup.tmpl', 'intranet', $cgi);
304
305
    my @rows;
306
    for my $basket (@$baskets) {
307
        my @orders     = GetOrders( $$basket{basketno} );
308
        my $contract   = GetContract( $$basket{contractnumber} );
309
        my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
310
311
        foreach my $order (@orders) {
312
            my $bd = GetBiblioData( $order->{'biblionumber'} );
313
            my $row = {
314
                clientnumber => $bookseller->{accountnumber},
315
                basketname => $basket->{basketname},
316
                ordernumber => $order->{ordernumber},
317
                author => $bd->{author},
318
                title => $bd->{title},
319
                publishercode => $bd->{publishercode},
320
                publicationyear => $bd->{publicationyear},
321
                collectiontitle => $bd->{collectiontitle},
322
                isbn => $order->{isbn},
323
                quantity => $order->{quantity},
324
                rrp => $order->{rrp},
325
                discount => $bookseller->{discount},
326
                ecost => $order->{ecost},
327
                notes => $order->{notes},
328
                entrydate => $order->{entrydate},
329
                booksellername => $bookseller->{name},
330
                bookselleraddress => $bookseller->{address1},
331
                booksellerpostal => $bookseller->{postal},
332
                contractnumber => $contract->{contractnumber},
333
                contractname => $contract->{contractname},
334
            };
335
            foreach(qw(
336
                basketname author title publishercode collectiontitle notes
337
                booksellername bookselleraddress booksellerpostal contractname
338
                basketgroupdeliveryplace basketgroupbillingplace
339
                basketdeliveryplace basketbillingplace
340
            ) ) {
341
                # Double the quotes to not be interpreted as a field end
342
                $row->{$_} =~ s/"/""/g if $row->{$_};
343
            }
344
            push @rows, $row;
345
         }
346
     }
347
    $template->param(rows => \@rows);
348
349
    return $template->output;
350
351
}
352
278
=head3 CloseBasketgroup
353
=head3 CloseBasketgroup
279
354
280
  &CloseBasketgroup($basketgroupno);
355
  &CloseBasketgroup($basketgroupno);
Lines 514-521 Returns a reference to all baskets that belong to basketgroup $basketgroupid. Link Here
514
589
515
sub GetBasketsByBasketgroup {
590
sub GetBasketsByBasketgroup {
516
    my $basketgroupid = shift;
591
    my $basketgroupid = shift;
517
    my $query = "SELECT * FROM aqbasket
592
    my $query = qq{
518
                LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?";
593
        SELECT *, aqbasket.booksellerid as booksellerid
594
        FROM aqbasket
595
        LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?
596
    };
519
    my $dbh = C4::Context->dbh;
597
    my $dbh = C4::Context->dbh;
520
    my $sth = $dbh->prepare($query);
598
    my $sth = $dbh->prepare($query);
521
    $sth->execute($basketgroupid);
599
    $sth->execute($basketgroupid);
(-)a/C4/Output.pm (-2 / +2 lines)
Lines 42-54 BEGIN { Link Here
42
42
43
 @ISA    = qw(Exporter);
43
 @ISA    = qw(Exporter);
44
    @EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
44
    @EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
45
    %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar
45
    %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar &gettemplate
46
                                &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
46
                                &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
47
                    ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
47
                    ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
48
                    html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
48
                    html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
49
                );
49
                );
50
    push @EXPORT, qw(
50
    push @EXPORT, qw(
51
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
51
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar &gettemplate
52
    );
52
    );
53
    push @EXPORT, qw(
53
    push @EXPORT, qw(
54
        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber
54
        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber
(-)a/acqui/basket.pl (-1 / +8 lines)
Lines 146-152 if ( $op eq 'delete_confirm' ) { Link Here
146
        -type       => 'text/csv',
146
        -type       => 'text/csv',
147
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
147
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
148
    );
148
    );
149
    print GetBasketAsCSV($query->param('basketno'));
149
    print GetBasketAsCSV($query->param('basketno'), $query);
150
    exit;
150
    exit;
151
} elsif ($op eq 'close') {
151
} elsif ($op eq 'close') {
152
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
152
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
Lines 156-163 if ( $op eq 'delete_confirm' ) { Link Here
156
        $basketno =~ /^\d+$/ and CloseBasket($basketno);
156
        $basketno =~ /^\d+$/ and CloseBasket($basketno);
157
        # if requested, create basket group, close it and attach the basket
157
        # if requested, create basket group, close it and attach the basket
158
        if ($query->param('createbasketgroup')) {
158
        if ($query->param('createbasketgroup')) {
159
            my $branchcode;
160
            if(C4::Context->userenv and C4::Context->userenv->{'branch'}
161
              and C4::Context->userenv->{'branch'} ne "NO_LIBRARY_SET") {
162
                $branchcode = C4::Context->userenv->{'branch'};
163
            }
159
            my $basketgroupid = NewBasketgroup( { name => $basket->{basketname},
164
            my $basketgroupid = NewBasketgroup( { name => $basket->{basketname},
160
                            booksellerid => $booksellerid,
165
                            booksellerid => $booksellerid,
166
                            deliveryplace => $branchcode,
167
                            billingplace => $branchcode,
161
                            closed => 1,
168
                            closed => 1,
162
                            });
169
                            });
163
            ModBasket( { basketno => $basketno,
170
            ModBasket( { basketno => $basketno,
(-)a/acqui/basketgroup.pl (-2 / +10 lines)
Lines 53-59 use C4::Output; Link Here
53
use CGI;
53
use CGI;
54
54
55
use C4::Bookseller qw/GetBookSellerFromId/;
55
use C4::Bookseller qw/GetBookSellerFromId/;
56
use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket/;
56
use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/;
57
use C4::Bookseller qw/GetBookSellerFromId/;
57
use C4::Bookseller qw/GetBookSellerFromId/;
58
use C4::Branch qw/GetBranches/;
58
use C4::Branch qw/GetBranches/;
59
use C4::Members qw/GetMember/;
59
use C4::Members qw/GetMember/;
Lines 277-283 sub printbasketgrouppdf{ Link Here
277
277
278
}
278
}
279
279
280
my $op = $input->param('op');
280
my $op = $input->param('op') || 'display';
281
my $booksellerid = $input->param('booksellerid');
281
my $booksellerid = $input->param('booksellerid');
282
$template->param(booksellerid => $booksellerid);
282
$template->param(booksellerid => $booksellerid);
283
283
Lines 417-422 if ( $op eq "add" ) { Link Here
417
    
417
    
418
    printbasketgrouppdf($basketgroupid);
418
    printbasketgrouppdf($basketgroupid);
419
    exit;
419
    exit;
420
}elsif ( $op eq "export" ) {
421
    my $basketgroupid = $input->param('basketgroupid');
422
    print $input->header(
423
        -type       => 'text/csv',
424
        -attachment => 'basketgroup' . $basketgroupid . '.csv',
425
    );
426
    print GetBasketGroupAsCSV( $basketgroupid, $input );
427
    exit;
420
}elsif( $op eq "delete"){
428
}elsif( $op eq "delete"){
421
    my $basketgroupid = $input->param('basketgroupid');
429
    my $basketgroupid = $input->param('basketgroupid');
422
    DelBasketgroup($basketgroupid);
430
    DelBasketgroup($basketgroupid);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt (+3 lines)
Lines 305-310 function yuiToolbar() { Link Here
305
						<td>
305
						<td>
306
							<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="print" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Print" /></form>
306
							<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="print" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Print" /></form>
307
						</td>
307
						</td>
308
                    <td>
309
                        <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="export" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Export as CSV" /></form>
310
                    </td>
308
				</tr>
311
				</tr>
309
				[% END %]
312
				[% END %]
310
				[% END %]
313
				[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/basket.tt (+3 lines)
Line 0 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 %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/basketgroup.tt (-1 / +3 lines)
Line 0 Link Here
0
- 
1
Client number,Basket name,Order number,Author,Title,Publisher code,Publication year,Collection title,ISBN,Quantity,RRP,Discount,Estimated cost,Notes,Entry date,Bookseller name,Bookseller physical address,Bookseller postal address,Contract number,Contract name,Basket group delivery place,Basket group billing place,Basket delivery place,Basket billing place
2
[% FOREACH r IN rows %][% r.clientnumber %],"[% r.basketname %]",[% r.ordernumber %],"[% r.author %]","[% r.title %]","[% r.publishercode %]",[% r.publicationyear %],"[% r.collectiontitle %]",[% r.isbn %],[% r.quantity %],[% r.rrp %],[% r.discount %],[% r.ecost %],"[% r.notes %]",[% r.entrydate %],"[% r.booksellername %]","[% r.bookselleraddress %]","[% r.booksellerpostal %]",[% r.contractnumber %],"[% r.contractname %]","[% r.basketgroupdeliveryplace %]","[% r.basketgroupbillingplace %]","[% r.basketdeliveryplace %]","[% r.basketbillingplace %]"
3
[% END %]

Return to bug 7302