1 package Koha::pdfformat::layout1page;
3 # Copyright 2022 Catalyst IT <aleisha@catalyst.net.nz>
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub.
21 use vars qw(@ISA @EXPORT);
25 use Koha::Number::Price;
26 use Koha::DateUtils qw( dt_from_string output_pref );
31 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
33 @EXPORT = qw(printpdf);
37 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurement of PDF::API2).
38 #The constants exported transform that into PostScript points (/mm for millimeter, /in for inch, pt is postscript point, and as so is there only to show what is happening.
39 use constant mm => 25.4 / 72;
40 use constant in => 1 / 72;
45 my ($height, $width) = (297, 210);
49 my ($pdf, $basketgroup, $baskets, $orders) = @_;
51 my $cur_format = C4::Context->preference("CurrencyFormat");
53 $pdf->mediabox($height/mm, $width/mm);
54 my $page = $pdf->openpage(1);
56 my $pdftable = PDF::Table->new();
60 my @keys = ('Qty', 'Document', 'RRP tax inc.', 'Discount', 'Tax', 'Total tax exc.', 'Total tax inc.');
61 for my $bkey (@keys) {
62 push(@$arrbasket, $bkey);
64 push(@$abaskets, $arrbasket);
67 for my $basket (@$baskets){
68 for my $line (@{$orders->{$basket->{basketno}}}) {
71 if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
72 $titleinfo = $line->{title} . " / " . $line->{author} .
73 ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
74 ( $line->{en} ? " EN: " . $line->{en} : '' ) .
75 ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) .
76 ( $line->{edition} ? ", " . $line->{edition} : '' ) .
77 ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') .
78 ( $line->{publicationyear} ? ', '. $line->{publicationyear} : '');
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} ? ' published by '. $line->{publishercode} : '') .
87 ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : '');
91 $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor: " . $line->{order_vendornote} : '' ),
92 Koha::Number::Price->new( $line->{rrp_tax_included} )->format,
93 Koha::Number::Price->new( $line->{discount} )->format . '%',
94 Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%',
95 Koha::Number::Price->new( $line->{total_tax_excluded} )->format,
96 Koha::Number::Price->new( $line->{total_tax_included} )->format,
98 push(@$abaskets, $arrbasket);
102 $pdftable->table($pdf, $page, $abaskets,
104 w => ($width - 20)/mm,
111 background_color_odd => "lightgray",
112 font => $pdf->corefont("Times", -encoding => "utf8"),
115 font => $pdf->corefont("Times", -encoding => "utf8"),
121 { justify => 'left' },
123 { justify => 'right' },
124 { justify => 'right' },
125 { justify => 'right' },
126 { justify => 'right' },
127 { justify => 'right' },
128 { justify => 'right' },
132 $pdf->mediabox($width/mm, $height/mm);
136 my ($pdf, $basketgroup, $bookseller) = @_;
139 my $libraryname = C4::Context->preference("LibraryName");
140 my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} );
141 my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} );
142 my $freedeliveryplace = $basketgroup->{freedeliveryplace};
144 # open 1st page (with the header)
145 my $page = $pdf->openpage(1);
148 my $text = $page->text;
149 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
151 # print order info, on the default PDF
152 $text->translate(42/mm, ($height-62)/mm);
153 $text->text($basketgroup->{'id'});
156 my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
157 $text->translate(41/mm, ($height-67)/mm);
160 # print billing infos
161 $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
162 $text->translate(107/mm, ($height-67)/mm);
163 $text->text($libraryname);
165 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm );
166 $text->translate(107/mm, ($height-71)/mm);
167 $text->text($billing_library->branchname);
168 $text->translate(116/mm, ($height-97)/mm);
169 $text->text($billing_library->branchphone);
170 $text->translate(155/mm, ($height-97)/mm);
171 $text->text($billing_library->branchfax);
173 # print bookseller infos
174 $text->translate(20/mm, ($height-33)/mm);
175 $text->text($bookseller->name);
176 $text->translate(20/mm, ($height-37)/mm);
177 if ( $bookseller->postal ) {
179 my @postal = split('\n', $bookseller->postal);
182 $text->translate( 20 / mm, ( $height - $start ) / mm );
186 $text->translate(20/mm, ($height-57)/mm);
187 $text->text($bookseller->accountnumber);
189 # print delivery infos
190 $text->translate(107/mm, ($height-75)/mm);
191 if ($freedeliveryplace) {
193 my @fdp = split('\n', $freedeliveryplace);
196 $text->translate( 107 / mm, ( $height - $start ) / mm );
200 $text->text( $delivery_library->branchaddress1 );
201 $text->translate( 107 / mm, ( $height - 75 ) / mm );
202 $text->text( $delivery_library->branchaddress2 );
203 $text->translate( 107 / mm, ( $height - 79 ) / mm );
204 $text->text( $delivery_library->branchaddress3 );
205 $text->translate( 107 / mm, ( $height - 83 ) / mm );
206 $text->text( join( ' ', $delivery_library->branchcity, $delivery_library->branchzip, $delivery_library->branchcountry ) );
208 $text->translate( 20 / mm, ( $height - 120 ) / mm );
209 $text->text($basketgroup->{deliverycomment});
214 for ( 1..$pdf->pages ) {
215 my $page = $pdf->openpage($_);
216 my $text = $page->text;
217 $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm );
218 $text->translate(10/mm, 10/mm);
219 $text->text("Page $_ / ".$pdf->pages);
224 my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
225 # open the default PDF that will be used for base (1st page already filled)
226 my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout1page.pdf';
227 my $pdf = PDF::API2->open($pdf_template);
228 $pdf->pageLabel( 0, {
230 } ); # start with roman numbering
231 # fill the 1st page (basketgroup information)
232 printhead($pdf, $basketgroup, $bookseller);
233 # fill other pages (orders)
234 printorders($pdf, $basketgroup, $baskets, $orders);
235 # print something on each page (usually the footer, but you could also put a header
237 return $pdf->stringify;