3 #example script to print a basketgroup
4 #written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com
6 # Copyright 2008-2009 BibLibre SARL
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub.
24 package pdfformat
::layout2pagesde
;
25 use vars
qw($VERSION @ISA @EXPORT);
31 use C4::Branch qw(GetBranchDetail);
33 use Koha
::Number
::Price
;
37 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
38 # set the version for version checking
41 @EXPORT = qw(printpdf);
45 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
46 #The constants exported tranform that into PostScript points (/mm for milimeter, /in for inch, pt is postscript point, and as so is there only to show what is happening.
47 use constant mm
=> 25.4 / 72;
48 use constant
in => 1 / 72;
53 my ($height, $width) = (297, 210);
57 my ($pdf, $basketgroup, $baskets, $orders) = @_;
59 my $cur_format = C4
::Context
->preference("CurrencyFormat");
61 $pdf->mediabox($height/mm, $width/mm);
62 my $page = $pdf->page();
64 my $pdftable = new PDF
::Table
();
68 my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.');
69 for my $bkey (@keys) {
70 push(@
$arrbasket, $bkey);
72 push(@
$abaskets, $arrbasket);
75 for my $basket (@
$baskets){
76 for my $line (@
{$orders->{$basket->{basketno
}}}) {
79 if ( C4
::Context
->preference("marcflavour") eq 'UNIMARC' ) {
80 $titleinfo = $line->{title
} . " / " . $line->{author
} .
81 ( $line->{isbn
} ?
" ISBN: " . $line->{isbn
} : '' ) .
82 ( $line->{en
} ?
" EN: " . $line->{en
} : '' ) .
83 ( $line->{itemtype
} ?
", " . $line->{itemtype
} : '' ) .
84 ( $line->{edition
} ?
", " . $line->{edition
} : '' ) .
85 ( $line->{publishercode
} ?
' Verlag: '. $line->{publishercode
} : '') .
86 ( $line->{publicationyear
} ?
', '. $line->{publicationyear
} : '');
88 else { # MARC21, NORMARC
89 $titleinfo = $line->{title
} . " " . $line->{author
} .
90 ( $line->{isbn
} ?
" ISBN: " . $line->{isbn
} : '' ) .
91 ( $line->{en
} ?
" EN: " . $line->{en
} : '' ) .
92 ( $line->{itemtype
} ?
" " . $line->{itemtype
} : '' ) .
93 ( $line->{edition
} ?
", " . $line->{edition
} : '' ) .
94 ( $line->{publishercode
} ?
' Verlag: '. $line->{publishercode
} : '') .
95 ( $line->{copyrightdate
} ?
' '. $line->{copyrightdate
} : '');
99 $titleinfo. ($line->{order_vendornote
} ?
"\n----------------\nLieferantennotiz : ". $line->{order_vendornote
} : '' ), $line->{quantity
},
101 Koha
::Number
::Price
->new( $line->{rrpgsti
} )->format,
102 Koha
::Number
::Price
->new( $line->{discount
} )->format . '%',
103 Koha
::Number
::Price
->new( $line->{gstrate
} * 100 )->format . '%',
104 Koha
::Number
::Price
->new( $line->{totalgste
} )->format,
105 Koha
::Number
::Price
->new( $line->{totalgsti
} )->format,
107 push(@
$abaskets, $arrbasket);
111 $pdftable->table($pdf, $page, $abaskets,
113 w
=> ($width - 20)/mm
,
120 background_color_odd
=> "lightgray",
121 font
=> $pdf->corefont("Times", -encoding
=> "utf8"),
124 font
=> $pdf->corefont("Times", -encoding
=> "utf8"),
130 { justify
=> 'left' },
132 { justify
=> 'right' },
133 { justify
=> 'right' },
134 { justify
=> 'right' },
135 { justify
=> 'right' },
136 { justify
=> 'right' },
137 { justify
=> 'right' },
141 $pdf->mediabox($width/mm, $height/mm);
145 my ($pdf, $basketgroup, $bookseller) = @_;
148 my $libraryname = C4
::Context
->preference("LibraryName");
150 my $billingdetails = GetBranchDetail
( $basketgroup->{billingplace
} );
151 my $deliverydetails = GetBranchDetail
( $basketgroup->{deliveryplace
} );
152 my $freedeliveryplace = $basketgroup->{freedeliveryplace
};
156 # open 1st page (with the header)
157 my $page = $pdf->openpage(1);
160 my $text = $page->text;
162 # print the libraryname in the header
163 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 6/mm
);
164 $text->translate(30/mm, ($height-28.5)/mm);
165 $text->text($libraryname);
167 # print order info, on the default PDF
168 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 8/mm
);
169 $text->translate(100/mm, ($height-5-48)/mm);
170 $text->text($basketgroup->{'id'});
173 my $today = C4
::Dates
->today();
174 $text->translate(130/mm, ($height-5-48)/mm);
177 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 4/mm
);
179 # print billing infos
180 $text->translate(100/mm, ($height-86)/mm);
181 $text->text($libraryname);
182 $text->translate(100/mm, ($height-97)/mm);
183 $text->text($billingdetails->{branchname
});
184 $text->translate(100/mm, ($height-108.5)/mm);
185 $text->text($billingdetails->{branchphone
});
186 $text->translate(100/mm, ($height-115.5)/mm);
187 $text->text($billingdetails->{branchfax
});
188 $text->translate(100/mm, ($height-122.5)/mm);
189 $text->text($billingdetails->{branchaddress1
});
190 $text->translate(100/mm, ($height-127.5)/mm);
191 $text->text($billingdetails->{branchaddress2
});
192 $text->translate(100/mm, ($height-132.5)/mm);
193 $text->text($billingdetails->{branchaddress3
});
194 $text->translate(100/mm, ($height-137.5)/mm);
195 $text->text(join(' ', $billingdetails->{branchzip
}, $billingdetails->{branchcity
}, $billingdetails->{branchcountry
}));
196 $text->translate(100/mm, ($height-147.5)/mm);
197 $text->text($billingdetails->{branchemail
});
200 $text->translate(100/mm, ($height-145.5)/mm);
201 $text->text($subject);
203 # print bookseller infos
204 $text->translate(100/mm, ($height-180)/mm);
205 $text->text($bookseller->{name
});
206 $text->translate(100/mm, ($height-185)/mm);
207 $text->text($bookseller->{postal
});
208 $text->translate(100/mm, ($height-190)/mm);
209 $text->text($bookseller->{address1
});
210 $text->translate(100/mm, ($height-195)/mm);
211 $text->text($bookseller->{address2
});
212 $text->translate(100/mm, ($height-200)/mm);
213 $text->text($bookseller->{address3
});
214 $text->translate(100/mm, ($height-205)/mm);
215 $text->text($bookseller->{accountnumber
});
217 # print delivery infos
218 $text->font( $pdf->corefont("Times-Bold", -encoding
=> "utf8"), 4/mm
);
219 $text->translate(50/mm, ($height-237)/mm);
220 if ($freedeliveryplace) {
222 my @fdp = split('\n', $freedeliveryplace);
225 $text->translate( 50 / mm, ( $height - $start ) / mm
);
229 $text->text( $deliverydetails->{branchaddress1
} );
230 $text->translate( 50 / mm, ( $height - 242 ) / mm
);
231 $text->text( $deliverydetails->{branchaddress2
} );
232 $text->translate( 50 / mm, ( $height - 247 ) / mm
);
233 $text->text( $deliverydetails->{branchaddress3
} );
234 $text->translate( 50 / mm, ( $height - 252 ) / mm
);
235 $text->text( join( ' ', $deliverydetails->{branchzip
}, $deliverydetails->{branchcity
}, $deliverydetails->{branchcountry
} ) );
237 $text->translate(50/mm, ($height-262)/mm);
238 $text->text($basketgroup->{deliverycomment
});
243 for ( 1..$pdf->pages ) {
244 my $page = $pdf->openpage($_);
245 my $text = $page->text;
246 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 3/mm
);
247 $text->translate(10/mm, 10/mm);
248 $text->text("Seite $_ / ".$pdf->pages);
253 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
254 # open the default PDF that will be used for base (1st page already filled)
255 my $pdf_template = C4
::Context
->config('intrahtdocs') . '/' . C4
::Context
->preference('template') . '/pdf/layout2pagesde.pdf';
256 my $pdf = PDF
::API2
->open($pdf_template);
257 $pdf->pageLabel( 0, {
259 } ); # start with roman numbering
260 # fill the 1st page (basketgroup information)
261 printhead
($pdf, $basketgroup, $bookseller);
262 # fill other pages (orders)
263 printorders
($pdf, $basketgroup, $baskets, $orders);
264 # print something on each page (usually the footer, but you could also put a header
266 return $pdf->stringify;