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
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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(@ISA @EXPORT);
30 use Koha::Number::Price;
36 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
38 @EXPORT = qw(printpdf);
42 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
43 #The constants exported transform 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.
44 use constant mm => 25.4 / 72;
45 use constant in => 1 / 72;
50 my ($height, $width) = (297, 210);
54 my ($pdf, $basketgroup, $baskets, $orders) = @_;
56 my $cur_format = C4::Context->preference("CurrencyFormat");
58 $pdf->mediabox($height/mm, $width/mm);
59 my $page = $pdf->page();
61 my $pdftable = new PDF::Table();
65 my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.');
66 for my $bkey (@keys) {
67 push(@$arrbasket, $bkey);
69 push(@$abaskets, $arrbasket);
72 for my $basket (@$baskets){
73 for my $line (@{$orders->{$basket->{basketno}}}) {
76 if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
77 $titleinfo = $line->{title} . " / " . $line->{author} .
78 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
79 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
80 ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) .
81 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
82 ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') .
83 ( $line->{publicationyear} ? ', '. $line->{publicationyear} : '');
85 else { # MARC21, NORMARC
86 $titleinfo = $line->{title} . " " . $line->{author} .
87 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
88 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
89 ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) .
90 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
91 ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') .
92 ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : '');
96 $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferantennotiz : ". $line->{order_vendornote} : '' ), $line->{quantity},
98 Koha::Number::Price->new( $line->{rrp_tax_included} )->format,
99 Koha::Number::Price->new( $line->{discount} )->format . '%',
100 Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%',
101 Koha::Number::Price->new( $line->{total_tax_excluded} )->format,
102 Koha::Number::Price->new( $line->{total_tax_included} )->format,
104 push(@$abaskets, $arrbasket);
108 $pdftable->table($pdf, $page, $abaskets,
110 w => ($width - 20)/mm,
117 background_color_odd => "lightgray",
118 font => $pdf->corefont("Times", -encoding => "utf8"),
121 font => $pdf->corefont("Times", -encoding => "utf8"),
127 { justify => 'left' },
129 { justify => 'right' },
130 { justify => 'right' },
131 { justify => 'right' },
132 { justify => 'right' },
133 { justify => 'right' },
134 { justify => 'right' },
138 $pdf->mediabox($width/mm, $height/mm);
142 my ($pdf, $basketgroup, $bookseller) = @_;
145 my $libraryname = C4::Context->preference("LibraryName");
146 my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} );
147 my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} );
148 my $freedeliveryplace = $basketgroup->{freedeliveryplace};
152 # open 1st page (with the header)
153 my $page = $pdf->openpage(1);
156 my $text = $page->text;
158 # print the libraryname in the header
159 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
160 $text->translate(30/mm, ($height-28.5)/mm);
161 $text->text($libraryname);
163 # print order info, on the default PDF
164 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm );
165 $text->translate(100/mm, ($height-5-48)/mm);
166 $text->text($basketgroup->{'id'});
169 my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
170 $text->translate(130/mm, ($height-5-48)/mm);
173 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
175 # print billing infos
176 $text->translate(100/mm, ($height-86)/mm);
177 $text->text($libraryname);
178 $text->translate(100/mm, ($height-97)/mm);
179 $text->text($billing_library->branchname);
180 $text->translate(100/mm, ($height-108.5)/mm);
181 $text->text($billing_library->branchphone);
182 $text->translate(100/mm, ($height-115.5)/mm);
183 $text->text($billing_library->branchfax);
184 $text->translate(100/mm, ($height-122.5)/mm);
185 $text->text($billing_library->branchaddress1);
186 $text->translate(100/mm, ($height-127.5)/mm);
187 $text->text($billing_library->branchaddress2);
188 $text->translate(100/mm, ($height-132.5)/mm);
189 $text->text($billing_library->branchaddress3);
190 $text->translate(100/mm, ($height-137.5)/mm);
191 $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry));
192 $text->translate(100/mm, ($height-147.5)/mm);
193 $text->text($billing_library->branchemail);
196 $text->translate(100/mm, ($height-145.5)/mm);
197 $text->text($subject);
199 # print bookseller infos
200 $text->translate(100/mm, ($height-180)/mm);
201 $text->text($bookseller->name);
202 $text->translate(100/mm, ($height-185)/mm);
203 $text->text($bookseller->postal);
204 $text->translate(100/mm, ($height-190)/mm);
205 $text->text($bookseller->address1);
206 $text->translate(100/mm, ($height-195)/mm);
207 $text->text($bookseller->address2);
208 $text->translate(100/mm, ($height-200)/mm);
209 $text->text($bookseller->address3);
210 $text->translate(100/mm, ($height-205)/mm);
211 $text->text($bookseller->accountnumber);
213 # print delivery infos
214 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
215 $text->translate(50/mm, ($height-237)/mm);
216 if ($freedeliveryplace) {
218 my @fdp = split('\n', $freedeliveryplace);
221 $text->translate( 50 / mm, ( $height - $start ) / mm );
225 $text->text( $delivery_library->branchaddress1 );
226 $text->translate( 50 / mm, ( $height - 242 ) / mm );
227 $text->text( $delivery_library->branchaddress2 );
228 $text->translate( 50 / mm, ( $height - 247 ) / mm );
229 $text->text( $delivery_library->branchaddress3 );
230 $text->translate( 50 / mm, ( $height - 252 ) / mm );
231 $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) );
233 $text->translate(50/mm, ($height-262)/mm);
234 $text->text($basketgroup->{deliverycomment});
239 for ( 1..$pdf->pages ) {
240 my $page = $pdf->openpage($_);
241 my $text = $page->text;
242 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
243 $text->translate(10/mm, 10/mm);
244 $text->text("Seite $_ / ".$pdf->pages);
249 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
250 # open the default PDF that will be used for base (1st page already filled)
251 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesde.pdf';
252 my $pdf = PDF::API2->open($pdf_template);
253 $pdf->pageLabel( 0, {
255 } ); # start with roman numbering
256 # fill the 1st page (basketgroup information)
257 printhead($pdf, $basketgroup, $bookseller);
258 # fill other pages (orders)
259 printorders($pdf, $basketgroup, $baskets, $orders);
260 # print something on each page (usually the footer, but you could also put a header
262 return $pdf->stringify;