View | Details | Raw Unified | Return to bug 27891
Collapse All | Expand All

(-)a/Koha/pdfformat/layout2pagesdinde.pm (+395 lines)
Line 0 Link Here
1
package Koha::pdfformat::layout2pagesdinde;
2
# script to print the order in german din format. Initial for duisburg public library (Stadtbibliothek Duisburg)
3
# written in Feb. 2021 by m.m.oehme@gmail.com
4
# based on:
5
#example script to print a basketgroup
6
#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com
7
8
# Copyright 2021 M.Oehme
9
#
10
# This file is only useful as part of Koha.
11
#
12
# Koha, and this file too, is free software; you can redistribute it and/or modify it
13
# under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 3 of the License, or
15
# (at your option) any later version.
16
#
17
# Koha is distributed in the hope that it will be useful, but
18
# WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
21
#
22
# You should have received a copy of the GNU General Public License
23
# along with Koha; if not, see <http://www.gnu.org/licenses>.
24
25
use vars qw(@ISA @EXPORT);
26
use MIME::Base64;
27
use List::MoreUtils qw/uniq/;
28
use Modern::Perl;
29
use utf8;
30
31
use C4::Acquisition;
32
use Koha::Number::Price;
33
use Koha::DateUtils;
34
use Koha::Libraries;
35
36
use PDF::API2;
37
use PDF::Table;
38
39
BEGIN {
40
    use Exporter   ();
41
    our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
42
    @ISA    = qw(Exporter);
43
    @EXPORT = qw(printpdf);
44
}
45
#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
46
use constant mm => 25.4 / 72;
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 in => 1 / 72;
49
#use constant pt => 1;
50
51
#A4 paper specs
52
my ($height, $width) = (297, 210);
53
54
sub printpage1 {
55
    my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_;
56
57
    my $libraryname       = C4::Context->preference("LibraryName");
58
    my $billing_library   = Koha::Libraries->find( $basketgroup->{billingplace} );
59
    my $delivery_library  = Koha::Libraries->find( $basketgroup->{deliveryplace} );
60
    my $freedeliveryplace = $basketgroup->{freedeliveryplace};
61
62
    # open 1st page (with the header)
63
    #my $page = $pdf->openpage(1);
64
    my $page = $pdf->page();
65
    my $text = $page->text;
66
67
    ############################################################################
68
    # print library name
69
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 6/mm );
70
    $text->translate(25/mm,  ($height-28.5)/mm);
71
    $text->text($libraryname);
72
73
    ############################################################################
74
    # print sender line in address field
75
    my $sender=$billing_library->branchname.($billing_library->branchaddress1 ? " - ".$billing_library->branchaddress1 : '' )." - ". $billing_library->branchzip." ".$billing_library->branchcity;
76
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 3/mm );
77
    $text->translate(25/mm,  ($height-55)/mm);
78
    $text->text($sender, -underline => 'auto');
79
80
    ############################################################################
81
    # print the address field  (bookseller infos)
82
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
83
    $text->translate(25/mm,  ($height-65)/mm);
84
    $text->text($bookseller->name);
85
    #  $bookseller->postal means address and can contain more than one line, so i split it on "\n" to an array and itterate thru every line
86
    if ( $bookseller->postal) {
87
      my @lines=split( /\n/, $bookseller->postal);
88
      my $vpos =70;
89
      foreach  (@lines) {
90
        $text->translate(25/mm,  (($height-$vpos)/mm));
91
        $text->text($_);
92
        $vpos=$vpos+5;
93
        last if $vpos>100;
94
      }
95
    }
96
97
    ############################################################################
98
    # print the date
99
    my $today = "Datum ".output_pref({ dt => dt_from_string, dateonly => 1 });
100
    $text->translate(195/mm,  ($height-75)/mm);
101
    $text->text_right($today);
102
103
    ############################################################################
104
    # Ordernr (booksellernote)
105
    $text->font( $pdf->corefont("Arial-Bold", -encoding => "utf8"), 5/mm );
106
    $text->translate(25/mm,  ($height-115)/mm);
107
    $text->text(("Bestellung ".$bookseller->notes), -underline => 'auto');
108
109
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
110
    $text->translate(25/mm,  ($height-120)/mm);
111
    $text->text("(bei der Rechnungsstellung bitte unbedingt angeben!)");
112
113
    $text->translate(25/mm,  ($height-130)/mm);
114
    $text->text("Wir bitten um Lieferung der ab Seite 2 aufgelisteten Positionen an die genannte Lieferadresse.");
115
116
    ############################################################################
117
    # print delivery infos
118
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
119
    $text->translate(25/mm,  ($height-145)/mm);
120
    $text->text("Lieferadresse", -underline => 'auto');
121
    if ($freedeliveryplace) {
122
        my $start = 150;
123
        my @fdp = split('\n', $freedeliveryplace);
124
        foreach (@fdp) {
125
            $text->translate( 25 / mm, ( $height - $start ) / mm );
126
            if ($_) {
127
                $text->text($_);
128
                $start += 5;
129
            }
130
        }
131
    }
132
    else {
133
        my $start = 150;
134
        my @fdp = ($delivery_library->branchname, $delivery_library->branchaddress1,
135
                   $delivery_library->branchaddress2, $delivery_library->branchaddress3,
136
                   join(' ', $delivery_library->branchzip, $delivery_library->branchcity)
137
	          );
138
        foreach (@fdp) {
139
            if ($_) {
140
                $text->translate( 25/mm, ( $height - $start )/mm );
141
                $text->text($_);
142
                $start += 5;
143
            }
144
        }
145
    }
146
147
    ############################################################################
148
    #print billing infos
149
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
150
    $text->translate(125/mm,  ($height-145)/mm);
151
    $text->text("Rechnungsadresse", -underline => 'auto');
152
153
    my $start = 150;
154
    my @pbi = ($billing_library->branchname, $billing_library->branchaddress1,
155
               $billing_library->branchaddress2, $billing_library->branchaddress3,
156
               join(' ', $billing_library->branchzip, $billing_library->branchcity));
157
    foreach (@pbi) {
158
        if ($_) {
159
            $text->translate( 125 / mm, ( $height - $start ) / mm );
160
            $text->text($_);
161
            $start += 5;
162
        }
163
    }
164
165
    ############################################################################
166
    ## collect all the money  ;-)
167
    my ($grandtotal_rrp_tax_excluded,     # Einzelpreis netto
168
        $grandtotaltax_value,             # Steuer
169
        $grandtotaldiscount,              # Rabatt
170
        $grandtotal_tax_excluded,         # Geamtpreis netto
171
        $grandtotal_tax_included);        # Gesamtpreis brutto
172
173
    # calculate each basket total
174
    for my $basket (@$hbaskets) {
175
        my ($total_rrp_tax_excluded,
176
            $totaltax_value,
177
            $totaldiscount,
178
            $total_tax_excluded,
179
            $total_tax_included );
180
181
        # calculate each order total
182
        my $ords = $orders->{$basket->{basketno}};
183
        foreach my $ord (@$ords) {
184
            $total_rrp_tax_excluded += get_rounded_price($ord->{rrp_tax_excluded}) * $ord->{quantity};
185
            $totaltax_value += $ord->{tax_value};
186
            $totaldiscount += (get_rounded_price($ord->{rrp_tax_excluded}) - get_rounded_price($ord->{ecost_tax_excluded}) ) * $ord->{quantity};
187
            $total_tax_excluded += $ord->{total_tax_excluded};
188
            $total_tax_included += $ord->{total_tax_included};
189
        }
190
        $grandtotal_rrp_tax_excluded += $total_rrp_tax_excluded;
191
        $grandtotaltax_value += $totaltax_value;
192
        $grandtotaldiscount += $totaldiscount;
193
        $grandtotal_tax_excluded += $total_tax_excluded;
194
        $grandtotal_tax_included += $total_tax_included;
195
    }
196
197
    ############################################################################
198
    ## data output
199
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
200
    $text->translate(25/mm,  ($height-180)/mm);
201
    $text->text("Zusammenfassung", -underline => 'auto');
202
    #$text->text(($basketgroup->{'name'}."(".$basketgroup->{'id'}."):"),-underline=>'auto') ;
203
204
    $text->translate(75/mm,  ($height-180)/mm);
205
    $text->text("Summe");
206
    $text->translate(($width-40)/mm,  ($height-180)/mm);
207
    $text->text_right((Koha::Number::Price->new($grandtotal_rrp_tax_excluded)->format." Euro"));
208
209
    $text->translate(75/mm,  ($height-185)/mm);
210
    $text->text("./. Rabatt");
211
    $text->translate(($width-40)/mm,  ($height-185)/mm);
212
    $text->text_right((Koha::Number::Price->new($grandtotaldiscount)->format." Euro"));
213
214
    my $content = $page->gfx();
215
    $content->move(75/mm, ($height-186)/mm);
216
    $content->hline(($width-40)/mm);
217
    $content->stroke;
218
219
    $text->translate(75/mm,  ($height-190)/mm);
220
    $text->text("Gesamt (Netto)");
221
    $text->translate(($width-40)/mm,  ($height-190)/mm);
222
    $text->text_right((Koha::Number::Price->new($grandtotal_tax_excluded)->format." Euro"));
223
224
    $text->translate(75/mm,  ($height-195)/mm);
225
    $text->text("MwSt.");
226
    $text->translate(($width-40)/mm,  ($height-195)/mm);
227
    $text->text_right((Koha::Number::Price->new($grandtotaltax_value)->format." Euro"));
228
229
    $content->move(75/mm, ($height-196)/mm);
230
    $content->hline(($width-40)/mm);
231
    $content->stroke;
232
233
    $text->font( $pdf->corefont("Arial-Bold", -encoding => "utf8"), 4/mm );
234
    $text->translate(75/mm,  ($height-200)/mm);
235
    $text->text("Gesamt (Brutto)");
236
    $text->translate(($width-40)/mm,  ($height-200)/mm);
237
    $text->text_right((Koha::Number::Price->new($grandtotal_tax_included)->format." Euro"));
238
239
    $content->move(75/mm, ($height-201)/mm);
240
    $content->hline(($width-40)/mm);
241
    $content->stroke;
242
    $content->move(75/mm, ($height-202)/mm);
243
    $content->hline(($width-40)/mm);
244
    $content->stroke;
245
246
    ############################################################################
247
    ## signature
248
    $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
249
    $text->translate(25/mm,  ($height-235)/mm);
250
    $text->text("Mit freundlichen Grüßen");
251
    $text->translate(25/mm,  ($height-240)/mm);
252
    $text->text("Im Auftrag");
253
}
254
255
sub printorders {
256
    my ($pdf, $basketgroup, $baskets, $orders) = @_;
257
    my $cur_format = C4::Context->preference("CurrencyFormat");
258
259
    $pdf->mediabox($height/mm, $width/mm);
260
    for my $basket (@$baskets){
261
        my $page = $pdf->page();
262
        my $billing_library  = Koha::Libraries->find( $basket->{billingplace} );
263
        my $delivery_library = Koha::Libraries->find( $basket->{deliveryplace} );
264
        my $text = $page->text;
265
266
        ########################################################################
267
        # print basket header (box)
268
        my $box = $page->gfx;
269
        $box->rectxy((25)/mm, ($height - 10)/mm, ($width - 10)/mm, ($height - 25)/mm);
270
        $box->stroke;
271
272
        ########################################################################
273
        # print basket header (text)
274
        $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 6/mm );
275
        $text->translate(30/mm,  ($height-15)/mm);
276
        $text->text("Bestellung: ".$basketgroup->{'name'}." (".$basketgroup->{'id'}.")");
277
278
        $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 4/mm );
279
        $text->translate(30/mm,  ($height-20)/mm);
280
 	      $text->text(("Hinweis: ".$basket->{booksellernote}));
281
282
        ########################################################################
283
        # print the orders in the basketgroup
284
        my $pdftable = PDF::Table->new();
285
        my $abaskets;
286
        my $arrbasket;
287
288
        my @keys = ("Best.", "Titel", "Anz.", "Preis\n(Netto)", "Rabatt", "Gesamt\n(Netto)", "MwSt.", "Gesamt\n(Brutto)");
289
        for my $bkey (@keys) {
290
            push(@$arrbasket, $bkey);
291
        }
292
        push(@$abaskets, $arrbasket);
293
294
        my $titleinfo;
295
296
        foreach my $line (@{$orders->{$basket->{basketno}}}) {
297
            $arrbasket = undef;
298
            $titleinfo = "";
299
300
            $titleinfo =  $line->{title} . " / " . $line->{author} .
301
                ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) .
302
                ( $line->{issn} ? " ISSN: " . $line->{issn} : '' ) .
303
                ( $line->{ean}  ? " EAN, Verlegernr., o.ä.: " . $line->{ean} : '' ) .
304
                ( $line->{en}   ? " EN: " . $line->{en} : '' ) .
305
                ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) .
306
                ( $line->{edition}  ? ", " . $line->{edition} : '' ) .
307
                ( $line->{publishercode}   ? ' published by '. $line->{publishercode} : '') .
308
                ( $line->{publicationyear} ? ', '. $line->{publicationyear} : '') .
309
                ( $line->{copyrightdate}   ? ' '. $line->{copyrightdate} : '');
310
311
            push( @$arrbasket,
312
               ($basket->{basketno}."-".$line->{ordernumber}),
313
               $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferhinweis: " . $line->{order_vendornote} : ''),
314
               $line->{quantity},
315
               Koha::Number::Price->new( $line->{rrp_tax_excluded} )->format,
316
               (
317
                 Koha::Number::Price->new( $line->{rrp_tax_excluded} - $line->{ecost_tax_excluded})->format."\n(".
318
                 Koha::Number::Price->new( $line->{discount} )->format . '%)',
319
               ) ,
320
               Koha::Number::Price->new( $line->{total_tax_excluded} )->format,
321
               (
322
                 Koha::Number::Price->new( $line->{tax_value} )->format."\n(".
323
                 Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%)'
324
               ),
325
    	         Koha::Number::Price->new( $line->{total_tax_included} )->format,
326
            );
327
            push(@$abaskets, $arrbasket);
328
        }
329
        $pdftable->table($pdf, $page, $abaskets,
330
            x => 25/mm,
331
            start_y => 270/mm,
332
            w => ($width - 35)/mm,
333
            start_h => 240/mm,
334
            next_y  => 285/mm,
335
            next_h  => 255/mm,
336
            padding => 2,
337
            padding_right => 2,
338
            background_color_odd  => "lightgray",
339
            font       => $pdf->corefont("Arial", -encoding => "utf8"),
340
            font_size => 3/mm,
341
            header_props   =>    {
342
                font       => $pdf->corefont("Arial", -encoding => "utf8"),
343
                font_size  => 9,
344
                bg_color   => 'gray',
345
                repeat     => 1,
346
            },
347
            column_props => [
348
                { justify => 'left',  },     # One of left|right ,
349
                { min_w => 65/mm,            # Minimum column width.
350
                  max_w => 65/mm,            # Maximum column width.
351
                  justify => 'left',         # One of left|right ,
352
                },
353
                { justify => 'right', }, # One of left|right ,
354
                { justify => 'right', }, # One of left|right ,
355
                { justify => 'right', }, # One of left|right ,
356
                { justify => 'right', }, # One of left|right ,
357
                { justify => 'right', }, # One of left|right ,
358
                { justify => 'right', }, # One of left|right ,
359
            ],
360
        );
361
    }
362
    $pdf->mediabox($width/mm, $height/mm);
363
}
364
365
sub printfooters {
366
    my ($pdf) = @_;
367
    for (my $i=1;$i <= $pdf->pages;$i++) {
368
        my $page = $pdf->openpage($i);
369
        my $text = $page->text;
370
        $text->font( $pdf->corefont("Arial", -encoding => "utf8"), 3/mm );
371
        $text->translate(105/mm,  20/mm);
372
        $text->text_center("Seite $i / ".$pdf->pages);
373
    }
374
}
375
376
sub printpdf {
377
    my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
378
379
    # we dont use template, but let the code as comment if someone in the future will do
380
    # open the default PDF that will be used for base (1st page already filled)
381
    #   my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesdin.pdf';
382
    #   my $pdf = PDF::API2->open($pdf_template);
383
    my $pdf = PDF::API2->new();
384
    $pdf->pageLabel( 0, { -style => 'roman', } ); # start with roman numbering
385
386
    # fill the 1st page
387
    printpage1($pdf, $basketgroup, $baskets, $bookseller, $GST, $orders);
388
    # fill other pages (orders)
389
    printorders($pdf, $basketgroup, $baskets, $orders);
390
    # print something on each page (usually the footer, but you could also put a header
391
    printfooters($pdf);
392
    return $pdf->stringify;
393
}
394
395
1;
(-)a/acqui/basketgroup.pl (-1 / +1 lines)
Lines 124-130 sub printbasketgrouppdf{ Link Here
124
    my ($basketgroupid) = @_;
124
    my ($basketgroupid) = @_;
125
125
126
    my $pdfformat = C4::Context->preference("OrderPdfFormat");
126
    my $pdfformat = C4::Context->preference("OrderPdfFormat");
127
    my @valid_pdfformats = qw(pdfformat::layout3pages pdfformat::layout2pages pdfformat::layout3pagesfr pdfformat::layout2pagesde);
127
    my @valid_pdfformats = qw(pdfformat::layout3pages pdfformat::layout2pages pdfformat::layout3pagesfr pdfformat::layout2pagesde pdfformat::layout2pagesdinde);
128
    if (grep {$_ eq $pdfformat} @valid_pdfformats) {
128
    if (grep {$_ eq $pdfformat} @valid_pdfformats) {
129
        $pdfformat = "Koha::$pdfformat";
129
        $pdfformat = "Koha::$pdfformat";
130
        my $pdfformat_filepath = File::Spec->catfile(split /::/, $pdfformat) . '.pm';
130
        my $pdfformat_filepath = File::Spec->catfile(split /::/, $pdfformat) . '.pm';
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref (-1 / +1 lines)
Lines 121-126 Acquisitions: Link Here
121
                  "pdfformat::layout3pages":   English 3-page
121
                  "pdfformat::layout3pages":   English 3-page
122
                  "pdfformat::layout3pagesfr": French 3-page
122
                  "pdfformat::layout3pagesfr": French 3-page
123
                  "pdfformat::layout2pagesde": German 2-page
123
                  "pdfformat::layout2pagesde": German 2-page
124
                  "pdfformat::layout2pagesdinde": German DIN-2-page
124
            - layout when printing basket groups.
125
            - layout when printing basket groups.
125
    EDIFACT:
126
    EDIFACT:
126
        -
127
        -
127
- 

Return to bug 27891