+sub printbasketgrouppdf{
+ my ($basketgroupid) = @_;
+
+ my $pdfformat = C4::Context->preference("pdfformat");
+ eval "use $pdfformat" ;
+ warn @_;
+ eval "use C4::Branch";
+
+ my $basketgroup = GetBasketgroup($basketgroupid);
+ my $bookseller = GetBookSellerFromId($basketgroup->{'booksellerid'});
+ my $baskets = GetBasketsByBasketgroup($basketgroupid);
+
+ my %orders;
+ for my $basket (@$baskets) {
+ my @ba_orders;
+ my @ords = &GetOrders($basket->{basketno});
+ for my $ord (@ords) {
+ # ba_order is filled with :
+ # 0 1 2 3 4 5 6 7 8 9
+ #isbn, itemtype, author, title, publishercode, quantity, listprice ecost discount gstrate
+ my @ba_order;
+ if ( $ord->{biblionumber} && $ord->{quantity}> 0 ) {
+ eval "use C4::Biblio";
+ eval "use C4::Koha";
+ my $bib = GetBiblioData($ord->{biblionumber});
+ my $itemtypes = GetItemTypes();
+ if($ord->{isbn}){
+ push(@ba_order, $ord->{isbn});
+ } else {
+ push(@ba_order, undef);
+ }
+ if ($ord->{itemtype}){
+ push(@ba_order, $itemtypes->{$bib->{itemtype}}->{description}) if $bib->{itemtype};
+ } else {
+ push(@ba_order, undef);
+ }
+# } else {
+# push(@ba_order, undef, undef);
+ for my $key (qw/author title publishercode quantity listprice ecost/) {
+ push(@ba_order, $ord->{$key}); #Order lines
+ }
+ push(@ba_order, $bookseller->{discount});
+ push(@ba_order, $bookseller->{gstrate}*100 || C4::Context->preference("gist") || 0);
+ push(@ba_orders, \@ba_order);
+ # Editor Number
+ my $en;
+ if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
+ $en = MARC::Record::new_from_xml($ord->{marcxml},'UTF-8')->subfield('345',"b");
+ } elsif (C4::Context->preference("marcflavour") eq 'MARC21') {
+ $en = MARC::Record::new_from_xml($ord->{marcxml},'UTF-8')->subfield('037',"a");
+ }
+ if($en){
+ push(@ba_order, $en);
+ } else {
+ push(@ba_order, undef);
+ }
+ }
+ }
+ %orders->{$basket->{basketno}}=\@ba_orders;
+ }
+ print $input->header( -type => 'application/pdf', -attachment => 'basketgroup.pdf' );
+ my $branch = GetBranchInfo(GetBranch($input, GetBranches()));
+ $branch = @$branch[0];
+ my $pdf = printpdf($basketgroup, $bookseller, $baskets, $branch, \%orders, $bookseller->{gstrate} || C4::Context->preference("gist")) || die "pdf generation failed";
+ print $pdf;
+ exit;
+}