|
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); |