1 package Koha
::pdfformat
::layout2pages
;
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 use vars
qw(@ISA @EXPORT);
29 use Koha::Number::Price;
35 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
37 @EXPORT = qw(printpdf);
41 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
42 #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.
43 use constant mm
=> 25.4 / 72;
44 use constant
in => 1 / 72;
49 my ($height, $width) = (297, 210);
53 my ($pdf, $basketgroup, $baskets, $orders) = @_;
55 my $cur_format = C4
::Context
->preference("CurrencyFormat");
57 $pdf->mediabox($height/mm, $width/mm);
58 my $page = $pdf->page();
60 my $pdftable = PDF
::Table
->new();
64 my @keys = ('Basket (no.)', 'Document', 'Qty', 'RRP tax inc.', 'Discount', 'Tax', 'Total tax exc.', 'Total tax inc.');
65 for my $bkey (@keys) {
66 push(@
$arrbasket, $bkey);
68 push(@
$abaskets, $arrbasket);
71 for my $basket (@
$baskets){
72 for my $line (@
{$orders->{$basket->{basketno
}}}) {
75 if ( C4
::Context
->preference("marcflavour") eq 'UNIMARC' ) {
76 $titleinfo = $line->{title
} . " / " . $line->{author
} .
77 ( $line->{isbn
} ?
" ISBN: " . $line->{isbn
} : '' ) .
78 ( $line->{en
} ?
" EN: " . $line->{en
} : '' ) .
79 ( $line->{itemtype
} ?
", " . $line->{itemtype
} : '' ) .
80 ( $line->{edition
} ?
", " . $line->{edition
} : '' ) .
81 ( $line->{publishercode
} ?
' published by '. $line->{publishercode
} : '') .
82 ( $line->{publicationyear
} ?
', '. $line->{publicationyear
} : '');
84 else { # MARC21, NORMARC
85 $titleinfo = $line->{title
} . " " . $line->{author
} .
86 ( $line->{isbn
} ?
" ISBN: " . $line->{isbn
} : '' ) .
87 ( $line->{en
} ?
" EN: " . $line->{en
} : '' ) .
88 ( $line->{itemtype
} ?
" " . $line->{itemtype
} : '' ) .
89 ( $line->{edition
} ?
", " . $line->{edition
} : '' ) .
90 ( $line->{publishercode
} ?
' published by '. $line->{publishercode
} : '') .
91 ( $line->{copyrightdate
} ?
' '. $line->{copyrightdate
} : '');
95 $titleinfo. ($line->{order_vendornote
} ?
"\n----------------\nNote for vendor : " . $line->{order_vendornote
} : '' ),
97 Koha
::Number
::Price
->new( $line->{rrp_tax_included
} )->format,
98 Koha
::Number
::Price
->new( $line->{discount
} )->format . '%',
99 Koha
::Number
::Price
->new( $line->{tax_rate
} * 100 )->format . '%',
100 Koha
::Number
::Price
->new( $line->{total_tax_excluded
} )->format,
101 Koha
::Number
::Price
->new( $line->{total_tax_included
} )->format,
103 push(@
$abaskets, $arrbasket);
107 $pdftable->table($pdf, $page, $abaskets,
109 w
=> ($width - 20)/mm
,
116 background_color_odd
=> "lightgray",
117 font
=> $pdf->corefont("Times", -encoding
=> "utf8"),
120 font
=> $pdf->corefont("Times", -encoding
=> "utf8"),
126 { justify
=> 'left' },
128 { justify
=> 'right' },
129 { justify
=> 'right' },
130 { justify
=> 'right' },
131 { justify
=> 'right' },
132 { justify
=> 'right' },
133 { justify
=> 'right' },
137 $pdf->mediabox($width/mm, $height/mm);
141 my ($pdf, $basketgroup, $bookseller) = @_;
144 my $libraryname = C4
::Context
->preference("LibraryName");
145 my $billing_library = Koha
::Libraries
->find( $basketgroup->{billingplace
} );
146 my $delivery_library = Koha
::Libraries
->find( $basketgroup->{deliveryplace
} );
147 my $freedeliveryplace = $basketgroup->{freedeliveryplace
};
151 # open 1st page (with the header)
152 my $page = $pdf->openpage(1);
155 my $text = $page->text;
157 # print the libraryname in the header
158 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 6/mm
);
159 $text->translate(30/mm, ($height-28.5)/mm);
160 $text->text($libraryname);
162 # print order info, on the default PDF
163 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 8/mm
);
164 $text->translate(100/mm, ($height-5-48)/mm);
165 $text->text($basketgroup->{'id'});
168 my $today = output_pref
({ dt
=> dt_from_string
, dateonly
=> 1 });
169 $text->translate(130/mm, ($height-5-48)/mm);
172 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 4/mm
);
174 # print billing infos
175 $text->translate(100/mm, ($height-86)/mm);
176 $text->text($libraryname);
177 $text->translate(100/mm, ($height-97)/mm);
178 $text->text($billing_library->branchname);
179 $text->translate(100/mm, ($height-108.5)/mm);
180 $text->text($billing_library->branchphone);
181 $text->translate(100/mm, ($height-115.5)/mm);
182 $text->text($billing_library->branchfax);
183 $text->translate(100/mm, ($height-122.5)/mm);
184 $text->text($billing_library->branchaddress1);
185 $text->translate(100/mm, ($height-127.5)/mm);
186 $text->text($billing_library->branchaddress2);
187 $text->translate(100/mm, ($height-132.5)/mm);
188 $text->text($billing_library->branchaddress3);
189 $text->translate(100/mm, ($height-137.5)/mm);
190 $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry));
191 $text->translate(100/mm, ($height-147.5)/mm);
192 $text->text($billing_library->branchemail);
195 $text->translate(100/mm, ($height-145.5)/mm);
196 $text->text($subject);
198 # print bookseller infos
199 $text->translate(100/mm, ($height-180)/mm);
200 $text->text($bookseller->name);
201 $text->translate(100/mm, ($height-185)/mm);
202 $text->text($bookseller->postal);
203 $text->translate(100/mm, ($height-190)/mm);
204 $text->text($bookseller->address1);
205 $text->translate(100/mm, ($height-195)/mm);
206 $text->text($bookseller->address2);
207 $text->translate(100/mm, ($height-200)/mm);
208 $text->text($bookseller->address3);
209 $text->translate(100/mm, ($height-205)/mm);
210 $text->text($bookseller->accountnumber);
212 # print delivery infos
213 $text->font( $pdf->corefont("Times-Bold", -encoding
=> "utf8"), 4/mm
);
214 $text->translate(50/mm, ($height-237)/mm);
215 if ($freedeliveryplace) {
217 my @fdp = split('\n', $freedeliveryplace);
220 $text->translate( 50 / mm, ( $height - $start ) / mm
);
224 $text->text( $delivery_library->branchaddress1 );
225 $text->translate( 50 / mm, ( $height - 242 ) / mm
);
226 $text->text( $delivery_library->branchaddress2 );
227 $text->translate( 50 / mm, ( $height - 247 ) / mm
);
228 $text->text( $delivery_library->branchaddress3 );
229 $text->translate( 50 / mm, ( $height - 252 ) / mm
);
230 $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) );
232 $text->translate(50/mm, ($height-262)/mm);
233 $text->text($basketgroup->{deliverycomment
});
238 for ( 1..$pdf->pages ) {
239 my $page = $pdf->openpage($_);
240 my $text = $page->text;
241 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 3/mm
);
242 $text->translate(10/mm, 10/mm);
243 $text->text("Page $_ / ".$pdf->pages);
248 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
249 # open the default PDF that will be used for base (1st page already filled)
250 my $pdf_template = C4
::Context
->config('intrahtdocs') . '/' . C4
::Context
->preference('template') . '/pdf/layout2pages.pdf';
251 my $pdf = PDF
::API2
->open($pdf_template);
252 $pdf->pageLabel( 0, {
254 } ); # start with roman numbering
255 # fill the 1st page (basketgroup information)
256 printhead
($pdf, $basketgroup, $bookseller);
257 # fill other pages (orders)
258 printorders
($pdf, $basketgroup, $baskets, $orders);
259 # print something on each page (usually the footer, but you could also put a header
261 return $pdf->stringify;