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 510-517 Returns a reference to all baskets that belong to basketgroup $basketgroupid. Link Here
510
585
511
sub GetBasketsByBasketgroup {
586
sub GetBasketsByBasketgroup {
512
    my $basketgroupid = shift;
587
    my $basketgroupid = shift;
513
    my $query = "SELECT * FROM aqbasket
588
    my $query = qq{
514
                LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?";
589
        SELECT *, aqbasket.booksellerid as booksellerid
590
        FROM aqbasket
591
        LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?
592
    };
515
    my $dbh = C4::Context->dbh;
593
    my $dbh = C4::Context->dbh;
516
    my $sth = $dbh->prepare($query);
594
    my $sth = $dbh->prepare($query);
517
    $sth->execute($basketgroupid);
595
    $sth->execute($basketgroupid);
(-)a/C4/Output.pm (-2 / +2 lines)
Lines 41-53 BEGIN { Link Here
41
    require Exporter;
41
    require Exporter;
42
    @ISA    = qw(Exporter);
42
    @ISA    = qw(Exporter);
43
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
43
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
44
	%EXPORT_TAGS = ( all =>[qw(&pagination_bar
44
	%EXPORT_TAGS = ( all =>[qw(&pagination_bar &gettemplate
45
							   &output_with_http_headers &output_html_with_http_headers)],
45
							   &output_with_http_headers &output_html_with_http_headers)],
46
					ajax =>[qw(&output_with_http_headers is_ajax)],
46
					ajax =>[qw(&output_with_http_headers is_ajax)],
47
					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
47
					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
48
				);
48
				);
49
    push @EXPORT, qw(
49
    push @EXPORT, qw(
50
        &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
50
        &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar &gettemplate
51
    );
51
    );
52
}
52
}
53
53
(-)a/acqui/basket.pl (-1 / +8 lines)
Lines 145-151 if ( $op eq 'delete_confirm' ) { Link Here
145
        -type       => 'text/csv',
145
        -type       => 'text/csv',
146
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
146
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
147
    );
147
    );
148
    print GetBasketAsCSV($query->param('basketno'));
148
    print GetBasketAsCSV($query->param('basketno'), $query);
149
    exit;
149
    exit;
150
} elsif ($op eq 'close') {
150
} elsif ($op eq 'close') {
151
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
151
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
Lines 155-162 if ( $op eq 'delete_confirm' ) { Link Here
155
        $basketno =~ /^\d+$/ and CloseBasket($basketno);
155
        $basketno =~ /^\d+$/ and CloseBasket($basketno);
156
        # if requested, create basket group, close it and attach the basket
156
        # if requested, create basket group, close it and attach the basket
157
        if ($query->param('createbasketgroup')) {
157
        if ($query->param('createbasketgroup')) {
158
            my $branchcode;
159
            if(C4::Context->userenv and C4::Context->userenv->{'branch'}
160
              and C4::Context->userenv->{'branch'} ne "NO_LIBRARY_SET") {
161
                $branchcode = C4::Context->userenv->{'branch'};
162
            }
158
            my $basketgroupid = NewBasketgroup( { name => $basket->{basketname},
163
            my $basketgroupid = NewBasketgroup( { name => $basket->{basketname},
159
                            booksellerid => $booksellerid,
164
                            booksellerid => $booksellerid,
165
                            deliveryplace => $branchcode,
166
                            billingplace => $branchcode,
160
                            closed => 1,
167
                            closed => 1,
161
                            });
168
                            });
162
            ModBasket( { basketno => $basketno,
169
            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 (-2 / +5 lines)
Lines 285-291 function yuiToolbar() { Link Here
285
		<table>
285
		<table>
286
			<thead>
286
			<thead>
287
				<tr>
287
				<tr>
288
					<th>Basket Group</th><th colspan="3">Action</th>
288
					<th>Basket Group</th><th colspan="4">Action</th>
289
				</tr>
289
				</tr>
290
			</thead>
290
			</thead>
291
			<tbody>
291
			<tbody>
Lines 293-299 function yuiToolbar() { Link Here
293
				[% IF ( basketgroup.closed ) %]
293
				[% IF ( basketgroup.closed ) %]
294
				<tr>
294
				<tr>
295
				<td>
295
				<td>
296
					<a href="/cgi-bin/koha/acqui/basketgroup.pl?op=reopen&amp;booksellerid=[% basketgroup.booksellerid %]&amp;basketgroupid[% basketgroup.id %]">[% IF ( basketgroup.name ) %]
296
					<a href="/cgi-bin/koha/acqui/basketgroup.pl?op=reopen&amp;booksellerid=[% basketgroup.booksellerid %]&amp;basketgroupid=[% basketgroup.id %]">[% IF ( basketgroup.name ) %]
297
											[% basketgroup.name %]
297
											[% basketgroup.name %]
298
										[% ELSE %]
298
										[% ELSE %]
299
											Basket group no. [% basketgroup.id %]
299
											Basket group no. [% basketgroup.id %]
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