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