Bug 7267: Add account number to German PDF template
[koha.git] / acqui / pdfformat / layout2pagesde.pm
blob8fa15f4168bbdd06822850d1d4799356ed2e5ea7
1 #!/usr/bin/perl
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
13 # version.
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::layout2pagesde;
25 use vars qw($VERSION @ISA @EXPORT);
26 use Number::Format qw(format_price);
27 use MIME::Base64;
28 use strict;
29 use warnings;
30 use utf8;
32 use C4::Branch qw(GetBranchDetail);
34 BEGIN {
35 use Exporter ();
36 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
37 # set the version for version checking
38 $VERSION = 1.00;
39 @ISA = qw(Exporter);
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;
48 use constant pt => 1;
50 use PDF::API2;
51 #A4 paper specs
52 my ($height, $width) = (297, 210);
53 use PDF::Table;
55 sub printorders {
56 my ($pdf, $basketgroup, $baskets, $orders) = @_;
58 my $cur_format = C4::Context->preference("CurrencyFormat");
59 my $num;
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();
83 my $abaskets;
84 my $arrbasket;
85 my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.');
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}}}) {
93 $arrbasket = undef;
94 push( @$arrbasket,
95 $basket->{basketno},
96 $line->{title} . " / " . $line->{author} . ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . ( $line->{en} ? " EN: " . $line->{en} : '' ) . ", " . $line->{itemtype} . ( $line->{publishercode} ? 'Verlag:'. $line->{publishercode} : ""),
97 $line->{quantity},
98 $num->format_price($line->{rrpgsti}),
99 $num->format_price($line->{discount}).'%',
100 $num->format_price($line->{gstrate} * 100).'%',
101 $num->format_price($line->{totalgste}),
102 $num->format_price($line->{totalgsti}),
104 push(@$abaskets, $arrbasket);
108 $pdftable->table($pdf, $page, $abaskets,
109 x => 10/mm,
110 w => ($width - 20)/mm,
111 start_y => 285/mm,
112 next_y => 285/mm,
113 start_h => 260/mm,
114 next_h => 260/mm,
115 padding => 5,
116 padding_right => 5,
117 background_color_odd => "lightgray",
118 font => $pdf->corefont("Times", -encoding => "utf8"),
119 font_size => 3/mm,
120 header_props => {
121 font => $pdf->corefont("Times", -encoding => "utf8"),
122 font_size => 10,
123 bg_color => 'gray',
124 repeat => 1,
126 column_props => [
127 { justify => 'left' },
128 { min_w => 90/mm },
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);
141 sub printhead {
142 my ($pdf, $basketgroup, $bookseller) = @_;
144 # get library name
145 my $libraryname = C4::Context->preference("LibraryName");
146 # get branch details
147 my $billingdetails = GetBranchDetail( $basketgroup->{billingplace} );
148 my $deliverydetails = GetBranchDetail( $basketgroup->{deliveryplace} );
149 my $freedeliveryplace = $basketgroup->{freedeliveryplace};
150 # get the subject
151 my $subject;
153 # open 1st page (with the header)
154 my $page = $pdf->openpage(1);
156 # create a text
157 my $text = $page->text;
159 # print the libraryname in the header
160 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
161 $text->translate(30/mm, ($height-28.5)/mm);
162 $text->text($libraryname);
164 # print order info, on the default PDF
165 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm );
166 $text->translate(100/mm, ($height-5-48)/mm);
167 $text->text($basketgroup->{'id'});
169 # print the date
170 my $today = C4::Dates->today();
171 $text->translate(130/mm, ($height-5-48)/mm);
172 $text->text($today);
174 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
176 # print billing infos
177 $text->translate(100/mm, ($height-86)/mm);
178 $text->text($libraryname);
179 $text->translate(100/mm, ($height-97)/mm);
180 $text->text($billingdetails->{branchname});
181 $text->translate(100/mm, ($height-108.5)/mm);
182 $text->text($billingdetails->{branchphone});
183 $text->translate(100/mm, ($height-115.5)/mm);
184 $text->text($billingdetails->{branchfax});
185 $text->translate(100/mm, ($height-122.5)/mm);
186 $text->text($billingdetails->{branchaddress1});
187 $text->translate(100/mm, ($height-127.5)/mm);
188 $text->text($billingdetails->{branchaddress2});
189 $text->translate(100/mm, ($height-132.5)/mm);
190 $text->text($billingdetails->{branchaddress3});
191 $text->translate(100/mm, ($height-137.5)/mm);
192 $text->text(join(' ', $billingdetails->{branchzip}, $billingdetails->{branchcity}, $billingdetails->{branchcountry}));
193 $text->translate(100/mm, ($height-147.5)/mm);
194 $text->text($billingdetails->{branchemail});
196 # print subject
197 $text->translate(100/mm, ($height-145.5)/mm);
198 $text->text($subject);
200 # print bookseller infos
201 $text->translate(100/mm, ($height-180)/mm);
202 $text->text($bookseller->{name});
203 $text->translate(100/mm, ($height-185)/mm);
204 $text->text($bookseller->{postal});
205 $text->translate(100/mm, ($height-190)/mm);
206 $text->text($bookseller->{address1});
207 $text->translate(100/mm, ($height-195)/mm);
208 $text->text($bookseller->{address2});
209 $text->translate(100/mm, ($height-200)/mm);
210 $text->text($bookseller->{address3});
211 $text->translate(100/mm, ($height-205)/mm);
212 $text->text($bookseller->{accountnumber});
214 # print delivery infos
215 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
216 $text->translate(50/mm, ($height-237)/mm);
217 if ($freedeliveryplace) {
218 my $start = 242;
219 my @fdp = split('\n', $freedeliveryplace);
220 foreach (@fdp) {
221 $text->text($_);
222 $text->translate( 50 / mm, ( $height - $start ) / mm );
223 $start += 5;
225 } else {
226 $text->text( $deliverydetails->{branchaddress1} );
227 $text->translate( 50 / mm, ( $height - 242 ) / mm );
228 $text->text( $deliverydetails->{branchaddress2} );
229 $text->translate( 50 / mm, ( $height - 247 ) / mm );
230 $text->text( $deliverydetails->{branchaddress3} );
231 $text->translate( 50 / mm, ( $height - 252 ) / mm );
232 $text->text( join( ' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry} ) );
234 $text->translate(50/mm, ($height-262)/mm);
235 $text->text($basketgroup->{deliverycomment});
238 sub printfooters {
239 my $pdf = shift;
240 for ( 1..$pdf->pages ) {
241 my $page = $pdf->openpage($_);
242 my $text = $page->text;
243 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
244 $text->translate(10/mm, 10/mm);
245 $text->text("Seite $_ / ".$pdf->pages);
249 sub printpdf {
250 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
251 # open the default PDF that will be used for base (1st page already filled)
252 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesde.pdf';
253 my $pdf = PDF::API2->open($pdf_template);
254 $pdf->pageLabel( 0, {
255 -style => 'roman',
256 } ); # start with roman numbering
257 # fill the 1st page (basketgroup information)
258 printhead($pdf, $basketgroup, $bookseller);
259 # fill other pages (orders)
260 printorders($pdf, $basketgroup, $baskets, $orders);
261 # print something on each page (usually the footer, but you could also put a header
262 printfooters($pdf);
263 return $pdf->stringify;