Bug 14928: Remove C4::Dates from files acqui/pdfformat/layout*.pm
[koha.git] / acqui / pdfformat / layout2pagesde.pm
blob5df84d3df9cda9eaef2fe81f93f5709f46f35690
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
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::layout2pagesde;
25 use vars qw($VERSION @ISA @EXPORT);
26 use MIME::Base64;
27 use strict;
28 use warnings;
29 use utf8;
31 use C4::Branch qw(GetBranchDetail);
33 use Koha::Number::Price;
34 use Koha::DateUtils;
36 BEGIN {
37 use Exporter ();
38 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
39 # set the version for version checking
40 $VERSION = 1.00;
41 @ISA = qw(Exporter);
42 @EXPORT = qw(printpdf);
46 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
47 #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.
48 use constant mm => 25.4 / 72;
49 use constant in => 1 / 72;
50 use constant pt => 1;
52 use PDF::API2;
53 #A4 paper specs
54 my ($height, $width) = (297, 210);
55 use PDF::Table;
57 sub printorders {
58 my ($pdf, $basketgroup, $baskets, $orders) = @_;
60 my $cur_format = C4::Context->preference("CurrencyFormat");
62 $pdf->mediabox($height/mm, $width/mm);
63 my $page = $pdf->page();
65 my $pdftable = new PDF::Table();
67 my $abaskets;
68 my $arrbasket;
69 my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.');
70 for my $bkey (@keys) {
71 push(@$arrbasket, $bkey);
73 push(@$abaskets, $arrbasket);
75 my $titleinfo;
76 for my $basket (@$baskets){
77 for my $line (@{$orders->{$basket->{basketno}}}) {
78 $arrbasket = undef;
79 $titleinfo = "";
80 if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
81 $titleinfo = $line->{title} . " / " . $line->{author} .
82 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
83 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
84 ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) .
85 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
86 ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') .
87 ( $line->{publicationyear} ? ', '. $line->{publicationyear} : '');
89 else { # MARC21, NORMARC
90 $titleinfo = $line->{title} . " " . $line->{author} .
91 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
92 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
93 ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) .
94 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
95 ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') .
96 ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : '');
98 push( @$arrbasket,
99 $basket->{basketno},
100 $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferantennotiz : ". $line->{order_vendornote} : '' ), $line->{quantity},
101 $line->{quantity},
102 Koha::Number::Price->new( $line->{rrpgsti} )->format,
103 Koha::Number::Price->new( $line->{discount} )->format . '%',
104 Koha::Number::Price->new( $line->{gstrate} * 100 )->format . '%',
105 Koha::Number::Price->new( $line->{totalgste} )->format,
106 Koha::Number::Price->new( $line->{totalgsti} )->format,
108 push(@$abaskets, $arrbasket);
112 $pdftable->table($pdf, $page, $abaskets,
113 x => 10/mm,
114 w => ($width - 20)/mm,
115 start_y => 285/mm,
116 next_y => 285/mm,
117 start_h => 260/mm,
118 next_h => 260/mm,
119 padding => 5,
120 padding_right => 5,
121 background_color_odd => "lightgray",
122 font => $pdf->corefont("Times", -encoding => "utf8"),
123 font_size => 3/mm,
124 header_props => {
125 font => $pdf->corefont("Times", -encoding => "utf8"),
126 font_size => 10,
127 bg_color => 'gray',
128 repeat => 1,
130 column_props => [
131 { justify => 'left' },
132 { min_w => 90/mm },
133 { justify => 'right' },
134 { justify => 'right' },
135 { justify => 'right' },
136 { justify => 'right' },
137 { justify => 'right' },
138 { justify => 'right' },
142 $pdf->mediabox($width/mm, $height/mm);
145 sub printhead {
146 my ($pdf, $basketgroup, $bookseller) = @_;
148 # get library name
149 my $libraryname = C4::Context->preference("LibraryName");
150 # get branch details
151 my $billingdetails = GetBranchDetail( $basketgroup->{billingplace} );
152 my $deliverydetails = GetBranchDetail( $basketgroup->{deliveryplace} );
153 my $freedeliveryplace = $basketgroup->{freedeliveryplace};
154 # get the subject
155 my $subject;
157 # open 1st page (with the header)
158 my $page = $pdf->openpage(1);
160 # create a text
161 my $text = $page->text;
163 # print the libraryname in the header
164 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
165 $text->translate(30/mm, ($height-28.5)/mm);
166 $text->text($libraryname);
168 # print order info, on the default PDF
169 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm );
170 $text->translate(100/mm, ($height-5-48)/mm);
171 $text->text($basketgroup->{'id'});
173 # print the date
174 my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
175 $text->translate(130/mm, ($height-5-48)/mm);
176 $text->text($today);
178 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
180 # print billing infos
181 $text->translate(100/mm, ($height-86)/mm);
182 $text->text($libraryname);
183 $text->translate(100/mm, ($height-97)/mm);
184 $text->text($billingdetails->{branchname});
185 $text->translate(100/mm, ($height-108.5)/mm);
186 $text->text($billingdetails->{branchphone});
187 $text->translate(100/mm, ($height-115.5)/mm);
188 $text->text($billingdetails->{branchfax});
189 $text->translate(100/mm, ($height-122.5)/mm);
190 $text->text($billingdetails->{branchaddress1});
191 $text->translate(100/mm, ($height-127.5)/mm);
192 $text->text($billingdetails->{branchaddress2});
193 $text->translate(100/mm, ($height-132.5)/mm);
194 $text->text($billingdetails->{branchaddress3});
195 $text->translate(100/mm, ($height-137.5)/mm);
196 $text->text(join(' ', $billingdetails->{branchzip}, $billingdetails->{branchcity}, $billingdetails->{branchcountry}));
197 $text->translate(100/mm, ($height-147.5)/mm);
198 $text->text($billingdetails->{branchemail});
200 # print subject
201 $text->translate(100/mm, ($height-145.5)/mm);
202 $text->text($subject);
204 # print bookseller infos
205 $text->translate(100/mm, ($height-180)/mm);
206 $text->text($bookseller->{name});
207 $text->translate(100/mm, ($height-185)/mm);
208 $text->text($bookseller->{postal});
209 $text->translate(100/mm, ($height-190)/mm);
210 $text->text($bookseller->{address1});
211 $text->translate(100/mm, ($height-195)/mm);
212 $text->text($bookseller->{address2});
213 $text->translate(100/mm, ($height-200)/mm);
214 $text->text($bookseller->{address3});
215 $text->translate(100/mm, ($height-205)/mm);
216 $text->text($bookseller->{accountnumber});
218 # print delivery infos
219 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
220 $text->translate(50/mm, ($height-237)/mm);
221 if ($freedeliveryplace) {
222 my $start = 242;
223 my @fdp = split('\n', $freedeliveryplace);
224 foreach (@fdp) {
225 $text->text($_);
226 $text->translate( 50 / mm, ( $height - $start ) / mm );
227 $start += 5;
229 } else {
230 $text->text( $deliverydetails->{branchaddress1} );
231 $text->translate( 50 / mm, ( $height - 242 ) / mm );
232 $text->text( $deliverydetails->{branchaddress2} );
233 $text->translate( 50 / mm, ( $height - 247 ) / mm );
234 $text->text( $deliverydetails->{branchaddress3} );
235 $text->translate( 50 / mm, ( $height - 252 ) / mm );
236 $text->text( join( ' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry} ) );
238 $text->translate(50/mm, ($height-262)/mm);
239 $text->text($basketgroup->{deliverycomment});
242 sub printfooters {
243 my $pdf = shift;
244 for ( 1..$pdf->pages ) {
245 my $page = $pdf->openpage($_);
246 my $text = $page->text;
247 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
248 $text->translate(10/mm, 10/mm);
249 $text->text("Seite $_ / ".$pdf->pages);
253 sub printpdf {
254 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
255 # open the default PDF that will be used for base (1st page already filled)
256 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesde.pdf';
257 my $pdf = PDF::API2->open($pdf_template);
258 $pdf->pageLabel( 0, {
259 -style => 'roman',
260 } ); # start with roman numbering
261 # fill the 1st page (basketgroup information)
262 printhead($pdf, $basketgroup, $bookseller);
263 # fill other pages (orders)
264 printorders($pdf, $basketgroup, $baskets, $orders);
265 # print something on each page (usually the footer, but you could also put a header
266 printfooters($pdf);
267 return $pdf->stringify;