+sub printbasketgrouppdf{
+ my ($basketgroupid) = @_;
+
+ my $pdfformat = C4::Context->preference("OrderPdfFormat");
+ if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages'){
+ eval {
+ eval "require $pdfformat";
+ import $pdfformat;
+ };
+ if ($@){
+ }
+ }
+ else {
+ print $input->header;
+ print $input->start_html; # FIXME Should do a nicer page
+ print "<h1>Invalid PDF Format set</h1>";
+ print "Please go to the systempreferences and set a valid pdfformat";
+ exit;
+ }
+
+ 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 {
+ require C4::Biblio;
+ import C4::Biblio;
+ };
+ if ($@){
+ croak $@;
+ }
+ eval {
+ require C4::Koha;
+ import C4::Koha;
+ };
+ if ($@){
+ croak $@;
+ }
+ my $bib = GetBiblioData($ord->{biblionumber});
+ my $itemtypes = GetItemTypes();
+ if($ord->{isbn}){
+ push(@ba_order, $ord->{isbn});
+ } else {
+ push(@ba_order, undef);
+ }
+ if ($ord->{itemtype} and $bib->{itemtype}){
+ push(@ba_order, $itemtypes->{$bib->{itemtype}}->{description});
+ } 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;
+ my $marcrecord=eval{MARC::Record::new_from_xml( $ord->{marcxml},'UTF-8' )};
+ if ($marcrecord){
+ if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
+ $en = $marcrecord->subfield( '345', "b" );
+ } elsif ( C4::Context->preference("marcflavour") eq 'MARC21' ) {
+ $en = $marcrecord->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->{name} || $basketgroupid ) . '.pdf'
+ );
+ my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->{gstrate} // C4::Context->preference("gist")) || die "pdf generation failed";
+ print $pdf;
+
+}