|
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 244-294
$cgi parameter is needed for column name translation
Link Here
|
| 244 |
=cut |
244 |
=cut |
| 245 |
|
245 |
|
| 246 |
sub GetBasketAsCSV { |
246 |
sub GetBasketAsCSV { |
| 247 |
my ($basketno, $cgi) = @_; |
247 |
my ($basketno, $lh) = @_; |
| 248 |
my $basket = GetBasket($basketno); |
248 |
my $basket = GetBasket($basketno); |
| 249 |
my @orders = GetOrders($basketno); |
249 |
my @orders = GetOrders($basketno); |
| 250 |
my $contract = GetContract($basket->{'contractnumber'}); |
250 |
my $contract = GetContract($basket->{'contractnumber'}); |
|
|
251 |
my $csv = Text::CSV::Encoded->new(); |
| 252 |
my $output; |
| 253 |
|
| 254 |
my @headers = ( |
| 255 |
$lh->maketext('Contract name'), |
| 256 |
$lh->maketext('Order number'), |
| 257 |
$lh->maketext('Entry date'), |
| 258 |
$lh->maketext('ISBN'), |
| 259 |
$lh->maketext('Author'), |
| 260 |
$lh->maketext('Title'), |
| 261 |
$lh->maketext('Publication year'), |
| 262 |
$lh->maketext('Publisher code'), |
| 263 |
$lh->maketext('Collection title'), |
| 264 |
$lh->maketext('Notes'), |
| 265 |
$lh->maketext('Quantity'), |
| 266 |
$lh->maketext('RRP'), |
| 267 |
$lh->maketext('Delivery place'), |
| 268 |
$lh->maketext('Billing place'), |
| 269 |
); |
| 251 |
|
270 |
|
| 252 |
my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi); |
271 |
$csv->combine(@headers); |
|
|
272 |
$output = $csv->string() . "\n"; |
| 253 |
|
273 |
|
| 254 |
my @rows; |
274 |
my @rows; |
| 255 |
foreach my $order (@orders) { |
275 |
foreach my $order (@orders) { |
| 256 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
276 |
my $bd = GetBiblioData( $order->{'biblionumber'} ); |
| 257 |
my $row = { |
277 |
my @row = ( |
| 258 |
contractname => $contract->{'contractname'}, |
278 |
$contract->{'contractname'}, |
| 259 |
ordernumber => $order->{'ordernumber'}, |
279 |
$order->{'ordernumber'}, |
| 260 |
entrydate => $order->{'entrydate'}, |
280 |
$order->{'entrydate'}, |
| 261 |
isbn => $order->{'isbn'}, |
281 |
$order->{'isbn'}, |
| 262 |
author => $bd->{'author'}, |
282 |
$bd->{'author'}, |
| 263 |
title => $bd->{'title'}, |
283 |
$bd->{'title'}, |
| 264 |
publicationyear => $bd->{'publicationyear'}, |
284 |
$bd->{'publicationyear'}, |
| 265 |
publishercode => $bd->{'publishercode'}, |
285 |
$bd->{'publishercode'}, |
| 266 |
collectiontitle => $bd->{'collectiontitle'}, |
286 |
$bd->{'collectiontitle'}, |
| 267 |
notes => $order->{'notes'}, |
287 |
$order->{'notes'}, |
| 268 |
quantity => $order->{'quantity'}, |
288 |
$order->{'quantity'}, |
| 269 |
rrp => $order->{'rrp'}, |
289 |
$order->{'rrp'}, |
| 270 |
deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ), |
290 |
C4::Branch::GetBranchName($basket->{'deliveryplace'}), |
| 271 |
billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ), |
291 |
C4::Branch::GetBranchName($basket->{'billingplace'}), |
| 272 |
}; |
292 |
); |
| 273 |
foreach(qw( |
293 |
foreach (@row) { |
| 274 |
contractname author title publishercode collectiontitle notes |
|
|
| 275 |
deliveryplace billingplace |
| 276 |
) ) { |
| 277 |
# Double the quotes to not be interpreted as a field end |
294 |
# Double the quotes to not be interpreted as a field end |
| 278 |
$row->{$_} =~ s/"/""/g if $row->{$_}; |
295 |
$_ =~ s/"/""/g; |
| 279 |
} |
296 |
} |
| 280 |
push @rows, $row; |
297 |
push @rows, \@row; |
| 281 |
} |
298 |
} |
| 282 |
|
299 |
|
| 283 |
@rows = sort { |
300 |
@rows = sort { |
| 284 |
if(defined $a->{publishercode} and defined $b->{publishercode}) { |
301 |
if(defined $a->[7] and defined $b->[7]) { |
| 285 |
$a->{publishercode} cmp $b->{publishercode}; |
302 |
$a->[7] cmp $b->[7]; |
| 286 |
} |
303 |
} |
| 287 |
} @rows; |
304 |
} @rows; |
|
|
305 |
foreach my $row (@rows) { |
| 306 |
$csv->combine(@$row); |
| 307 |
$output .= $csv->string . "\n"; |
| 308 |
} |
| 288 |
|
309 |
|
| 289 |
$template->param(rows => \@rows); |
310 |
return $output; |
| 290 |
|
|
|
| 291 |
return $template->output; |
| 292 |
} |
311 |
} |
| 293 |
|
312 |
|
| 294 |
|
313 |
|