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::layout2pages;
25 use vars qw($VERSION @ISA @EXPORT);
26 use Number::Format qw(format_price);
32 use C4::Branch qw(GetBranchDetail);
36 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
37 # set the version for version checking
40 @EXPORT = qw(printpdf);
44 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
45 #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.
46 use constant mm => 25.4 / 72;
47 use constant in => 1 / 72;
52 my ($height, $width) = (297, 210);
56 my ($pdf, $basketgroup, $baskets, $orders) = @_;
58 my $cur_format = C4::Context->preference("CurrencyFormat");
61 if ( $cur_format eq 'FR' ) {
62 $num = new Number::Format(
63 'decimal_fill' => '2',
64 'decimal_point' => ',',
65 'int_curr_symbol' => '',
66 'mon_thousands_sep' => ' ',
67 'thousands_sep' => ' ',
68 'mon_decimal_point' => ','
70 } else { # US by default..
71 $num = new Number::Format(
72 'int_curr_symbol' => '',
73 'mon_thousands_sep' => ',',
74 'mon_decimal_point' => '.'
78 $pdf->mediabox($height/mm, $width/mm);
79 my $page = $pdf->page();
81 my $pdftable = new PDF::Table();
85 my @keys = ('Basket (N°)','Document','Qty','RRT GST Inc.','Discount','Discount price GST Exc.','GST', 'Total GST Inc.');
86 for my $bkey (@keys) {
87 push(@$arrbasket, $bkey);
89 push(@$abaskets, $arrbasket);
91 for my $basket (@$baskets){
92 for my $line (@{$orders->{$basket->{basketno}}}) {
96 @$line[3]." / ".@$line[2].(@$line[0]?" ISBN : ".@$line[0]:'').(@$line[10]?" EN : ".@$line[10]:'').", ".@$line[1].(@$line[4]?' publié par '.@$line[4]:''),
98 $num->format_price(@$line[6]),
99 $num->format_price(@$line[8]).'%',
100 $num->format_price(@$line[7]/(1+@$line[9]/100)),
101 $num->format_price(@$line[9]).'%',
102 $num->format_price($num->round(@$line[7])*@$line[5])
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");
147 my $billingdetails = GetBranchDetail( $basketgroup->{billingplace} );
148 my $deliverydetails = GetBranchDetail( $basketgroup->{deliveryplace} );
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 = C4::Dates->today();
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($billingdetails->{branchname});
180 $text->translate(100/mm, ($height-108.5)/mm);
181 $text->text($billingdetails->{branchphone});
182 $text->translate(100/mm, ($height-115.5)/mm);
183 $text->text($billingdetails->{branchfax});
184 $text->translate(100/mm, ($height-122.5)/mm);
185 $text->text($billingdetails->{branchaddress1});
186 $text->translate(100/mm, ($height-127.5)/mm);
187 $text->text($billingdetails->{branchaddress2});
188 $text->translate(100/mm, ($height-132.5)/mm);
189 $text->text($billingdetails->{branchaddress3});
190 $text->translate(100/mm, ($height-137.5)/mm);
191 $text->text(join(' ', $billingdetails->{branchzip}, $billingdetails->{branchcity}, $billingdetails->{branchcountry}));
192 $text->translate(100/mm, ($height-147.5)/mm);
193 $text->text($billingdetails->{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});
211 # print delivery infos
212 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
213 $text->translate(50/mm, ($height-237)/mm);
214 $text->text($deliverydetails->{branchaddress1});
215 $text->translate(50/mm, ($height-242)/mm);
216 $text->text($deliverydetails->{branchaddress2});
217 $text->translate(50/mm, ($height-247)/mm);
218 $text->text($deliverydetails->{branchaddress3});
219 $text->translate(50/mm, ($height-252)/mm);
220 $text->text(join(' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry}));
221 $text->translate(50/mm, ($height-262)/mm);
222 $text->text($basketgroup->{deliverycomment});
227 for ( 1..$pdf->pages ) {
228 my $page = $pdf->openpage($_);
229 my $text = $page->text;
230 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
231 $text->translate(10/mm, 10/mm);
232 $text->text("Page $_ / ".$pdf->pages);
237 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
238 # open the default PDF that will be used for base (1st page already filled)
239 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pages.pdf';
240 my $pdf = PDF::API2->open($pdf_template);
241 $pdf->pageLabel( 0, {
243 } ); # start with roman numbering
244 # fill the 1st page (basketgroup information)
245 printhead($pdf, $basketgroup, $bookseller);
246 # fill other pages (orders)
247 printorders($pdf, $basketgroup, $baskets, $orders);
248 # print something on each page (usually the footer, but you could also put a header
250 return $pdf->stringify;