1 package Koha::pdfformat::layout3pagesfr;
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, 2013 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 3 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, see <http://www.gnu.org/licenses>.
22 #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub.
23 package pdfformat::layout3pagesfr;
24 use vars qw(@ISA @EXPORT);
26 use List::MoreUtils qw/uniq/;
30 use Koha::Number::Price;
36 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
38 @EXPORT = qw(printpdf);
42 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
43 #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.
44 use constant mm => 25.4 / 72;
45 use constant in => 1 / 72;
50 my ($height, $width) = (297, 210);
54 my ($pdf, $basketgroup, $baskets, $orders) = @_;
56 my $cur_format = C4::Context->preference("CurrencyFormat");
58 $pdf->mediabox($height/mm, $width/mm);
60 for my $basket (@$baskets){
61 my $page = $pdf->page();
62 my $billing_library = Koha::Libraries->find( $basket->{billingplace} );
63 my $delivery_library = Koha::Libraries->find( $basket->{deliveryplace} );
65 # print basket header (box)
67 $box->rectxy(($width - 10)/mm, ($height - 5)/mm, 10/mm, ($height - 25)/mm);
72 my $text = $page->text;
73 # add basketgroup number
74 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
75 $text->translate(20/mm, ($height-15)/mm);
76 $text->text("Commande N°".$basketgroup->{'id'}.". Panier N° ".$basket->{basketno}.". ".$basket->{booksellernote});
77 $text->translate(20/mm, ($height-20)/mm);
78 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
79 $text->text( ( $billing_library ? "Facturation à " . $billing_library->branchname : "" )
80 . ( $billing_library and $delivery_library ? " et " : "" )
81 . ( $delivery_library ? "livraison à " . $delivery_library->branchname : "" )
84 my $pdftable = new PDF::Table();
87 my @keys = ('Document', 'Qté', 'Prix', 'Prix net', '% Remise', 'Remise', 'Taux TVA', 'Total HT', 'Total TTC');
88 for my $bkey (@keys) {
89 push(@$arrbasket, $bkey);
91 push(@$abaskets, $arrbasket);
94 foreach my $line (@{$orders->{$basket->{basketno}}}) {
97 if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
98 $titleinfo = $line->{title} . " / " . $line->{author} .
99 ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) .
100 ( $line->{en} ? " EN : " . $line->{en} : '' ) .
101 ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) .
102 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
103 ( $line->{publishercode} ? ' publié par '. $line->{publishercode} : '') .
104 ( $line->{publicationyear} ? ', '. $line->{publicationyear} : '');
106 else { # MARC21, NORMARC
107 $titleinfo = $line->{title} . " " . $line->{author} .
108 ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) .
109 ( $line->{en} ? " EN : " . $line->{en} : '' ) .
110 ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) .
111 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
112 ( $line->{publishercode} ? ' publié par '. $line->{publishercode} : '') .
113 ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : '');
117 $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote pour le fournisseur : ". $line->{order_vendornote} : '' ),
119 Koha::Number::Price->new( $line->{rrp_tax_excluded})->format,
120 Koha::Number::Price->new( $line->{rrp_tax_included})->format,
121 Koha::Number::Price->new( $line->{discount})->format.'%',
122 Koha::Number::Price->new( $line->{rrp_tax_excluded} - $line->{ecost_tax_excluded})->format,
123 Koha::Number::Price->new( $line->{tax_rate} * 100)->format.'%',
124 Koha::Number::Price->new( $line->{total_tax_excluded})->format,
125 Koha::Number::Price->new( $line->{total_tax_included})->format,
127 push(@$abaskets, $arrbasket);
130 $pdftable->table($pdf, $page, $abaskets,
132 w => ($width - 20)/mm,
139 background_color_odd => "lightgray",
140 font => $pdf->corefont("Times", -encoding => "utf8"),
143 font => $pdf->corefont("Times", -encoding => "utf8"),
150 min_w => 85/mm, # Minimum column width.
153 justify => 'right', # One of left|right ,
156 justify => 'right', # One of left|right ,
159 justify => 'right', # One of left|right ,
162 justify => 'right', # One of left|right ,
165 justify => 'right', # One of left|right ,
168 justify => 'right', # One of left|right ,
171 justify => 'right', # One of left|right ,
174 justify => 'right', # One of left|right ,
179 $pdf->mediabox($width/mm, $height/mm);
183 my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_;
186 my $libraryname = C4::Context->preference("LibraryName");
188 my $cur_format = C4::Context->preference("CurrencyFormat");
190 $pdf->mediabox($width/mm, $height/mm);
191 my $page = $pdf->openpage(2);
193 my $text = $page->text;
195 # add basketgroup number
196 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
197 $text->translate(($width-40)/mm, ($height-53)/mm);
198 $text->text("".$basketgroup->{'id'});
199 # print the libraryname in the header
200 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
201 $text->translate(30/mm, ($height-28.5)/mm);
202 $text->text($libraryname);
203 my $pdftable = new PDF::Table();
206 # header of the table
207 my @keys = ('Lot', 'Panier', 'Prix', 'Prix net', 'Taux TVA', 'TVA', 'Remise', 'Total HT', 'Total TTC');
208 for my $bkey (@keys) {
209 push(@$arrbasket, $bkey);
211 my ($grandtotal_rrp_tax_included, $grandtotal_rrp_tax_excluded, $grandtotal_tax_included, $grandtotal_tax_excluded, $grandtotaltax_value, $grandtotaldiscount);
212 # calculate each basket total
213 push(@$abaskets, $arrbasket);
214 for my $basket (@$hbaskets) {
217 my ($total_rrp_tax_excluded, $total_rrp_tax_included, $total_tax_excluded, $total_tax_included, $totaltax_value, $totaldiscount);
218 my $ords = $orders->{$basket->{basketno}};
219 my $ordlength = @$ords;
220 foreach my $ord (@$ords) {
221 $total_tax_excluded += $ord->{total_tax_excluded};
222 $total_tax_included += $ord->{total_tax_included};
223 $totaltax_value += $ord->{tax_value};
224 $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity};
225 $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity};
226 $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity};
227 push @gst, $ord->{tax_rate};
229 @gst = uniq map { $_ * 100 } @gst;
230 $grandtotal_rrp_tax_excluded += $total_rrp_tax_excluded;
231 $grandtotal_rrp_tax_included += $total_rrp_tax_included;
232 $grandtotal_tax_included += $total_tax_included;
233 $grandtotal_tax_excluded += $total_tax_excluded;
234 $grandtotaltax_value += $totaltax_value;
235 $grandtotaldiscount += $totaldiscount;
237 map { Koha::Number::Price->new($_)->format . '%' } @gst;
239 $basket->{contractname},
240 $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')',
241 Koha::Number::Price->new( $total_rrp_tax_excluded )->format,
242 Koha::Number::Price->new( $total_rrp_tax_included )->format,
244 Koha::Number::Price->new( $totaltax_value )->format,
245 Koha::Number::Price->new( $totaldiscount )->format,
246 Koha::Number::Price->new( $total_tax_excluded )->format,
247 Koha::Number::Price->new( $total_tax_included )->format,
249 push(@$abaskets, $arrbasket);
256 Koha::Number::Price->new( $grandtotal_rrp_tax_excluded )->format,
257 Koha::Number::Price->new( $grandtotal_rrp_tax_included )->format,
259 Koha::Number::Price->new( $grandtotaltax_value )->format,
260 Koha::Number::Price->new( $grandtotaldiscount )->format,
261 Koha::Number::Price->new( $grandtotal_tax_excluded )->format,
262 Koha::Number::Price->new( $grandtotal_tax_included )->format;
263 push @$abaskets,$arrbasket;
264 # height is width and width is height in this function, as the pdf is in landscape mode for the Tables.
266 $pdftable->table($pdf, $page, $abaskets,
268 w => ($width - 10)/mm,
273 font => $pdf->corefont("Times", -encoding => "utf8"),
277 background_color_odd => "lightgray",
304 $pdf->mediabox($height/mm, $width/mm);
308 my ($pdf, $basketgroup, $bookseller) = @_;
311 my $libraryname = C4::Context->preference("LibraryName");
312 my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} );
313 my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} );
314 my $freedeliveryplace = $basketgroup->{freedeliveryplace};
318 # open 1st page (with the header)
319 my $page = $pdf->openpage(1);
322 my $text = $page->text;
324 # print the libraryname in the header
325 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm );
326 $text->translate(30/mm, ($height-28.5)/mm);
327 $text->text($libraryname);
329 # print order info, on the default PDF
330 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm );
331 $text->translate(100/mm, ($height-5-48)/mm);
332 $text->text($basketgroup->{'id'});
335 my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
336 $text->translate(130/mm, ($height-5-48)/mm);
339 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
341 # print billing infos
342 $text->translate(100/mm, ($height-86)/mm);
343 $text->text($libraryname);
344 $text->translate(100/mm, ($height-97)/mm);
345 $text->text($billing_library->branchname);
346 $text->translate(100/mm, ($height-108.5)/mm);
347 $text->text($billing_library->branchphone);
348 $text->translate(100/mm, ($height-115.5)/mm);
349 $text->text($billing_library->branchfax);
350 $text->translate(100/mm, ($height-122.5)/mm);
351 $text->text($billing_library->branchaddress1);
352 $text->translate(100/mm, ($height-127.5)/mm);
353 $text->text($billing_library->branchaddress2);
354 $text->translate(100/mm, ($height-132.5)/mm);
355 $text->text($billing_library->branchaddress3);
356 $text->translate(100/mm, ($height-137.5)/mm);
357 $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry));
358 $text->translate(100/mm, ($height-147.5)/mm);
359 $text->text($billing_library->branchemail);
362 $text->translate(100/mm, ($height-145.5)/mm);
363 $text->text($subject);
365 # print bookseller infos
366 $text->translate(100/mm, ($height-180)/mm);
367 $text->text($bookseller->name);
368 $text->translate(100/mm, ($height-185)/mm);
369 $text->text($bookseller->postal);
370 $text->translate(100/mm, ($height-190)/mm);
371 $text->text($bookseller->address1);
372 $text->translate(100/mm, ($height-195)/mm);
373 $text->text($bookseller->address2);
374 $text->translate(100/mm, ($height-200)/mm);
375 $text->text($bookseller->address3);
376 $text->translate(100/mm, ($height-205)/mm);
377 $text->text($bookseller->accountnumber);
379 # print delivery infos
380 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
381 $text->translate(50/mm, ($height-237)/mm);
382 if ($freedeliveryplace) {
384 my @fdp = split('\n', $freedeliveryplace);
387 $text->translate( 50 / mm, ( $height - $start ) / mm );
391 $text->text($delivery_library->branchaddress1);
392 $text->translate(50/mm, ($height-242)/mm);
393 $text->text($delivery_library->branchaddress2);
394 $text->translate(50/mm, ($height-247)/mm);
395 $text->text($delivery_library->branchaddress3);
396 $text->translate(50/mm, ($height-252)/mm);
397 $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry));
399 $text->translate(50/mm, ($height-262)/mm);
400 $text->text($basketgroup->{deliverycomment});
405 for (my $i=1;$i <= $pdf->pages;$i++) {
406 my $page = $pdf->openpage($i);
407 my $text = $page->text;
408 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
409 $text->translate(10/mm, 10/mm);
410 $text->text("Page $i / ".$pdf->pages);
415 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
416 # open the default PDF that will be used for base (1st page already filled)
417 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout3pagesfr.pdf';
418 my $pdf = PDF::API2->open($pdf_template);
419 $pdf->pageLabel( 0, {
421 } ); # start with roman numbering
422 # fill the 1st page (basketgroup information)
423 printhead($pdf, $basketgroup, $bookseller);
424 # fill the 2nd page (orders summary)
425 printbaskets($pdf, $basketgroup, $baskets, $bookseller, $GST, $orders);
426 # fill other pages (orders)
427 printorders($pdf, $basketgroup, $baskets, $orders);
428 # print something on each page (usually the footer, but you could also put a header
430 return $pdf->stringify;