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
::layout2pages
;
25 use vars
qw(@ISA @EXPORT);
31 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 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.
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 = ('Basket (No.)', 'Document', 'Qty', 'RRP tax inc.', 'Discount', 'GST', 'Total tax exc.', 'Total tax inc.');
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
} ?
' published by '. $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
} ?
' published by '. $line->{publishercode
} : '') .
95 ( $line->{copyrightdate
} ?
' '. $line->{copyrightdate
} : '');
99 $titleinfo. ($line->{order_vendornote
} ?
"\n----------------\nNote for vendor : " . $line->{order_vendornote
} : '' ),
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");
149 my $billing_library = Koha
::Libraries
->find( $basketgroup->{billingplace
} );
150 my $delivery_library = Koha
::Libraries
->find( $basketgroup->{deliveryplace
} );
151 my $freedeliveryplace = $basketgroup->{freedeliveryplace
};
155 # open 1st page (with the header)
156 my $page = $pdf->openpage(1);
159 my $text = $page->text;
161 # print the libraryname in the header
162 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 6/mm
);
163 $text->translate(30/mm, ($height-28.5)/mm);
164 $text->text($libraryname);
166 # print order info, on the default PDF
167 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 8/mm
);
168 $text->translate(100/mm, ($height-5-48)/mm);
169 $text->text($basketgroup->{'id'});
172 my $today = output_pref
({ dt
=> dt_from_string
, dateonly
=> 1 });
173 $text->translate(130/mm, ($height-5-48)/mm);
176 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 4/mm
);
178 # print billing infos
179 $text->translate(100/mm, ($height-86)/mm);
180 $text->text($libraryname);
181 $text->translate(100/mm, ($height-97)/mm);
182 $text->text($billing_library->branchname);
183 $text->translate(100/mm, ($height-108.5)/mm);
184 $text->text($billing_library->branchphone);
185 $text->translate(100/mm, ($height-115.5)/mm);
186 $text->text($billing_library->branchfax);
187 $text->translate(100/mm, ($height-122.5)/mm);
188 $text->text($billing_library->branchaddress1);
189 $text->translate(100/mm, ($height-127.5)/mm);
190 $text->text($billing_library->branchaddress2);
191 $text->translate(100/mm, ($height-132.5)/mm);
192 $text->text($billing_library->branchaddress3);
193 $text->translate(100/mm, ($height-137.5)/mm);
194 $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry));
195 $text->translate(100/mm, ($height-147.5)/mm);
196 $text->text($billing_library->branchemail);
199 $text->translate(100/mm, ($height-145.5)/mm);
200 $text->text($subject);
202 # print bookseller infos
203 $text->translate(100/mm, ($height-180)/mm);
204 $text->text($bookseller->{name
});
205 $text->translate(100/mm, ($height-185)/mm);
206 $text->text($bookseller->{postal
});
207 $text->translate(100/mm, ($height-190)/mm);
208 $text->text($bookseller->{address1
});
209 $text->translate(100/mm, ($height-195)/mm);
210 $text->text($bookseller->{address2
});
211 $text->translate(100/mm, ($height-200)/mm);
212 $text->text($bookseller->{address3
});
213 $text->translate(100/mm, ($height-205)/mm);
214 $text->text($bookseller->{accountnumber
});
216 # print delivery infos
217 $text->font( $pdf->corefont("Times-Bold", -encoding
=> "utf8"), 4/mm
);
218 $text->translate(50/mm, ($height-237)/mm);
219 if ($freedeliveryplace) {
221 my @fdp = split('\n', $freedeliveryplace);
224 $text->translate( 50 / mm, ( $height - $start ) / mm
);
228 $text->text( $delivery_library->branchaddress1 );
229 $text->translate( 50 / mm, ( $height - 242 ) / mm
);
230 $text->text( $delivery_library->branchaddress2 );
231 $text->translate( 50 / mm, ( $height - 247 ) / mm
);
232 $text->text( $delivery_library->branchaddress3 );
233 $text->translate( 50 / mm, ( $height - 252 ) / mm
);
234 $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) );
236 $text->translate(50/mm, ($height-262)/mm);
237 $text->text($basketgroup->{deliverycomment
});
242 for ( 1..$pdf->pages ) {
243 my $page = $pdf->openpage($_);
244 my $text = $page->text;
245 $text->font( $pdf->corefont("Times", -encoding
=> "utf8"), 3/mm
);
246 $text->translate(10/mm, 10/mm);
247 $text->text("Page $_ / ".$pdf->pages);
252 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
253 # open the default PDF that will be used for base (1st page already filled)
254 my $pdf_template = C4
::Context
->config('intrahtdocs') . '/' . C4
::Context
->preference('template') . '/pdf/layout2pages.pdf';
255 my $pdf = PDF
::API2
->open($pdf_template);
256 $pdf->pageLabel( 0, {
258 } ); # start with roman numbering
259 # fill the 1st page (basketgroup information)
260 printhead
($pdf, $basketgroup, $bookseller);
261 # fill other pages (orders)
262 printorders
($pdf, $basketgroup, $baskets, $orders);
263 # print something on each page (usually the footer, but you could also put a header
265 return $pdf->stringify;