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