Lines 27-39
use Koha::DateUtils qw( dt_from_string output_pref );
Link Here
|
27 |
use Koha::Libraries; |
27 |
use Koha::Libraries; |
28 |
|
28 |
|
29 |
BEGIN { |
29 |
BEGIN { |
30 |
use Exporter (); |
30 |
use Exporter (); |
31 |
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); |
31 |
our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); |
32 |
@ISA = qw(Exporter); |
32 |
@ISA = qw(Exporter); |
33 |
@EXPORT = qw(printpdf); |
33 |
@EXPORT = qw(printpdf); |
34 |
} |
34 |
} |
35 |
|
35 |
|
36 |
|
|
|
37 |
#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurement of PDF::API2). |
36 |
#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. |
37 |
#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; |
38 |
use constant mm => 25.4 / 72; |
Lines 41-125
use constant in => 1 / 72;
Link Here
|
41 |
use constant pt => 1; |
40 |
use constant pt => 1; |
42 |
|
41 |
|
43 |
use PDF::API2; |
42 |
use PDF::API2; |
|
|
43 |
|
44 |
#A4 paper specs |
44 |
#A4 paper specs |
45 |
my ($height, $width) = (297, 210); |
45 |
my ( $height, $width ) = ( 297, 210 ); |
46 |
use PDF::Table; |
46 |
use PDF::Table; |
47 |
|
47 |
|
48 |
sub printorders { |
48 |
sub printorders { |
49 |
my ($pdf, $basketgroup, $baskets, $orders) = @_; |
49 |
my ( $pdf, $basketgroup, $baskets, $orders ) = @_; |
50 |
|
50 |
|
51 |
my $cur_format = C4::Context->preference("CurrencyFormat"); |
51 |
my $cur_format = C4::Context->preference("CurrencyFormat"); |
52 |
|
52 |
|
53 |
$pdf->mediabox($height/mm, $width/mm); |
53 |
$pdf->mediabox( $height / mm, $width / mm ); |
54 |
my $page = $pdf->openpage(1); |
54 |
my $page = $pdf->openpage(1); |
55 |
|
55 |
|
56 |
my $pdftable = PDF::Table->new(); |
56 |
my $pdftable = PDF::Table->new(); |
57 |
|
57 |
|
58 |
my $abaskets; |
58 |
my $abaskets; |
59 |
my $arrbasket; |
59 |
my $arrbasket; |
60 |
my @keys = ('Qty', 'Document', 'RRP tax inc.', 'Discount', 'Tax', 'Total tax exc.', 'Total tax inc.'); |
60 |
my @keys = ( 'Qty', 'Document', 'RRP tax inc.', 'Discount', 'Tax', 'Total tax exc.', 'Total tax inc.' ); |
61 |
for my $bkey (@keys) { |
61 |
for my $bkey (@keys) { |
62 |
push(@$arrbasket, $bkey); |
62 |
push( @$arrbasket, $bkey ); |
63 |
} |
63 |
} |
64 |
push(@$abaskets, $arrbasket); |
64 |
push( @$abaskets, $arrbasket ); |
65 |
|
65 |
|
66 |
my $titleinfo; |
66 |
my $titleinfo; |
67 |
for my $basket (@$baskets){ |
67 |
for my $basket (@$baskets) { |
68 |
for my $line (@{$orders->{$basket->{basketno}}}) { |
68 |
for my $line ( @{ $orders->{ $basket->{basketno} } } ) { |
69 |
$arrbasket = undef; |
69 |
$arrbasket = undef; |
70 |
$titleinfo = ""; |
70 |
$titleinfo = ""; |
71 |
if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { |
71 |
if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { |
72 |
$titleinfo = $line->{title} . " / " . $line->{author} . |
72 |
$titleinfo = |
73 |
( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . |
73 |
$line->{title} . " / " |
74 |
( $line->{en} ? " EN: " . $line->{en} : '' ) . |
74 |
. $line->{author} |
75 |
( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . |
75 |
. ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) |
76 |
( $line->{edition} ? ", " . $line->{edition} : '' ) . |
76 |
. ( $line->{en} ? " EN: " . $line->{en} : '' ) |
77 |
( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . |
77 |
. ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) |
78 |
( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); |
78 |
. ( $line->{edition} ? ", " . $line->{edition} : '' ) |
|
|
79 |
. ( $line->{publishercode} ? ' published by ' . $line->{publishercode} : '' ) |
80 |
. ( $line->{publicationyear} ? ', ' . $line->{publicationyear} : '' ); |
81 |
} else { # MARC21 |
82 |
$titleinfo = |
83 |
$line->{title} . " " |
84 |
. $line->{author} |
85 |
. ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) |
86 |
. ( $line->{en} ? " EN: " . $line->{en} : '' ) |
87 |
. ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) |
88 |
. ( $line->{edition} ? ", " . $line->{edition} : '' ) |
89 |
. ( $line->{publishercode} ? ' published by ' . $line->{publishercode} : '' ) |
90 |
. ( $line->{copyrightdate} ? ' ' . $line->{copyrightdate} : '' ); |
79 |
} |
91 |
} |
80 |
else { # MARC21 |
92 |
push( |
81 |
$titleinfo = $line->{title} . " " . $line->{author} . |
93 |
@$arrbasket, |
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} : ''); |
88 |
} |
89 |
push( @$arrbasket, |
90 |
$line->{quantity}, |
94 |
$line->{quantity}, |
91 |
$titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor: " . $line->{order_vendornote} : '' ), |
95 |
$titleinfo |
|
|
96 |
. ( |
97 |
$line->{order_vendornote} |
98 |
? "\n----------------\nNote for vendor: " . $line->{order_vendornote} |
99 |
: '' |
100 |
), |
92 |
Koha::Number::Price->new( $line->{rrp_tax_included} )->format, |
101 |
Koha::Number::Price->new( $line->{rrp_tax_included} )->format, |
93 |
Koha::Number::Price->new( $line->{discount} )->format . '%', |
102 |
Koha::Number::Price->new( $line->{discount} )->format . '%', |
94 |
Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', |
103 |
Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', |
95 |
Koha::Number::Price->new( $line->{total_tax_excluded} )->format, |
104 |
Koha::Number::Price->new( $line->{total_tax_excluded} )->format, |
96 |
Koha::Number::Price->new( $line->{total_tax_included} )->format, |
105 |
Koha::Number::Price->new( $line->{total_tax_included} )->format, |
97 |
); |
106 |
); |
98 |
push(@$abaskets, $arrbasket); |
107 |
push( @$abaskets, $arrbasket ); |
99 |
} |
108 |
} |
100 |
} |
109 |
} |
101 |
|
110 |
|
102 |
$pdftable->table($pdf, $page, $abaskets, |
111 |
$pdftable->table( |
103 |
x => 10/mm, |
112 |
$pdf, $page, $abaskets, |
104 |
w => ($width - 20)/mm, |
113 |
x => 10 / mm, |
105 |
start_y => 170/mm, |
114 |
w => ( $width - 20 ) / mm, |
106 |
next_y => 280/mm, |
115 |
start_y => 170 / mm, |
107 |
start_h => 150/mm, |
116 |
next_y => 280 / mm, |
108 |
next_h => 260/mm, |
117 |
start_h => 150 / mm, |
109 |
padding => 5, |
118 |
next_h => 260 / mm, |
110 |
padding_right => 5, |
119 |
padding => 5, |
111 |
background_color_odd => "lightgray", |
120 |
padding_right => 5, |
112 |
font => $pdf->corefont("Times", -encoding => "utf8"), |
121 |
background_color_odd => "lightgray", |
113 |
font_size => 3/mm, |
122 |
font => $pdf->corefont( "Times", -encoding => "utf8" ), |
114 |
header_props => { |
123 |
font_size => 3 / mm, |
115 |
font => $pdf->corefont("Times", -encoding => "utf8"), |
124 |
header_props => { |
116 |
font_size => 10, |
125 |
font => $pdf->corefont( "Times", -encoding => "utf8" ), |
117 |
bg_color => 'gray', |
126 |
font_size => 10, |
118 |
repeat => 1, |
127 |
bg_color => 'gray', |
|
|
128 |
repeat => 1, |
119 |
}, |
129 |
}, |
120 |
column_props => [ |
130 |
column_props => [ |
121 |
{ justify => 'left' }, |
131 |
{ justify => 'left' }, |
122 |
{ min_w => 90/mm }, |
132 |
{ min_w => 90 / mm }, |
123 |
{ justify => 'right' }, |
133 |
{ justify => 'right' }, |
124 |
{ justify => 'right' }, |
134 |
{ justify => 'right' }, |
125 |
{ justify => 'right' }, |
135 |
{ justify => 'right' }, |
Lines 129-207
sub printorders {
Link Here
|
129 |
], |
139 |
], |
130 |
); |
140 |
); |
131 |
|
141 |
|
132 |
$pdf->mediabox($width/mm, $height/mm); |
142 |
$pdf->mediabox( $width / mm, $height / mm ); |
133 |
} |
143 |
} |
134 |
|
144 |
|
135 |
sub printhead { |
145 |
sub printhead { |
136 |
my ($pdf, $basketgroup, $bookseller) = @_; |
146 |
my ( $pdf, $basketgroup, $bookseller ) = @_; |
137 |
|
147 |
|
138 |
# get library name |
148 |
# get library name |
139 |
my $libraryname = C4::Context->preference("LibraryName"); |
149 |
my $libraryname = C4::Context->preference("LibraryName"); |
140 |
my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); |
150 |
my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); |
141 |
my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); |
151 |
my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); |
142 |
my $freedeliveryplace = $basketgroup->{freedeliveryplace}; |
152 |
my $freedeliveryplace = $basketgroup->{freedeliveryplace}; |
143 |
my $ordersentences = C4::Context->preference("1PageOrderPDFText"); |
153 |
my $ordersentences = C4::Context->preference("1PageOrderPDFText"); |
144 |
|
154 |
|
145 |
# open 1st page (with the header) |
155 |
# open 1st page (with the header) |
146 |
my $page = $pdf->openpage(1); |
156 |
my $page = $pdf->openpage(1); |
147 |
|
157 |
|
148 |
# create a text |
158 |
# create a text |
149 |
my $text = $page->text; |
159 |
my $text = $page->text; |
150 |
$text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); |
160 |
$text->font( $pdf->corefont( "Times", -encoding => "utf8" ), 4 / mm ); |
151 |
|
161 |
|
152 |
# print order info, on the default PDF |
162 |
# print order info, on the default PDF |
153 |
$text->translate(42/mm, ($height-62)/mm); |
163 |
$text->translate( 42 / mm, ( $height - 62 ) / mm ); |
154 |
$text->text($basketgroup->{'id'}); |
164 |
$text->text( $basketgroup->{'id'} ); |
155 |
|
165 |
|
156 |
# print the date |
166 |
# print the date |
157 |
my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); |
167 |
my $today = output_pref( { dt => dt_from_string, dateonly => 1 } ); |
158 |
$text->translate(41/mm, ($height-67)/mm); |
168 |
$text->translate( 41 / mm, ( $height - 67 ) / mm ); |
159 |
$text->text($today); |
169 |
$text->text($today); |
160 |
|
170 |
|
161 |
# print billing infos |
171 |
# print billing infos |
162 |
$text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); |
172 |
$text->font( $pdf->corefont( "Times-Bold", -encoding => "utf8" ), 4 / mm ); |
163 |
$text->translate(107/mm, ($height-67)/mm); |
173 |
$text->translate( 107 / mm, ( $height - 67 ) / mm ); |
164 |
$text->text($libraryname); |
174 |
$text->text($libraryname); |
165 |
|
175 |
|
166 |
# print text defined in 1PageOrderPDFText syspref |
176 |
# print text defined in 1PageOrderPDFText syspref |
167 |
$text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); |
177 |
$text->font( $pdf->corefont( "Times", -encoding => "utf8" ), 4 / mm ); |
168 |
my @allLines = split/\n+/, $ordersentences; |
178 |
my @allLines = split /\n+/, $ordersentences; |
169 |
my $count = 0; |
179 |
my $count = 0; |
170 |
foreach my $ordersentence ( @allLines ) { |
180 |
foreach my $ordersentence (@allLines) { |
171 |
$count+=4; |
181 |
$count += 4; |
172 |
$text->translate(15/mm, ($height-(105 + $count ))/mm); |
182 |
$text->translate( 15 / mm, ( $height - ( 105 + $count ) ) / mm ); |
173 |
$text->text( $ordersentence ); |
183 |
$text->text($ordersentence); |
174 |
} |
184 |
} |
175 |
|
185 |
|
176 |
$text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); |
186 |
$text->font( $pdf->corefont( "Times", -encoding => "utf8" ), 4 / mm ); |
177 |
$text->translate(107/mm, ($height-71)/mm); |
187 |
$text->translate( 107 / mm, ( $height - 71 ) / mm ); |
178 |
$text->text($billing_library->branchname); |
188 |
$text->text( $billing_library->branchname ); |
179 |
$text->translate(116/mm, ($height-97)/mm); |
189 |
$text->translate( 116 / mm, ( $height - 97 ) / mm ); |
180 |
$text->text($billing_library->branchphone); |
190 |
$text->text( $billing_library->branchphone ); |
181 |
$text->translate(155/mm, ($height-97)/mm); |
191 |
$text->translate( 155 / mm, ( $height - 97 ) / mm ); |
182 |
$text->text($billing_library->branchfax); |
192 |
$text->text( $billing_library->branchfax ); |
183 |
|
193 |
|
184 |
# print bookseller infos |
194 |
# print bookseller infos |
185 |
$text->translate(20/mm, ($height-33)/mm); |
195 |
$text->translate( 20 / mm, ( $height - 33 ) / mm ); |
186 |
$text->text($bookseller->name); |
196 |
$text->text( $bookseller->name ); |
187 |
$text->translate(20/mm, ($height-37)/mm); |
197 |
$text->translate( 20 / mm, ( $height - 37 ) / mm ); |
188 |
if ( $bookseller->postal ) { |
198 |
if ( $bookseller->postal ) { |
189 |
my $start = 41; |
199 |
my $start = 41; |
190 |
my @postal = split('\n', $bookseller->postal); |
200 |
my @postal = split( '\n', $bookseller->postal ); |
191 |
foreach (@postal) { |
201 |
foreach (@postal) { |
192 |
$text->text($_); |
202 |
$text->text($_); |
193 |
$text->translate( 20 / mm, ( $height - $start ) / mm ); |
203 |
$text->translate( 20 / mm, ( $height - $start ) / mm ); |
194 |
$start += 4; |
204 |
$start += 4; |
195 |
} |
205 |
} |
196 |
} |
206 |
} |
197 |
$text->translate(20/mm, ($height-57)/mm); |
207 |
$text->translate( 20 / mm, ( $height - 57 ) / mm ); |
198 |
$text->text($bookseller->accountnumber); |
208 |
$text->text( $bookseller->accountnumber ); |
199 |
|
209 |
|
200 |
# print delivery infos |
210 |
# print delivery infos |
201 |
$text->translate(107/mm, ($height-75)/mm); |
211 |
$text->translate( 107 / mm, ( $height - 75 ) / mm ); |
202 |
if ($freedeliveryplace) { |
212 |
if ($freedeliveryplace) { |
203 |
my $start = 79; |
213 |
my $start = 79; |
204 |
my @fdp = split('\n', $freedeliveryplace); |
214 |
my @fdp = split( '\n', $freedeliveryplace ); |
205 |
foreach (@fdp) { |
215 |
foreach (@fdp) { |
206 |
$text->text($_); |
216 |
$text->text($_); |
207 |
$text->translate( 107 / mm, ( $height - $start ) / mm ); |
217 |
$text->translate( 107 / mm, ( $height - $start ) / mm ); |
Lines 214-248
sub printhead {
Link Here
|
214 |
$text->translate( 107 / mm, ( $height - 79 ) / mm ); |
224 |
$text->translate( 107 / mm, ( $height - 79 ) / mm ); |
215 |
$text->text( $delivery_library->branchaddress3 ); |
225 |
$text->text( $delivery_library->branchaddress3 ); |
216 |
$text->translate( 107 / mm, ( $height - 83 ) / mm ); |
226 |
$text->translate( 107 / mm, ( $height - 83 ) / mm ); |
217 |
$text->text( join( ' ', $delivery_library->branchcity, $delivery_library->branchzip, $delivery_library->branchcountry ) ); |
227 |
$text->text( |
|
|
228 |
join( ' ', $delivery_library->branchcity, $delivery_library->branchzip, $delivery_library->branchcountry ) |
229 |
); |
218 |
} |
230 |
} |
219 |
$text->translate( 20 / mm, ( $height - 120 ) / mm ); |
231 |
$text->translate( 20 / mm, ( $height - 120 ) / mm ); |
220 |
$text->text($basketgroup->{deliverycomment}); |
232 |
$text->text( $basketgroup->{deliverycomment} ); |
221 |
} |
233 |
} |
222 |
|
234 |
|
223 |
sub printfooters { |
235 |
sub printfooters { |
224 |
my $pdf = shift; |
236 |
my $pdf = shift; |
225 |
for ( 1..$pdf->pages ) { |
237 |
for ( 1 .. $pdf->pages ) { |
226 |
my $page = $pdf->openpage($_); |
238 |
my $page = $pdf->openpage($_); |
227 |
my $text = $page->text; |
239 |
my $text = $page->text; |
228 |
$text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); |
240 |
$text->font( $pdf->corefont( "Times", -encoding => "utf8" ), 3 / mm ); |
229 |
$text->translate(10/mm, 10/mm); |
241 |
$text->translate( 10 / mm, 10 / mm ); |
230 |
$text->text("Page $_ / ".$pdf->pages); |
242 |
$text->text( "Page $_ / " . $pdf->pages ); |
231 |
} |
243 |
} |
232 |
} |
244 |
} |
233 |
|
245 |
|
234 |
sub printpdf { |
246 |
sub printpdf { |
235 |
my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; |
247 |
my ( $basketgroup, $bookseller, $baskets, $orders, $GST ) = @_; |
|
|
248 |
|
236 |
# open the default PDF that will be used for base (1st page already filled) |
249 |
# open the default PDF that will be used for base (1st page already filled) |
237 |
my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout1page.pdf'; |
250 |
my $pdf_template = |
|
|
251 |
C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout1page.pdf'; |
238 |
my $pdf = PDF::API2->open($pdf_template); |
252 |
my $pdf = PDF::API2->open($pdf_template); |
239 |
$pdf->pageLabel( 0, { |
253 |
$pdf->pageLabel( |
240 |
-style => 'roman', |
254 |
0, |
241 |
} ); # start with roman numbering |
255 |
{ |
242 |
# fill the 1st page (basketgroup information) |
256 |
-style => 'roman', |
243 |
printhead($pdf, $basketgroup, $bookseller); |
257 |
} |
|
|
258 |
); # start with roman numbering |
259 |
# fill the 1st page (basketgroup information) |
260 |
printhead( $pdf, $basketgroup, $bookseller ); |
261 |
|
244 |
# fill other pages (orders) |
262 |
# fill other pages (orders) |
245 |
printorders($pdf, $basketgroup, $baskets, $orders); |
263 |
printorders( $pdf, $basketgroup, $baskets, $orders ); |
|
|
264 |
|
246 |
# print something on each page (usually the footer, but you could also put a header |
265 |
# print something on each page (usually the footer, but you could also put a header |
247 |
printfooters($pdf); |
266 |
printfooters($pdf); |
248 |
return $pdf->stringify; |
267 |
return $pdf->stringify; |
249 |
- |
|
|