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 514-521
Returns a reference to all baskets that belong to basketgroup $basketgroupid.
Link Here
|
514 |
|
589 |
|
515 |
sub GetBasketsByBasketgroup { |
590 |
sub GetBasketsByBasketgroup { |
516 |
my $basketgroupid = shift; |
591 |
my $basketgroupid = shift; |
517 |
my $query = "SELECT * FROM aqbasket |
592 |
my $query = qq{ |
518 |
LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?"; |
593 |
SELECT *, aqbasket.booksellerid as booksellerid |
|
|
594 |
FROM aqbasket |
595 |
LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=? |
596 |
}; |
519 |
my $dbh = C4::Context->dbh; |
597 |
my $dbh = C4::Context->dbh; |
520 |
my $sth = $dbh->prepare($query); |
598 |
my $sth = $dbh->prepare($query); |
521 |
$sth->execute($basketgroupid); |
599 |
$sth->execute($basketgroupid); |