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
49
48
        &ModBasketHeader
50
        &ModBasketHeader
Lines 226-279 sub CloseBasket { Link Here
226
228
227
Export a basket as CSV
229
Export a basket as CSV
228
230
231
$cgi parameter is needed for column name translation
232
229
=cut
233
=cut
230
234
231
sub GetBasketAsCSV {
235
sub GetBasketAsCSV {
232
    my ($basketno) = @_;
236
    my ($basketno, $cgi) = @_;
233
    my $basket = GetBasket($basketno);
237
    my $basket = GetBasket($basketno);
234
    my @orders = GetOrders($basketno);
238
    my @orders = GetOrders($basketno);
235
    my $contract = GetContract($basket->{'contractnumber'});
239
    my $contract = GetContract($basket->{'contractnumber'});
236
    my $csv = Text::CSV->new();
237
    my $output; 
238
239
    # TODO: Translate headers
240
    my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp);
241
240
242
    $csv->combine(@headers);                                                                                                        
241
    my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi);
243
    $output = $csv->string() . "\n";	
244
242
245
    my @rows;
243
    my @rows;
246
    foreach my $order (@orders) {
244
    foreach my $order (@orders) {
247
	my @cols;
245
        my $bd = GetBiblioData( $order->{'biblionumber'} );
248
	# newlines are not valid characters for Text::CSV combine()
246
        my $row = {
249
        $order->{'notes'} =~ s/[\r\n]+//g;
247
            contractname => $contract->{'contractname'},
250
	push(@cols,
248
            ordernumber => $order->{'ordernumber'},
251
		$contract->{'contractname'},
249
            entrydate => $order->{'entrydate'},
252
		$order->{'ordernumber'},
250
            isbn => $order->{'isbn'},
253
		$order->{'entrydate'}, 
251
            author => $bd->{'author'},
254
		$order->{'isbn'},
252
            title => $bd->{'title'},
255
		$order->{'author'},
253
            publicationyear => $bd->{'publicationyear'},
256
		$order->{'title'},
254
            publishercode => $bd->{'publishercode'},
257
		$order->{'publishercode'},
255
            collectiontitle => $bd->{'collectiontitle'},
258
		$order->{'collectiontitle'},
256
            notes => $order->{'notes'},
259
		$order->{'notes'},
257
            quantity => $order->{'quantity'},
260
		$order->{'quantity'},
258
            rrp => $order->{'rrp'},
261
		$order->{'rrp'},
259
            deliveryplace => $basket->{'deliveryplace'},
262
	    );
260
            billingplace => $basket->{'billingplace'}
263
	push (@rows, \@cols);
261
        };
262
        foreach(qw(
263
            contractname author title publishercode collectiontitle notes
264
            deliveryplace billingplace
265
        ) ) {
266
            # Double the quotes to not be interpreted as a field end
267
            $row->{$_} =~ s/"/""/g if $row->{$_};
268
        }
269
        push @rows, $row;
264
    }
270
    }
265
271
266
    foreach my $row (@rows) {
272
    @rows = sort {
267
	$csv->combine(@$row);                                                                                                                    
273
        if(defined $a->{publishercode} and defined $b->{publishercode}) {
268
	$output .= $csv->string() . "\n";    
274
            $a->{publishercode} cmp $b->{publishercode};
275
        }
276
    } @rows;
269
277
270
    }
278
    $template->param(rows => \@rows);
271
                                                                                                                                                      
272
    return $output;             
273
279
280
    return $template->output;
274
}
281
}
275
282
276
283
284
=head3 GetBasketGroupAsCSV
285
286
=over 4
287
288
&GetBasketGroupAsCSV($basketgroupid);
289
290
Export a basket group as CSV
291
292
$cgi parameter is needed for column name translation
293
294
=back
295
296
=cut
297
298
sub GetBasketGroupAsCSV {
299
    my ($basketgroupid, $cgi) = @_;
300
    my $baskets = GetBasketsByBasketgroup($basketgroupid);
301
302
    my $template = C4::Templates::gettemplate('acqui/csv/basketgroup.tmpl', 'intranet', $cgi);
303
304
    my @rows;
305
    for my $basket (@$baskets) {
306
        my @orders     = GetOrders( $$basket{basketno} );
307
        my $contract   = GetContract( $$basket{contractnumber} );
308
        my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
309
310
        foreach my $order (@orders) {
311
            my $bd = GetBiblioData( $order->{'biblionumber'} );
312
            my $row = {
313
                clientnumber => $bookseller->{accountnumber},
314
                basketname => $basket->{basketname},
315
                ordernumber => $order->{ordernumber},
316
                author => $bd->{author},
317
                title => $bd->{title},
318
                publishercode => $bd->{publishercode},
319
                publicationyear => $bd->{publicationyear},
320
                collectiontitle => $bd->{collectiontitle},
321
                isbn => $order->{isbn},
322
                quantity => $order->{quantity},
323
                rrp => $order->{rrp},
324
                discount => $bookseller->{discount},
325
                ecost => $order->{ecost},
326
                notes => $order->{notes},
327
                entrydate => $order->{entrydate},
328
                booksellername => $bookseller->{name},
329
                bookselleraddress => $bookseller->{address1},
330
                booksellerpostal => $bookseller->{postal},
331
                contractnumber => $contract->{contractnumber},
332
                contractname => $contract->{contractname},
333
            };
334
            foreach(qw(
335
                basketname author title publishercode collectiontitle notes
336
                booksellername bookselleraddress booksellerpostal contractname
337
                basketgroupdeliveryplace basketgroupbillingplace
338
                basketdeliveryplace basketbillingplace
339
            ) ) {
340
                # Double the quotes to not be interpreted as a field end
341
                $row->{$_} =~ s/"/""/g if $row->{$_};
342
            }
343
            push @rows, $row;
344
         }
345
     }
346
    $template->param(rows => \@rows);
347
348
    return $template->output;
349
350
}
351
277
=head3 CloseBasketgroup
352
=head3 CloseBasketgroup
278
353
279
  &CloseBasketgroup($basketgroupno);
354
  &CloseBasketgroup($basketgroupno);
Lines 476-483 Returns a reference to all baskets that belong to basketgroup $basketgroupid. Link Here
476
551
477
sub GetBasketsByBasketgroup {
552
sub GetBasketsByBasketgroup {
478
    my $basketgroupid = shift;
553
    my $basketgroupid = shift;
479
    my $query = "SELECT * FROM aqbasket
554
    my $query = qq{
480
                LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?";
555
        SELECT *, aqbasket.booksellerid as booksellerid
556
        FROM aqbasket
557
        LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?
558
    };
481
    my $dbh = C4::Context->dbh;
559
    my $dbh = C4::Context->dbh;
482
    my $sth = $dbh->prepare($query);
560
    my $sth = $dbh->prepare($query);
483
    $sth->execute($basketgroupid);
561
    $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 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 (-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