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 |
|
313 |
my $row = { |
314 |
clientnumber => $bookseller->{clientnumber}, |
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 |
|
277 |
=head3 CloseBasketgroup |
353 |
=head3 CloseBasketgroup |
278 |
|
354 |
|
279 |
&CloseBasketgroup($basketgroupno); |
355 |
&CloseBasketgroup($basketgroupno); |
Lines 476-483
Returns a reference to all baskets that belong to basketgroup $basketgroupid.
Link Here
|
476 |
|
552 |
|
477 |
sub GetBasketsByBasketgroup { |
553 |
sub GetBasketsByBasketgroup { |
478 |
my $basketgroupid = shift; |
554 |
my $basketgroupid = shift; |
479 |
my $query = "SELECT * FROM aqbasket |
555 |
my $query = qq{ |
480 |
LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?"; |
556 |
SELECT *, aqbasket.booksellerid as booksellerid |
|
|
557 |
FROM aqbasket |
558 |
LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=? |
559 |
}; |
481 |
my $dbh = C4::Context->dbh; |
560 |
my $dbh = C4::Context->dbh; |
482 |
my $sth = $dbh->prepare($query); |
561 |
my $sth = $dbh->prepare($query); |
483 |
$sth->execute($basketgroupid); |
562 |
$sth->execute($basketgroupid); |