1 package Koha::pdfformat::layout2pagesde;
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.
27 use Koha::Number::Price;
28 use Koha::DateUtils qw( dt_from_string output_pref );
31 our (@ISA, @EXPORT_OK);
35 @EXPORT_OK = qw(printpdf);
39 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
40 #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.
41 use constant mm => 25.4 / 72;
42 use constant in => 1 / 72;
47 my ($height, $width) = (297, 210);
51 my ($pdf, $basketgroup, $baskets, $orders) = @_;
53 my $cur_format = C4::Context->preference("CurrencyFormat");
55 $pdf->mediabox($height/mm, $width/mm);
56 my $page = $pdf->page();
58 my $pdftable = PDF::Table->new();
62 my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.');
63 for my $bkey (@keys) {
64 push(@$arrbasket, $bkey);
66 push(@$abaskets, $arrbasket);
69 for my $basket (@$baskets){
70 for my $line (@{$orders->{$basket->{basketno}}}) {
73 if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
74 $titleinfo = $line->{title} . " / " . $line->{author} .
75 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
76 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
77 ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) .
78 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
79 ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') .
80 ( $line->{publicationyear} ? ', '. $line->{publicationyear} : '');
82 else { # MARC21, NORMARC
83 $titleinfo = $line->{title} . " " . $line->{author} .
84 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
85 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
86 ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) .
87 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
88 ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') .
89 ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : '');
93 $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferantennotiz : ". $line->{order_vendornote} : '' ),
95 Koha::Number::Price->new( $line->{rrp_tax_included} )->format,
96 Koha::Number::Price->new( $line->{discount} )->format . '%',
97 Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%',
98 Koha::Number::Price->new( $line->{total_tax_excluded} )->format,
99 Koha::Number::Price->new( $line->{total_tax_included} )->format,
101 push(@$abaskets, $arrbasket);
105 $pdftable->table($pdf, $page, $abaskets,
107 w => ($width - 20)/mm,
114 background_color_odd => "lightgray",
115 font => $pdf->corefont("Times", -encoding => "utf8"),
118 font => $pdf->corefont("Times", -encoding => "utf8"),
124 { justify => 'left' },
126 { justify => 'right' },
127 { justify => 'right' },
128 { justify => 'right' },
129 { justify => 'right' },
130 { justify => 'right' },
131 { justify => 'right' },
135 $pdf->mediabox($width/mm, $height/mm);
139 my ($pdf, $basketgroup, $bookseller) = @_;
142 my $libraryname = C4::Context->preference("LibraryName");
143 my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} );
144 my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} );
145 my $freedeliveryplace = $basketgroup->{freedeliveryplace};
149 # open 1st page (with the header)
150 my $page = $pdf->openpage(1);
153 my $text = $page->text;
155 # print the libraryname in the header
156 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
157 $text->translate(30/mm, ($height-28.5)/mm);
158 $text->text($libraryname);
160 # print order info, on the default PDF
161 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm );
162 $text->translate(100/mm, ($height-5-48)/mm);
163 $text->text($basketgroup->{'id'});
166 my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
167 $text->translate(130/mm, ($height-5-48)/mm);
170 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
172 # print billing infos
173 $text->translate(100/mm, ($height-86)/mm);
174 $text->text($libraryname);
175 $text->translate(100/mm, ($height-97)/mm);
176 $text->text($billing_library->branchname);
177 $text->translate(100/mm, ($height-108.5)/mm);
178 $text->text($billing_library->branchphone);
179 $text->translate(100/mm, ($height-115.5)/mm);
180 $text->text($billing_library->branchfax);
181 $text->translate(100/mm, ($height-122.5)/mm);
182 $text->text($billing_library->branchaddress1);
183 $text->translate(100/mm, ($height-127.5)/mm);
184 $text->text($billing_library->branchaddress2);
185 $text->translate(100/mm, ($height-132.5)/mm);
186 $text->text($billing_library->branchaddress3);
187 $text->translate(100/mm, ($height-137.5)/mm);
188 $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry));
189 $text->translate(100/mm, ($height-147.5)/mm);
190 $text->text($billing_library->branchemail);
193 $text->translate(100/mm, ($height-145.5)/mm);
194 $text->text($subject);
196 # print bookseller infos
197 $text->translate(100/mm, ($height-180)/mm);
198 $text->text($bookseller->name);
199 $text->translate(100/mm, ($height-185)/mm);
200 $text->text($bookseller->postal);
201 $text->translate(100/mm, ($height-190)/mm);
202 $text->text($bookseller->address1);
203 $text->translate(100/mm, ($height-195)/mm);
204 $text->text($bookseller->address2);
205 $text->translate(100/mm, ($height-200)/mm);
206 $text->text($bookseller->address3);
207 $text->translate(100/mm, ($height-205)/mm);
208 $text->text($bookseller->accountnumber);
210 # print delivery infos
211 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
212 $text->translate(50/mm, ($height-237)/mm);
213 if ($freedeliveryplace) {
215 my @fdp = split('\n', $freedeliveryplace);
218 $text->translate( 50 / mm, ( $height - $start ) / mm );
222 $text->text( $delivery_library->branchaddress1 );
223 $text->translate( 50 / mm, ( $height - 242 ) / mm );
224 $text->text( $delivery_library->branchaddress2 );
225 $text->translate( 50 / mm, ( $height - 247 ) / mm );
226 $text->text( $delivery_library->branchaddress3 );
227 $text->translate( 50 / mm, ( $height - 252 ) / mm );
228 $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) );
230 $text->translate(50/mm, ($height-262)/mm);
231 $text->text($basketgroup->{deliverycomment});
236 for ( 1..$pdf->pages ) {
237 my $page = $pdf->openpage($_);
238 my $text = $page->text;
239 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
240 $text->translate(10/mm, 10/mm);
241 $text->text("Seite $_ / ".$pdf->pages);
246 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
247 # open the default PDF that will be used for base (1st page already filled)
248 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesde.pdf';
249 my $pdf = PDF::API2->open($pdf_template);
250 $pdf->pageLabel( 0, {
252 } ); # start with roman numbering
253 # fill the 1st page (basketgroup information)
254 printhead($pdf, $basketgroup, $bookseller);
255 # fill other pages (orders)
256 printorders($pdf, $basketgroup, $baskets, $orders);
257 # print something on each page (usually the footer, but you could also put a header
259 return $pdf->stringify;