From 3c18d4c18fad5a0d470c7bdf1ac746a640f25099 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Sat, 17 Nov 2018 11:58:02 +0100 Subject: [PATCH] Bug 21853: Fix PDF export of basketgroups In recent versions of Perl, '.' is not included by default in @INC. This breaks PDF export of basketgroups. This patch moves acqui/pdfformat/*.pm files in Koha namespace so that they can be 'require'd without manipulating @INC Test plan: 1. Turn off Plack/Starman and test PDF export for every value of OrderPdfFormat system preference 2. Turn on Plack/Starman and test PDF export for every value of OrderPdfFormat system preference 3. Test on a dev install and a standard/package install Signed-off-by: Mark Tompsett Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens --- Koha/pdfformat/layout2pages.pm | 264 ++++++++++++++++++++++ Koha/pdfformat/layout2pagesde.pm | 264 ++++++++++++++++++++++ Koha/pdfformat/layout3pages.pm | 432 ++++++++++++++++++++++++++++++++++++ Koha/pdfformat/layout3pagesfr.pm | 433 +++++++++++++++++++++++++++++++++++++ acqui/basketgroup.pl | 31 ++-- acqui/pdfformat/layout2pages.pm | 265 ----------------------- acqui/pdfformat/layout2pagesde.pm | 265 ----------------------- acqui/pdfformat/layout3pages.pm | 433 ------------------------------------- acqui/pdfformat/layout3pagesfr.pm | 433 ------------------------------------- 9 files changed, 1408 insertions(+), 1412 deletions(-) create mode 100644 Koha/pdfformat/layout2pages.pm create mode 100644 Koha/pdfformat/layout2pagesde.pm create mode 100644 Koha/pdfformat/layout3pages.pm create mode 100644 Koha/pdfformat/layout3pagesfr.pm delete mode 100644 acqui/pdfformat/layout2pages.pm delete mode 100644 acqui/pdfformat/layout2pagesde.pm delete mode 100644 acqui/pdfformat/layout3pages.pm delete mode 100644 acqui/pdfformat/layout3pagesfr.pm diff --git a/Koha/pdfformat/layout2pages.pm b/Koha/pdfformat/layout2pages.pm new file mode 100644 index 0000000..90537c3 --- /dev/null +++ b/Koha/pdfformat/layout2pages.pm @@ -0,0 +1,264 @@ +package Koha::pdfformat::layout2pages; + +#example script to print a basketgroup +#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com + +# Copyright 2008-2009 BibLibre SARL +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. +use vars qw(@ISA @EXPORT); +use MIME::Base64; +use Modern::Perl; +use utf8; + +use Koha::Number::Price; +use Koha::DateUtils; +use Koha::Libraries; + +BEGIN { + use Exporter (); + our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + @ISA = qw(Exporter); + @EXPORT = qw(printpdf); +} + + +#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). +#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. +use constant mm => 25.4 / 72; +use constant in => 1 / 72; +use constant pt => 1; + +use PDF::API2; +#A4 paper specs +my ($height, $width) = (297, 210); +use PDF::Table; + +sub printorders { + my ($pdf, $basketgroup, $baskets, $orders) = @_; + + my $cur_format = C4::Context->preference("CurrencyFormat"); + + $pdf->mediabox($height/mm, $width/mm); + my $page = $pdf->page(); + + my $pdftable = new PDF::Table(); + + my $abaskets; + my $arrbasket; + my @keys = ('Basket (No.)', 'Document', 'Qty', 'RRP tax inc.', 'Discount', 'GST', 'Total tax exc.', 'Total tax inc.'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + push(@$abaskets, $arrbasket); + + my $titleinfo; + for my $basket (@$baskets){ + for my $line (@{$orders->{$basket->{basketno}}}) { + $arrbasket = undef; + $titleinfo = ""; + if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { + $titleinfo = $line->{title} . " / " . $line->{author} . + ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN: " . $line->{en} : '' ) . + ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . + ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); + } + else { # MARC21, NORMARC + $titleinfo = $line->{title} . " " . $line->{author} . + ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN: " . $line->{en} : '' ) . + ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . + ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); + } + push( @$arrbasket, + $basket->{basketno}, + $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), + $line->{quantity}, + Koha::Number::Price->new( $line->{rrp_tax_included} )->format, + Koha::Number::Price->new( $line->{discount} )->format . '%', + Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', + Koha::Number::Price->new( $line->{total_tax_excluded} )->format, + Koha::Number::Price->new( $line->{total_tax_included} )->format, + ); + push(@$abaskets, $arrbasket); + } + } + + $pdftable->table($pdf, $page, $abaskets, + x => 10/mm, + w => ($width - 20)/mm, + start_y => 285/mm, + next_y => 285/mm, + start_h => 260/mm, + next_h => 260/mm, + padding => 5, + padding_right => 5, + background_color_odd => "lightgray", + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 3/mm, + header_props => { + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 10, + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { justify => 'left' }, + { min_w => 90/mm }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + ], + ); + + $pdf->mediabox($width/mm, $height/mm); +} + +sub printhead { + my ($pdf, $basketgroup, $bookseller) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); + my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); + my $freedeliveryplace = $basketgroup->{freedeliveryplace}; + # get the subject + my $subject; + + # open 1st page (with the header) + my $page = $pdf->openpage(1); + + # create a text + my $text = $page->text; + + # print the libraryname in the header + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(30/mm, ($height-28.5)/mm); + $text->text($libraryname); + + # print order info, on the default PDF + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); + $text->translate(100/mm, ($height-5-48)/mm); + $text->text($basketgroup->{'id'}); + + # print the date + my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); + $text->translate(130/mm, ($height-5-48)/mm); + $text->text($today); + + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + + # print billing infos + $text->translate(100/mm, ($height-86)/mm); + $text->text($libraryname); + $text->translate(100/mm, ($height-97)/mm); + $text->text($billing_library->branchname); + $text->translate(100/mm, ($height-108.5)/mm); + $text->text($billing_library->branchphone); + $text->translate(100/mm, ($height-115.5)/mm); + $text->text($billing_library->branchfax); + $text->translate(100/mm, ($height-122.5)/mm); + $text->text($billing_library->branchaddress1); + $text->translate(100/mm, ($height-127.5)/mm); + $text->text($billing_library->branchaddress2); + $text->translate(100/mm, ($height-132.5)/mm); + $text->text($billing_library->branchaddress3); + $text->translate(100/mm, ($height-137.5)/mm); + $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); + $text->translate(100/mm, ($height-147.5)/mm); + $text->text($billing_library->branchemail); + + # print subject + $text->translate(100/mm, ($height-145.5)/mm); + $text->text($subject); + + # print bookseller infos + $text->translate(100/mm, ($height-180)/mm); + $text->text($bookseller->name); + $text->translate(100/mm, ($height-185)/mm); + $text->text($bookseller->postal); + $text->translate(100/mm, ($height-190)/mm); + $text->text($bookseller->address1); + $text->translate(100/mm, ($height-195)/mm); + $text->text($bookseller->address2); + $text->translate(100/mm, ($height-200)/mm); + $text->text($bookseller->address3); + $text->translate(100/mm, ($height-205)/mm); + $text->text($bookseller->accountnumber); + + # print delivery infos + $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); + $text->translate(50/mm, ($height-237)/mm); + if ($freedeliveryplace) { + my $start = 242; + my @fdp = split('\n', $freedeliveryplace); + foreach (@fdp) { + $text->text($_); + $text->translate( 50 / mm, ( $height - $start ) / mm ); + $start += 5; + } + } else { + $text->text( $delivery_library->branchaddress1 ); + $text->translate( 50 / mm, ( $height - 242 ) / mm ); + $text->text( $delivery_library->branchaddress2 ); + $text->translate( 50 / mm, ( $height - 247 ) / mm ); + $text->text( $delivery_library->branchaddress3 ); + $text->translate( 50 / mm, ( $height - 252 ) / mm ); + $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) ); + } + $text->translate(50/mm, ($height-262)/mm); + $text->text($basketgroup->{deliverycomment}); +} + +sub printfooters { + my $pdf = shift; + for ( 1..$pdf->pages ) { + my $page = $pdf->openpage($_); + my $text = $page->text; + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); + $text->translate(10/mm, 10/mm); + $text->text("Page $_ / ".$pdf->pages); + } +} + +sub printpdf { + my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; + # open the default PDF that will be used for base (1st page already filled) + my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pages.pdf'; + my $pdf = PDF::API2->open($pdf_template); + $pdf->pageLabel( 0, { + -style => 'roman', + } ); # start with roman numbering + # fill the 1st page (basketgroup information) + printhead($pdf, $basketgroup, $bookseller); + # fill other pages (orders) + printorders($pdf, $basketgroup, $baskets, $orders); + # print something on each page (usually the footer, but you could also put a header + printfooters($pdf); + return $pdf->stringify; +} + +1; diff --git a/Koha/pdfformat/layout2pagesde.pm b/Koha/pdfformat/layout2pagesde.pm new file mode 100644 index 0000000..aeee17b --- /dev/null +++ b/Koha/pdfformat/layout2pagesde.pm @@ -0,0 +1,264 @@ +package Koha::pdfformat::layout2pagesde; + +#example script to print a basketgroup +#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com + +# Copyright 2008-2009 BibLibre SARL +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. +use vars qw(@ISA @EXPORT); +use MIME::Base64; +use Modern::Perl; +use utf8; + +use Koha::Number::Price; +use Koha::DateUtils; +use Koha::Libraries; + +BEGIN { + use Exporter (); + our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + @ISA = qw(Exporter); + @EXPORT = qw(printpdf); +} + + +#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). +#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. +use constant mm => 25.4 / 72; +use constant in => 1 / 72; +use constant pt => 1; + +use PDF::API2; +#A4 paper specs +my ($height, $width) = (297, 210); +use PDF::Table; + +sub printorders { + my ($pdf, $basketgroup, $baskets, $orders) = @_; + + my $cur_format = C4::Context->preference("CurrencyFormat"); + + $pdf->mediabox($height/mm, $width/mm); + my $page = $pdf->page(); + + my $pdftable = new PDF::Table(); + + my $abaskets; + my $arrbasket; + my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + push(@$abaskets, $arrbasket); + + my $titleinfo; + for my $basket (@$baskets){ + for my $line (@{$orders->{$basket->{basketno}}}) { + $arrbasket = undef; + $titleinfo = ""; + if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { + $titleinfo = $line->{title} . " / " . $line->{author} . + ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN: " . $line->{en} : '' ) . + ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') . + ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); + } + else { # MARC21, NORMARC + $titleinfo = $line->{title} . " " . $line->{author} . + ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN: " . $line->{en} : '' ) . + ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') . + ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); + } + push( @$arrbasket, + $basket->{basketno}, + $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferantennotiz : ". $line->{order_vendornote} : '' ), $line->{quantity}, + $line->{quantity}, + Koha::Number::Price->new( $line->{rrp_tax_included} )->format, + Koha::Number::Price->new( $line->{discount} )->format . '%', + Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', + Koha::Number::Price->new( $line->{total_tax_excluded} )->format, + Koha::Number::Price->new( $line->{total_tax_included} )->format, + ); + push(@$abaskets, $arrbasket); + } + } + + $pdftable->table($pdf, $page, $abaskets, + x => 10/mm, + w => ($width - 20)/mm, + start_y => 285/mm, + next_y => 285/mm, + start_h => 260/mm, + next_h => 260/mm, + padding => 5, + padding_right => 5, + background_color_odd => "lightgray", + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 3/mm, + header_props => { + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 10, + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { justify => 'left' }, + { min_w => 90/mm }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + { justify => 'right' }, + ], + ); + + $pdf->mediabox($width/mm, $height/mm); +} + +sub printhead { + my ($pdf, $basketgroup, $bookseller) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); + my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); + my $freedeliveryplace = $basketgroup->{freedeliveryplace}; + # get the subject + my $subject; + + # open 1st page (with the header) + my $page = $pdf->openpage(1); + + # create a text + my $text = $page->text; + + # print the libraryname in the header + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(30/mm, ($height-28.5)/mm); + $text->text($libraryname); + + # print order info, on the default PDF + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); + $text->translate(100/mm, ($height-5-48)/mm); + $text->text($basketgroup->{'id'}); + + # print the date + my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); + $text->translate(130/mm, ($height-5-48)/mm); + $text->text($today); + + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + + # print billing infos + $text->translate(100/mm, ($height-86)/mm); + $text->text($libraryname); + $text->translate(100/mm, ($height-97)/mm); + $text->text($billing_library->branchname); + $text->translate(100/mm, ($height-108.5)/mm); + $text->text($billing_library->branchphone); + $text->translate(100/mm, ($height-115.5)/mm); + $text->text($billing_library->branchfax); + $text->translate(100/mm, ($height-122.5)/mm); + $text->text($billing_library->branchaddress1); + $text->translate(100/mm, ($height-127.5)/mm); + $text->text($billing_library->branchaddress2); + $text->translate(100/mm, ($height-132.5)/mm); + $text->text($billing_library->branchaddress3); + $text->translate(100/mm, ($height-137.5)/mm); + $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); + $text->translate(100/mm, ($height-147.5)/mm); + $text->text($billing_library->branchemail); + + # print subject + $text->translate(100/mm, ($height-145.5)/mm); + $text->text($subject); + + # print bookseller infos + $text->translate(100/mm, ($height-180)/mm); + $text->text($bookseller->name); + $text->translate(100/mm, ($height-185)/mm); + $text->text($bookseller->postal); + $text->translate(100/mm, ($height-190)/mm); + $text->text($bookseller->address1); + $text->translate(100/mm, ($height-195)/mm); + $text->text($bookseller->address2); + $text->translate(100/mm, ($height-200)/mm); + $text->text($bookseller->address3); + $text->translate(100/mm, ($height-205)/mm); + $text->text($bookseller->accountnumber); + + # print delivery infos + $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); + $text->translate(50/mm, ($height-237)/mm); + if ($freedeliveryplace) { + my $start = 242; + my @fdp = split('\n', $freedeliveryplace); + foreach (@fdp) { + $text->text($_); + $text->translate( 50 / mm, ( $height - $start ) / mm ); + $start += 5; + } + } else { + $text->text( $delivery_library->branchaddress1 ); + $text->translate( 50 / mm, ( $height - 242 ) / mm ); + $text->text( $delivery_library->branchaddress2 ); + $text->translate( 50 / mm, ( $height - 247 ) / mm ); + $text->text( $delivery_library->branchaddress3 ); + $text->translate( 50 / mm, ( $height - 252 ) / mm ); + $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) ); + } + $text->translate(50/mm, ($height-262)/mm); + $text->text($basketgroup->{deliverycomment}); +} + +sub printfooters { + my $pdf = shift; + for ( 1..$pdf->pages ) { + my $page = $pdf->openpage($_); + my $text = $page->text; + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); + $text->translate(10/mm, 10/mm); + $text->text("Seite $_ / ".$pdf->pages); + } +} + +sub printpdf { + my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; + # open the default PDF that will be used for base (1st page already filled) + my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesde.pdf'; + my $pdf = PDF::API2->open($pdf_template); + $pdf->pageLabel( 0, { + -style => 'roman', + } ); # start with roman numbering + # fill the 1st page (basketgroup information) + printhead($pdf, $basketgroup, $bookseller); + # fill other pages (orders) + printorders($pdf, $basketgroup, $baskets, $orders); + # print something on each page (usually the footer, but you could also put a header + printfooters($pdf); + return $pdf->stringify; +} + +1; diff --git a/Koha/pdfformat/layout3pages.pm b/Koha/pdfformat/layout3pages.pm new file mode 100644 index 0000000..d02160e --- /dev/null +++ b/Koha/pdfformat/layout3pages.pm @@ -0,0 +1,432 @@ +package Koha::pdfformat::layout3pages; + +#example script to print a basketgroup +#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com + +# Copyright 2008-2009 BibLibre SARL +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. +use vars qw(@ISA @EXPORT); +use MIME::Base64; +use List::MoreUtils qw/uniq/; +use Modern::Perl; +use utf8; + +use Koha::Number::Price; +use Koha::DateUtils; +use Koha::Libraries; + +BEGIN { + use Exporter (); + our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + @ISA = qw(Exporter); + @EXPORT = qw(printpdf); +} + + +#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). +#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. +use constant mm => 25.4 / 72; +use constant in => 1 / 72; +use constant pt => 1; + +use PDF::API2; +#A4 paper specs +my ($height, $width) = (297, 210); +use PDF::Table; + +sub printorders { + my ($pdf, $basketgroup, $baskets, $orders) = @_; + + my $cur_format = C4::Context->preference("CurrencyFormat"); + + $pdf->mediabox($height/mm, $width/mm); + my $number = 3; + for my $basket (@$baskets){ + my $page = $pdf->page(); + my $billing_library = Koha::Libraries->find( $basket->{billingplace} ); + my $delivery_library = Koha::Libraries->find( $basket->{deliveryplace} ); + + # print basket header (box) + my $box = $page->gfx; + $box->rectxy(($width - 10)/mm, ($height - 5)/mm, 10/mm, ($height - 25)/mm); + $box->stroke; +# $box->restore(); + + # create a text + my $text = $page->text; + # add basketgroup number + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(20/mm, ($height-15)/mm); + $text->text("Order no. ".$basketgroup->{'id'}.". Basket no. ".$basket->{basketno}.". ".$basket->{booksellernote}); + $text->translate(20/mm, ($height-20)/mm); + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + $text->text( ( $billing_library ? "Billing at " . $billing_library->branchname : "" ) + . ( $billing_library and $delivery_library ? " and " : "" ) + . ( $delivery_library ? "delivery at " . $delivery_library->branchname : "" ) + ); + + my $pdftable = new PDF::Table(); + my $abaskets; + my $arrbasket; + my @keys = ('Document', 'Qty', 'RRP tax exc.', 'RRP tax inc.', 'Discount', 'Discount price', 'GST rate', 'Total tax exc.', 'Total tax inc.'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + push(@$abaskets, $arrbasket); + + my $titleinfo; + foreach my $line (@{$orders->{$basket->{basketno}}}) { + $arrbasket = undef; + $titleinfo = ""; + if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { + $titleinfo = $line->{title} . " / " . $line->{author} . + ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN: " . $line->{en} : '' ) . + ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . + ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); + } + else { # MARC21, NORMARC + $titleinfo = $line->{title} . " " . $line->{author} . + ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN: " . $line->{en} : '' ) . + ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . + ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); + } + push( @$arrbasket, + $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), + $line->{quantity}, + Koha::Number::Price->new( $line->{rrp_tax_excluded} )->format, + Koha::Number::Price->new( $line->{rrp_tax_included} )->format, + Koha::Number::Price->new( $line->{discount} )->format . '%', + Koha::Number::Price->new( $line->{rrp_tax_excluded} - $line->{ecost_tax_excluded})->format, + Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', + Koha::Number::Price->new( $line->{total_tax_excluded} )->format, + Koha::Number::Price->new( $line->{total_tax_included} )->format, + ); + push(@$abaskets, $arrbasket); + } + + $pdftable->table($pdf, $page, $abaskets, + x => 10/mm, + w => ($width - 20)/mm, + start_y => 270/mm, + next_y => 285/mm, + start_h => 250/mm, + next_h => 250/mm, + padding => 5, + padding_right => 5, + background_color_odd => "lightgray", + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 3/mm, + header_props => { + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 9, + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { + min_w => 85/mm, # Minimum column width. + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + ], + ); + } + $pdf->mediabox($width/mm, $height/mm); +} + +sub printbaskets { + my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + + my $cur_format = C4::Context->preference("CurrencyFormat"); + + $pdf->mediabox($width/mm, $height/mm); + my $page = $pdf->openpage(2); + # create a text + my $text = $page->text; + + # add basketgroup number + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(($width-40)/mm, ($height-53)/mm); + $text->text("".$basketgroup->{'id'}); + # print the libraryname in the header + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(30/mm, ($height-28.5)/mm); + $text->text($libraryname); + my $pdftable = new PDF::Table(); + my $abaskets; + my $arrbasket; + # header of the table + my @keys = ('Lot', 'Basket (No.)','Total RRP tax exc.', 'Total RRP tax inc.', 'GST rate', 'GST', 'Total discount', 'Total tax exc.', 'Total tax inc.'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + my ($grandtotal_rrp_tax_included, $grandtotal_rrp_tax_excluded, $grandtotal_tax_included, $grandtotal_tax_excluded, $grandtotaltax_value, $grandtotaldiscount); + # calculate each basket total + push(@$abaskets, $arrbasket); + for my $basket (@$hbaskets) { + my @gst; + $arrbasket = undef; + my ($total_rrp_tax_excluded, $total_rrp_tax_included, $total_tax_excluded, $total_tax_included, $totaltax_value, $totaldiscount); + my $ords = $orders->{$basket->{basketno}}; + my $ordlength = @$ords; + foreach my $ord (@$ords) { + $total_tax_excluded += $ord->{total_tax_excluded}; + $total_tax_included += $ord->{total_tax_included}; + $totaltax_value += $ord->{tax_value}; + $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity}; + $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity}; + $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity}; + push @gst, $ord->{tax_rate}; + } + @gst = uniq map { $_ * 100 } @gst; + $grandtotal_rrp_tax_excluded += $total_rrp_tax_excluded; + $grandtotal_rrp_tax_included += $total_rrp_tax_included; + $grandtotal_tax_included += $total_tax_included; + $grandtotal_tax_excluded += $total_tax_excluded; + $grandtotaltax_value += $totaltax_value; + $grandtotaldiscount += $totaldiscount; + my @gst_string = + map { Koha::Number::Price->new($_)->format . '%' } @gst; + push(@$arrbasket, + $basket->{contractname}, + $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')', + Koha::Number::Price->new( $total_rrp_tax_excluded )->format, + Koha::Number::Price->new( $total_rrp_tax_included )->format, + "@gst_string", + Koha::Number::Price->new( $totaltax_value )->format, + Koha::Number::Price->new( $totaldiscount )->format, + Koha::Number::Price->new( $total_tax_excluded )->format, + Koha::Number::Price->new( $total_tax_included )->format, + ); + push(@$abaskets, $arrbasket); + } + # now, push total + undef $arrbasket; + push @$arrbasket, + '', + 'Total', + Koha::Number::Price->new( $grandtotal_rrp_tax_excluded )->format, + Koha::Number::Price->new( $grandtotal_rrp_tax_included )->format, + '', + Koha::Number::Price->new( $grandtotaltax_value )->format, + Koha::Number::Price->new( $grandtotaldiscount )->format, + Koha::Number::Price->new( $grandtotal_tax_excluded )->format, + Koha::Number::Price->new( $grandtotal_tax_included )->format; + push @$abaskets,$arrbasket; + # height is width and width is height in this function, as the pdf is in landscape mode for the Tables. + + $pdftable->table($pdf, $page, $abaskets, + x => 5/mm, + w => ($width - 10)/mm, + start_y => 230/mm, + next_y => 230/mm, + start_h => 230/mm, + next_h => 230/mm, + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 3/mm, + padding => 5, + padding_right => 10, + background_color_odd => "lightgray", + header_props => { + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { + }, + { + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + ], + ); + $pdf->mediabox($height/mm, $width/mm); +} + +sub printhead { + my ($pdf, $basketgroup, $bookseller) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); + my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); + my $freedeliveryplace = $basketgroup->{freedeliveryplace}; + # get the subject + my $subject; + + # open 1st page (with the header) + my $page = $pdf->openpage(1); + + # create a text + my $text = $page->text; + + # print the libraryname in the header + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(30/mm, ($height-28.5)/mm); + $text->text($libraryname); + + # print order info, on the default PDF + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); + $text->translate(100/mm, ($height-5-48)/mm); + $text->text($basketgroup->{'id'}); + + # print the date + my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); + $text->translate(130/mm, ($height-5-48)/mm); + $text->text($today); + + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + + # print billing infos + $text->translate(100/mm, ($height-86)/mm); + $text->text($libraryname); + $text->translate(100/mm, ($height-97)/mm); + $text->text($billing_library->branchname); + $text->translate(100/mm, ($height-108.5)/mm); + $text->text($billing_library->branchphone); + $text->translate(100/mm, ($height-115.5)/mm); + $text->text($billing_library->branchfax); + $text->translate(100/mm, ($height-122.5)/mm); + $text->text($billing_library->branchaddress1); + $text->translate(100/mm, ($height-127.5)/mm); + $text->text($billing_library->branchaddress2); + $text->translate(100/mm, ($height-132.5)/mm); + $text->text($billing_library->branchaddress3); + $text->translate(100/mm, ($height-137.5)/mm); + $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); + $text->translate(100/mm, ($height-147.5)/mm); + $text->text($billing_library->branchemail); + + # print subject + $text->translate(100/mm, ($height-145.5)/mm); + $text->text($subject); + + # print bookseller infos + $text->translate(100/mm, ($height-180)/mm); + $text->text($bookseller->name); + $text->translate(100/mm, ($height-185)/mm); + $text->text($bookseller->postal); + $text->translate(100/mm, ($height-190)/mm); + $text->text($bookseller->address1); + $text->translate(100/mm, ($height-195)/mm); + $text->text($bookseller->address2); + $text->translate(100/mm, ($height-200)/mm); + $text->text($bookseller->address3); + $text->translate(100/mm, ($height-205)/mm); + $text->text($bookseller->accountnumber); + + # print delivery infos + $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); + $text->translate(50/mm, ($height-237)/mm); + if ($freedeliveryplace) { + my $start = 242; + my @fdp = split('\n', $freedeliveryplace); + foreach (@fdp) { + $text->text($_); + $text->translate( 50 / mm, ( $height - $start ) / mm ); + $start += 5; + } + } else { + $text->text($delivery_library->branchaddress1); + $text->translate(50/mm, ($height-242)/mm); + $text->text($delivery_library->branchaddress2); + $text->translate(50/mm, ($height-247)/mm); + $text->text($delivery_library->branchaddress3); + $text->translate(50/mm, ($height-252)/mm); + $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry)); + } + $text->translate(50/mm, ($height-262)/mm); + $text->text($basketgroup->{deliverycomment}); +} + +sub printfooters { + my ($pdf) = @_; + for (my $i=1;$i <= $pdf->pages;$i++) { + my $page = $pdf->openpage($i); + my $text = $page->text; + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); + $text->translate(10/mm, 10/mm); + $text->text("Page $i / ".$pdf->pages); + } +} + +sub printpdf { + my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; + # open the default PDF that will be used for base (1st page already filled) + my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout3pages.pdf'; + my $pdf = PDF::API2->open($pdf_template); + $pdf->pageLabel( 0, { + -style => 'roman', + } ); # start with roman numbering + # fill the 1st page (basketgroup information) + printhead($pdf, $basketgroup, $bookseller); + # fill the 2nd page (orders summary) + printbaskets($pdf, $basketgroup, $baskets, $bookseller, $GST, $orders); + # fill other pages (orders) + printorders($pdf, $basketgroup, $baskets, $orders); + # print something on each page (usually the footer, but you could also put a header + printfooters($pdf); + return $pdf->stringify; +} + +1; diff --git a/Koha/pdfformat/layout3pagesfr.pm b/Koha/pdfformat/layout3pagesfr.pm new file mode 100644 index 0000000..b4bdf78 --- /dev/null +++ b/Koha/pdfformat/layout3pagesfr.pm @@ -0,0 +1,433 @@ +package Koha::pdfformat::layout3pagesfr; + +#example script to print a basketgroup +#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com + +# Copyright 2008-2009, 2013 BibLibre SARL +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, see . + +#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. +package pdfformat::layout3pagesfr; +use vars qw(@ISA @EXPORT); +use MIME::Base64; +use List::MoreUtils qw/uniq/; +use Modern::Perl; +use utf8; + +use Koha::Number::Price; +use Koha::DateUtils; +use Koha::Libraries; + +BEGIN { + use Exporter (); + our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + @ISA = qw(Exporter); + @EXPORT = qw(printpdf); +} + + +#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). +#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. +use constant mm => 25.4 / 72; +use constant in => 1 / 72; +use constant pt => 1; + +use PDF::API2; +#A4 paper specs +my ($height, $width) = (297, 210); +use PDF::Table; + +sub printorders { + my ($pdf, $basketgroup, $baskets, $orders) = @_; + + my $cur_format = C4::Context->preference("CurrencyFormat"); + + $pdf->mediabox($height/mm, $width/mm); + my $number = 3; + for my $basket (@$baskets){ + my $page = $pdf->page(); + my $billing_library = Koha::Libraries->find( $basket->{billingplace} ); + my $delivery_library = Koha::Libraries->find( $basket->{deliveryplace} ); + + # print basket header (box) + my $box = $page->gfx; + $box->rectxy(($width - 10)/mm, ($height - 5)/mm, 10/mm, ($height - 25)/mm); + $box->stroke; +# $box->restore(); + + # create a text + my $text = $page->text; + # add basketgroup number + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(20/mm, ($height-15)/mm); + $text->text("Commande N°".$basketgroup->{'id'}.". Panier N° ".$basket->{basketno}.". ".$basket->{booksellernote}); + $text->translate(20/mm, ($height-20)/mm); + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + $text->text( ( $billing_library ? "Facturation à " . $billing_library->branchname : "" ) + . ( $billing_library and $delivery_library ? " et " : "" ) + . ( $delivery_library ? "livraison à " . $delivery_library->branchname : "" ) + ); + + my $pdftable = new PDF::Table(); + my $abaskets; + my $arrbasket; + my @keys = ('Document', 'Qté', 'Prix', 'Prix net', '% Remise', 'Remise', 'Taux TVA', 'Total HT', 'Total TTC'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + push(@$abaskets, $arrbasket); + + my $titleinfo; + foreach my $line (@{$orders->{$basket->{basketno}}}) { + $arrbasket = undef; + $titleinfo = ""; + if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { + $titleinfo = $line->{title} . " / " . $line->{author} . + ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN : " . $line->{en} : '' ) . + ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' publié par '. $line->{publishercode} : '') . + ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); + } + else { # MARC21, NORMARC + $titleinfo = $line->{title} . " " . $line->{author} . + ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) . + ( $line->{en} ? " EN : " . $line->{en} : '' ) . + ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . + ( $line->{edition} ? ", " . $line->{edition} : '' ) . + ( $line->{publishercode} ? ' publié par '. $line->{publishercode} : '') . + ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); + } + + push( @$arrbasket, + $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote pour le fournisseur : ". $line->{order_vendornote} : '' ), + $line->{quantity}, + Koha::Number::Price->new( $line->{rrp_tax_excluded})->format, + Koha::Number::Price->new( $line->{rrp_tax_included})->format, + Koha::Number::Price->new( $line->{discount})->format.'%', + Koha::Number::Price->new( $line->{rrp_tax_excluded} - $line->{ecost_tax_excluded})->format, + Koha::Number::Price->new( $line->{tax_rate} * 100)->format.'%', + Koha::Number::Price->new( $line->{total_tax_excluded})->format, + Koha::Number::Price->new( $line->{total_tax_included})->format, + ); + push(@$abaskets, $arrbasket); + } + + $pdftable->table($pdf, $page, $abaskets, + x => 10/mm, + w => ($width - 20)/mm, + start_y => 270/mm, + next_y => 285/mm, + start_h => 250/mm, + next_h => 250/mm, + padding => 5, + padding_right => 5, + background_color_odd => "lightgray", + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 3/mm, + header_props => { + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 9, + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { + min_w => 85/mm, # Minimum column width. + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + { + justify => 'right', # One of left|right , + }, + ], + ); + } + $pdf->mediabox($width/mm, $height/mm); +} + +sub printbaskets { + my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + + my $cur_format = C4::Context->preference("CurrencyFormat"); + + $pdf->mediabox($width/mm, $height/mm); + my $page = $pdf->openpage(2); + # create a text + my $text = $page->text; + + # add basketgroup number + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(($width-40)/mm, ($height-53)/mm); + $text->text("".$basketgroup->{'id'}); + # print the libraryname in the header + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(30/mm, ($height-28.5)/mm); + $text->text($libraryname); + my $pdftable = new PDF::Table(); + my $abaskets; + my $arrbasket; + # header of the table + my @keys = ('Lot', 'Panier', 'Prix', 'Prix net', 'Taux TVA', 'TVA', 'Remise', 'Total HT', 'Total TTC'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + my ($grandtotal_rrp_tax_included, $grandtotal_rrp_tax_excluded, $grandtotal_tax_included, $grandtotal_tax_excluded, $grandtotaltax_value, $grandtotaldiscount); + # calculate each basket total + push(@$abaskets, $arrbasket); + for my $basket (@$hbaskets) { + my @gst; + $arrbasket = undef; + my ($total_rrp_tax_excluded, $total_rrp_tax_included, $total_tax_excluded, $total_tax_included, $totaltax_value, $totaldiscount); + my $ords = $orders->{$basket->{basketno}}; + my $ordlength = @$ords; + foreach my $ord (@$ords) { + $total_tax_excluded += $ord->{total_tax_excluded}; + $total_tax_included += $ord->{total_tax_included}; + $totaltax_value += $ord->{tax_value}; + $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity}; + $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity}; + $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity}; + push @gst, $ord->{tax_rate}; + } + @gst = uniq map { $_ * 100 } @gst; + $grandtotal_rrp_tax_excluded += $total_rrp_tax_excluded; + $grandtotal_rrp_tax_included += $total_rrp_tax_included; + $grandtotal_tax_included += $total_tax_included; + $grandtotal_tax_excluded += $total_tax_excluded; + $grandtotaltax_value += $totaltax_value; + $grandtotaldiscount += $totaldiscount; + my @gst_string = + map { Koha::Number::Price->new($_)->format . '%' } @gst; + push(@$arrbasket, + $basket->{contractname}, + $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')', + Koha::Number::Price->new( $total_rrp_tax_excluded )->format, + Koha::Number::Price->new( $total_rrp_tax_included )->format, + "@gst_string", + Koha::Number::Price->new( $totaltax_value )->format, + Koha::Number::Price->new( $totaldiscount )->format, + Koha::Number::Price->new( $total_tax_excluded )->format, + Koha::Number::Price->new( $total_tax_included )->format, + ); + push(@$abaskets, $arrbasket); + } + # now, push total + undef $arrbasket; + push @$arrbasket, + '', + 'Total', + Koha::Number::Price->new( $grandtotal_rrp_tax_excluded )->format, + Koha::Number::Price->new( $grandtotal_rrp_tax_included )->format, + '', + Koha::Number::Price->new( $grandtotaltax_value )->format, + Koha::Number::Price->new( $grandtotaldiscount )->format, + Koha::Number::Price->new( $grandtotal_tax_excluded )->format, + Koha::Number::Price->new( $grandtotal_tax_included )->format; + push @$abaskets,$arrbasket; + # height is width and width is height in this function, as the pdf is in landscape mode for the Tables. + + $pdftable->table($pdf, $page, $abaskets, + x => 5/mm, + w => ($width - 10)/mm, + start_y => 230/mm, + next_y => 230/mm, + start_h => 230/mm, + next_h => 230/mm, + font => $pdf->corefont("Times", -encoding => "utf8"), + font_size => 3/mm, + padding => 5, + padding_right => 10, + background_color_odd => "lightgray", + header_props => { + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { + }, + { + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + ], + ); + $pdf->mediabox($height/mm, $width/mm); +} + +sub printhead { + my ($pdf, $basketgroup, $bookseller) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); + my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); + my $freedeliveryplace = $basketgroup->{freedeliveryplace}; + # get the subject + my $subject; + + # open 1st page (with the header) + my $page = $pdf->openpage(1); + + # create a text + my $text = $page->text; + + # print the libraryname in the header + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); + $text->translate(30/mm, ($height-28.5)/mm); + $text->text($libraryname); + + # print order info, on the default PDF + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); + $text->translate(100/mm, ($height-5-48)/mm); + $text->text($basketgroup->{'id'}); + + # print the date + my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); + $text->translate(130/mm, ($height-5-48)/mm); + $text->text($today); + + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + + # print billing infos + $text->translate(100/mm, ($height-86)/mm); + $text->text($libraryname); + $text->translate(100/mm, ($height-97)/mm); + $text->text($billing_library->branchname); + $text->translate(100/mm, ($height-108.5)/mm); + $text->text($billing_library->branchphone); + $text->translate(100/mm, ($height-115.5)/mm); + $text->text($billing_library->branchfax); + $text->translate(100/mm, ($height-122.5)/mm); + $text->text($billing_library->branchaddress1); + $text->translate(100/mm, ($height-127.5)/mm); + $text->text($billing_library->branchaddress2); + $text->translate(100/mm, ($height-132.5)/mm); + $text->text($billing_library->branchaddress3); + $text->translate(100/mm, ($height-137.5)/mm); + $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); + $text->translate(100/mm, ($height-147.5)/mm); + $text->text($billing_library->branchemail); + + # print subject + $text->translate(100/mm, ($height-145.5)/mm); + $text->text($subject); + + # print bookseller infos + $text->translate(100/mm, ($height-180)/mm); + $text->text($bookseller->name); + $text->translate(100/mm, ($height-185)/mm); + $text->text($bookseller->postal); + $text->translate(100/mm, ($height-190)/mm); + $text->text($bookseller->address1); + $text->translate(100/mm, ($height-195)/mm); + $text->text($bookseller->address2); + $text->translate(100/mm, ($height-200)/mm); + $text->text($bookseller->address3); + $text->translate(100/mm, ($height-205)/mm); + $text->text($bookseller->accountnumber); + + # print delivery infos + $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); + $text->translate(50/mm, ($height-237)/mm); + if ($freedeliveryplace) { + my $start = 242; + my @fdp = split('\n', $freedeliveryplace); + foreach (@fdp) { + $text->text($_); + $text->translate( 50 / mm, ( $height - $start ) / mm ); + $start += 5; + } + } else { + $text->text($delivery_library->branchaddress1); + $text->translate(50/mm, ($height-242)/mm); + $text->text($delivery_library->branchaddress2); + $text->translate(50/mm, ($height-247)/mm); + $text->text($delivery_library->branchaddress3); + $text->translate(50/mm, ($height-252)/mm); + $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry)); + } + $text->translate(50/mm, ($height-262)/mm); + $text->text($basketgroup->{deliverycomment}); +} + +sub printfooters { + my ($pdf) = @_; + for (my $i=1;$i <= $pdf->pages;$i++) { + my $page = $pdf->openpage($i); + my $text = $page->text; + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); + $text->translate(10/mm, 10/mm); + $text->text("Page $i / ".$pdf->pages); + } +} + +sub printpdf { + my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; + # open the default PDF that will be used for base (1st page already filled) + my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout3pagesfr.pdf'; + my $pdf = PDF::API2->open($pdf_template); + $pdf->pageLabel( 0, { + -style => 'roman', + } ); # start with roman numbering + # fill the 1st page (basketgroup information) + printhead($pdf, $basketgroup, $bookseller); + # fill the 2nd page (orders summary) + printbaskets($pdf, $basketgroup, $baskets, $bookseller, $GST, $orders); + # fill other pages (orders) + printorders($pdf, $basketgroup, $baskets, $orders); + # print something on each page (usually the footer, but you could also put a header + printfooters($pdf); + return $pdf->stringify; +} + +1; diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 05c505a..e1cba84 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -49,6 +49,7 @@ use Carp; use C4::Auth; use C4::Output; use CGI qw ( -utf8 ); +use File::Spec; use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/; use Koha::EDI qw/create_edi_order get_edifact_ean/; @@ -123,29 +124,27 @@ sub displaybasketgroups { sub printbasketgrouppdf{ my ($basketgroupid) = @_; - + my $pdfformat = C4::Context->preference("OrderPdfFormat"); - if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr' - || $pdfformat eq 'pdfformat::layout2pagesde'){ - eval { - eval "require $pdfformat"; - import $pdfformat; - }; - if ($@){ - } + my @valid_pdfformats = qw(pdfformat::layout3pages pdfformat::layout2pages pdfformat::layout3pagesfr pdfformat::layout2pagesde); + if (grep {$_ eq $pdfformat} @valid_pdfformats) { + $pdfformat = "Koha::$pdfformat"; + my $pdfformat_filepath = File::Spec->catfile(split /::/, $pdfformat) . '.pm'; + require $pdfformat_filepath; + import $pdfformat; } else { - print $input->header; - print $input->start_html; # FIXME Should do a nicer page - print "

Invalid PDF Format set

"; - print "Please go to the systempreferences and set a valid pdfformat"; - exit; + print $input->header; + print $input->start_html; # FIXME Should do a nicer page + print "

Invalid PDF Format set

"; + print "Please go to the systempreferences and set a valid pdfformat"; + exit; } - + my $basketgroup = GetBasketgroup($basketgroupid); my $bookseller = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} ); my $baskets = GetBasketsByBasketgroup($basketgroupid); - + my %orders; for my $basket (@$baskets) { my @ba_orders; diff --git a/acqui/pdfformat/layout2pages.pm b/acqui/pdfformat/layout2pages.pm deleted file mode 100644 index 0d2a6e7..0000000 --- a/acqui/pdfformat/layout2pages.pm +++ /dev/null @@ -1,265 +0,0 @@ -#!/usr/bin/perl - -#example script to print a basketgroup -#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com - -# Copyright 2008-2009 BibLibre SARL -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout2pages; -use vars qw(@ISA @EXPORT); -use MIME::Base64; -use Modern::Perl; -use utf8; - -use Koha::Number::Price; -use Koha::DateUtils; -use Koha::Libraries; - -BEGIN { - use Exporter (); - our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); - @ISA = qw(Exporter); - @EXPORT = qw(printpdf); -} - - -#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). -#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. -use constant mm => 25.4 / 72; -use constant in => 1 / 72; -use constant pt => 1; - -use PDF::API2; -#A4 paper specs -my ($height, $width) = (297, 210); -use PDF::Table; - -sub printorders { - my ($pdf, $basketgroup, $baskets, $orders) = @_; - - my $cur_format = C4::Context->preference("CurrencyFormat"); - - $pdf->mediabox($height/mm, $width/mm); - my $page = $pdf->page(); - - my $pdftable = new PDF::Table(); - - my $abaskets; - my $arrbasket; - my @keys = ('Basket (No.)', 'Document', 'Qty', 'RRP tax inc.', 'Discount', 'GST', 'Total tax exc.', 'Total tax inc.'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - push(@$abaskets, $arrbasket); - - my $titleinfo; - for my $basket (@$baskets){ - for my $line (@{$orders->{$basket->{basketno}}}) { - $arrbasket = undef; - $titleinfo = ""; - if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { - $titleinfo = $line->{title} . " / " . $line->{author} . - ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN: " . $line->{en} : '' ) . - ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . - ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); - } - else { # MARC21, NORMARC - $titleinfo = $line->{title} . " " . $line->{author} . - ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN: " . $line->{en} : '' ) . - ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . - ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); - } - push( @$arrbasket, - $basket->{basketno}, - $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), - $line->{quantity}, - Koha::Number::Price->new( $line->{rrp_tax_included} )->format, - Koha::Number::Price->new( $line->{discount} )->format . '%', - Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', - Koha::Number::Price->new( $line->{total_tax_excluded} )->format, - Koha::Number::Price->new( $line->{total_tax_included} )->format, - ); - push(@$abaskets, $arrbasket); - } - } - - $pdftable->table($pdf, $page, $abaskets, - x => 10/mm, - w => ($width - 20)/mm, - start_y => 285/mm, - next_y => 285/mm, - start_h => 260/mm, - next_h => 260/mm, - padding => 5, - padding_right => 5, - background_color_odd => "lightgray", - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 3/mm, - header_props => { - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 10, - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { justify => 'left' }, - { min_w => 90/mm }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - ], - ); - - $pdf->mediabox($width/mm, $height/mm); -} - -sub printhead { - my ($pdf, $basketgroup, $bookseller) = @_; - - # get library name - my $libraryname = C4::Context->preference("LibraryName"); - my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); - my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); - my $freedeliveryplace = $basketgroup->{freedeliveryplace}; - # get the subject - my $subject; - - # open 1st page (with the header) - my $page = $pdf->openpage(1); - - # create a text - my $text = $page->text; - - # print the libraryname in the header - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(30/mm, ($height-28.5)/mm); - $text->text($libraryname); - - # print order info, on the default PDF - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); - $text->translate(100/mm, ($height-5-48)/mm); - $text->text($basketgroup->{'id'}); - - # print the date - my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); - $text->translate(130/mm, ($height-5-48)/mm); - $text->text($today); - - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - - # print billing infos - $text->translate(100/mm, ($height-86)/mm); - $text->text($libraryname); - $text->translate(100/mm, ($height-97)/mm); - $text->text($billing_library->branchname); - $text->translate(100/mm, ($height-108.5)/mm); - $text->text($billing_library->branchphone); - $text->translate(100/mm, ($height-115.5)/mm); - $text->text($billing_library->branchfax); - $text->translate(100/mm, ($height-122.5)/mm); - $text->text($billing_library->branchaddress1); - $text->translate(100/mm, ($height-127.5)/mm); - $text->text($billing_library->branchaddress2); - $text->translate(100/mm, ($height-132.5)/mm); - $text->text($billing_library->branchaddress3); - $text->translate(100/mm, ($height-137.5)/mm); - $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); - $text->translate(100/mm, ($height-147.5)/mm); - $text->text($billing_library->branchemail); - - # print subject - $text->translate(100/mm, ($height-145.5)/mm); - $text->text($subject); - - # print bookseller infos - $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->name); - $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->postal); - $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->address1); - $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->address2); - $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->address3); - $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->accountnumber); - - # print delivery infos - $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); - $text->translate(50/mm, ($height-237)/mm); - if ($freedeliveryplace) { - my $start = 242; - my @fdp = split('\n', $freedeliveryplace); - foreach (@fdp) { - $text->text($_); - $text->translate( 50 / mm, ( $height - $start ) / mm ); - $start += 5; - } - } else { - $text->text( $delivery_library->branchaddress1 ); - $text->translate( 50 / mm, ( $height - 242 ) / mm ); - $text->text( $delivery_library->branchaddress2 ); - $text->translate( 50 / mm, ( $height - 247 ) / mm ); - $text->text( $delivery_library->branchaddress3 ); - $text->translate( 50 / mm, ( $height - 252 ) / mm ); - $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) ); - } - $text->translate(50/mm, ($height-262)/mm); - $text->text($basketgroup->{deliverycomment}); -} - -sub printfooters { - my $pdf = shift; - for ( 1..$pdf->pages ) { - my $page = $pdf->openpage($_); - my $text = $page->text; - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); - $text->translate(10/mm, 10/mm); - $text->text("Page $_ / ".$pdf->pages); - } -} - -sub printpdf { - my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; - # open the default PDF that will be used for base (1st page already filled) - my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pages.pdf'; - my $pdf = PDF::API2->open($pdf_template); - $pdf->pageLabel( 0, { - -style => 'roman', - } ); # start with roman numbering - # fill the 1st page (basketgroup information) - printhead($pdf, $basketgroup, $bookseller); - # fill other pages (orders) - printorders($pdf, $basketgroup, $baskets, $orders); - # print something on each page (usually the footer, but you could also put a header - printfooters($pdf); - return $pdf->stringify; -} - -1; diff --git a/acqui/pdfformat/layout2pagesde.pm b/acqui/pdfformat/layout2pagesde.pm deleted file mode 100644 index 63269df..0000000 --- a/acqui/pdfformat/layout2pagesde.pm +++ /dev/null @@ -1,265 +0,0 @@ -#!/usr/bin/perl - -#example script to print a basketgroup -#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com - -# Copyright 2008-2009 BibLibre SARL -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout2pagesde; -use vars qw(@ISA @EXPORT); -use MIME::Base64; -use Modern::Perl; -use utf8; - -use Koha::Number::Price; -use Koha::DateUtils; -use Koha::Libraries; - -BEGIN { - use Exporter (); - our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); - @ISA = qw(Exporter); - @EXPORT = qw(printpdf); -} - - -#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). -#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. -use constant mm => 25.4 / 72; -use constant in => 1 / 72; -use constant pt => 1; - -use PDF::API2; -#A4 paper specs -my ($height, $width) = (297, 210); -use PDF::Table; - -sub printorders { - my ($pdf, $basketgroup, $baskets, $orders) = @_; - - my $cur_format = C4::Context->preference("CurrencyFormat"); - - $pdf->mediabox($height/mm, $width/mm); - my $page = $pdf->page(); - - my $pdftable = new PDF::Table(); - - my $abaskets; - my $arrbasket; - my @keys = ('Bestellung', 'Titel', 'Anz.', 'Preis inkl. MWSt.', 'Rabatt', 'MWSt.', 'Gesamt, exkl. MWSt.', 'Gesamt inkl. MWSt.'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - push(@$abaskets, $arrbasket); - - my $titleinfo; - for my $basket (@$baskets){ - for my $line (@{$orders->{$basket->{basketno}}}) { - $arrbasket = undef; - $titleinfo = ""; - if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { - $titleinfo = $line->{title} . " / " . $line->{author} . - ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN: " . $line->{en} : '' ) . - ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') . - ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); - } - else { # MARC21, NORMARC - $titleinfo = $line->{title} . " " . $line->{author} . - ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN: " . $line->{en} : '' ) . - ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' Verlag: '. $line->{publishercode} : '') . - ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); - } - push( @$arrbasket, - $basket->{basketno}, - $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferantennotiz : ". $line->{order_vendornote} : '' ), $line->{quantity}, - $line->{quantity}, - Koha::Number::Price->new( $line->{rrp_tax_included} )->format, - Koha::Number::Price->new( $line->{discount} )->format . '%', - Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', - Koha::Number::Price->new( $line->{total_tax_excluded} )->format, - Koha::Number::Price->new( $line->{total_tax_included} )->format, - ); - push(@$abaskets, $arrbasket); - } - } - - $pdftable->table($pdf, $page, $abaskets, - x => 10/mm, - w => ($width - 20)/mm, - start_y => 285/mm, - next_y => 285/mm, - start_h => 260/mm, - next_h => 260/mm, - padding => 5, - padding_right => 5, - background_color_odd => "lightgray", - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 3/mm, - header_props => { - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 10, - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { justify => 'left' }, - { min_w => 90/mm }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - { justify => 'right' }, - ], - ); - - $pdf->mediabox($width/mm, $height/mm); -} - -sub printhead { - my ($pdf, $basketgroup, $bookseller) = @_; - - # get library name - my $libraryname = C4::Context->preference("LibraryName"); - my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); - my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); - my $freedeliveryplace = $basketgroup->{freedeliveryplace}; - # get the subject - my $subject; - - # open 1st page (with the header) - my $page = $pdf->openpage(1); - - # create a text - my $text = $page->text; - - # print the libraryname in the header - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(30/mm, ($height-28.5)/mm); - $text->text($libraryname); - - # print order info, on the default PDF - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); - $text->translate(100/mm, ($height-5-48)/mm); - $text->text($basketgroup->{'id'}); - - # print the date - my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); - $text->translate(130/mm, ($height-5-48)/mm); - $text->text($today); - - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - - # print billing infos - $text->translate(100/mm, ($height-86)/mm); - $text->text($libraryname); - $text->translate(100/mm, ($height-97)/mm); - $text->text($billing_library->branchname); - $text->translate(100/mm, ($height-108.5)/mm); - $text->text($billing_library->branchphone); - $text->translate(100/mm, ($height-115.5)/mm); - $text->text($billing_library->branchfax); - $text->translate(100/mm, ($height-122.5)/mm); - $text->text($billing_library->branchaddress1); - $text->translate(100/mm, ($height-127.5)/mm); - $text->text($billing_library->branchaddress2); - $text->translate(100/mm, ($height-132.5)/mm); - $text->text($billing_library->branchaddress3); - $text->translate(100/mm, ($height-137.5)/mm); - $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); - $text->translate(100/mm, ($height-147.5)/mm); - $text->text($billing_library->branchemail); - - # print subject - $text->translate(100/mm, ($height-145.5)/mm); - $text->text($subject); - - # print bookseller infos - $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->name); - $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->postal); - $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->address1); - $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->address2); - $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->address3); - $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->accountnumber); - - # print delivery infos - $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); - $text->translate(50/mm, ($height-237)/mm); - if ($freedeliveryplace) { - my $start = 242; - my @fdp = split('\n', $freedeliveryplace); - foreach (@fdp) { - $text->text($_); - $text->translate( 50 / mm, ( $height - $start ) / mm ); - $start += 5; - } - } else { - $text->text( $delivery_library->branchaddress1 ); - $text->translate( 50 / mm, ( $height - 242 ) / mm ); - $text->text( $delivery_library->branchaddress2 ); - $text->translate( 50 / mm, ( $height - 247 ) / mm ); - $text->text( $delivery_library->branchaddress3 ); - $text->translate( 50 / mm, ( $height - 252 ) / mm ); - $text->text( join( ' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry ) ); - } - $text->translate(50/mm, ($height-262)/mm); - $text->text($basketgroup->{deliverycomment}); -} - -sub printfooters { - my $pdf = shift; - for ( 1..$pdf->pages ) { - my $page = $pdf->openpage($_); - my $text = $page->text; - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); - $text->translate(10/mm, 10/mm); - $text->text("Seite $_ / ".$pdf->pages); - } -} - -sub printpdf { - my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; - # open the default PDF that will be used for base (1st page already filled) - my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pagesde.pdf'; - my $pdf = PDF::API2->open($pdf_template); - $pdf->pageLabel( 0, { - -style => 'roman', - } ); # start with roman numbering - # fill the 1st page (basketgroup information) - printhead($pdf, $basketgroup, $bookseller); - # fill other pages (orders) - printorders($pdf, $basketgroup, $baskets, $orders); - # print something on each page (usually the footer, but you could also put a header - printfooters($pdf); - return $pdf->stringify; -} - -1; diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm deleted file mode 100644 index 8f80fe2..0000000 --- a/acqui/pdfformat/layout3pages.pm +++ /dev/null @@ -1,433 +0,0 @@ -#!/usr/bin/perl - -#example script to print a basketgroup -#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com - -# Copyright 2008-2009 BibLibre SARL -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout3pages; -use vars qw(@ISA @EXPORT); -use MIME::Base64; -use List::MoreUtils qw/uniq/; -use Modern::Perl; -use utf8; - -use Koha::Number::Price; -use Koha::DateUtils; -use Koha::Libraries; - -BEGIN { - use Exporter (); - our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); - @ISA = qw(Exporter); - @EXPORT = qw(printpdf); -} - - -#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). -#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. -use constant mm => 25.4 / 72; -use constant in => 1 / 72; -use constant pt => 1; - -use PDF::API2; -#A4 paper specs -my ($height, $width) = (297, 210); -use PDF::Table; - -sub printorders { - my ($pdf, $basketgroup, $baskets, $orders) = @_; - - my $cur_format = C4::Context->preference("CurrencyFormat"); - - $pdf->mediabox($height/mm, $width/mm); - my $number = 3; - for my $basket (@$baskets){ - my $page = $pdf->page(); - my $billing_library = Koha::Libraries->find( $basket->{billingplace} ); - my $delivery_library = Koha::Libraries->find( $basket->{deliveryplace} ); - - # print basket header (box) - my $box = $page->gfx; - $box->rectxy(($width - 10)/mm, ($height - 5)/mm, 10/mm, ($height - 25)/mm); - $box->stroke; -# $box->restore(); - - # create a text - my $text = $page->text; - # add basketgroup number - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(20/mm, ($height-15)/mm); - $text->text("Order no. ".$basketgroup->{'id'}.". Basket no. ".$basket->{basketno}.". ".$basket->{booksellernote}); - $text->translate(20/mm, ($height-20)/mm); - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - $text->text( ( $billing_library ? "Billing at " . $billing_library->branchname : "" ) - . ( $billing_library and $delivery_library ? " and " : "" ) - . ( $delivery_library ? "delivery at " . $delivery_library->branchname : "" ) - ); - - my $pdftable = new PDF::Table(); - my $abaskets; - my $arrbasket; - my @keys = ('Document', 'Qty', 'RRP tax exc.', 'RRP tax inc.', 'Discount', 'Discount price', 'GST rate', 'Total tax exc.', 'Total tax inc.'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - push(@$abaskets, $arrbasket); - - my $titleinfo; - foreach my $line (@{$orders->{$basket->{basketno}}}) { - $arrbasket = undef; - $titleinfo = ""; - if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { - $titleinfo = $line->{title} . " / " . $line->{author} . - ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN: " . $line->{en} : '' ) . - ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . - ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); - } - else { # MARC21, NORMARC - $titleinfo = $line->{title} . " " . $line->{author} . - ( $line->{isbn} ? " ISBN: " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN: " . $line->{en} : '' ) . - ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . - ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); - } - push( @$arrbasket, - $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), - $line->{quantity}, - Koha::Number::Price->new( $line->{rrp_tax_excluded} )->format, - Koha::Number::Price->new( $line->{rrp_tax_included} )->format, - Koha::Number::Price->new( $line->{discount} )->format . '%', - Koha::Number::Price->new( $line->{rrp_tax_excluded} - $line->{ecost_tax_excluded})->format, - Koha::Number::Price->new( $line->{tax_rate} * 100 )->format . '%', - Koha::Number::Price->new( $line->{total_tax_excluded} )->format, - Koha::Number::Price->new( $line->{total_tax_included} )->format, - ); - push(@$abaskets, $arrbasket); - } - - $pdftable->table($pdf, $page, $abaskets, - x => 10/mm, - w => ($width - 20)/mm, - start_y => 270/mm, - next_y => 285/mm, - start_h => 250/mm, - next_h => 250/mm, - padding => 5, - padding_right => 5, - background_color_odd => "lightgray", - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 3/mm, - header_props => { - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 9, - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { - min_w => 85/mm, # Minimum column width. - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - ], - ); - } - $pdf->mediabox($width/mm, $height/mm); -} - -sub printbaskets { - my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_; - - # get library name - my $libraryname = C4::Context->preference("LibraryName"); - - my $cur_format = C4::Context->preference("CurrencyFormat"); - - $pdf->mediabox($width/mm, $height/mm); - my $page = $pdf->openpage(2); - # create a text - my $text = $page->text; - - # add basketgroup number - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(($width-40)/mm, ($height-53)/mm); - $text->text("".$basketgroup->{'id'}); - # print the libraryname in the header - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(30/mm, ($height-28.5)/mm); - $text->text($libraryname); - my $pdftable = new PDF::Table(); - my $abaskets; - my $arrbasket; - # header of the table - my @keys = ('Lot', 'Basket (No.)','Total RRP tax exc.', 'Total RRP tax inc.', 'GST rate', 'GST', 'Total discount', 'Total tax exc.', 'Total tax inc.'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - my ($grandtotal_rrp_tax_included, $grandtotal_rrp_tax_excluded, $grandtotal_tax_included, $grandtotal_tax_excluded, $grandtotaltax_value, $grandtotaldiscount); - # calculate each basket total - push(@$abaskets, $arrbasket); - for my $basket (@$hbaskets) { - my @gst; - $arrbasket = undef; - my ($total_rrp_tax_excluded, $total_rrp_tax_included, $total_tax_excluded, $total_tax_included, $totaltax_value, $totaldiscount); - my $ords = $orders->{$basket->{basketno}}; - my $ordlength = @$ords; - foreach my $ord (@$ords) { - $total_tax_excluded += $ord->{total_tax_excluded}; - $total_tax_included += $ord->{total_tax_included}; - $totaltax_value += $ord->{tax_value}; - $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity}; - $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity}; - $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity}; - push @gst, $ord->{tax_rate}; - } - @gst = uniq map { $_ * 100 } @gst; - $grandtotal_rrp_tax_excluded += $total_rrp_tax_excluded; - $grandtotal_rrp_tax_included += $total_rrp_tax_included; - $grandtotal_tax_included += $total_tax_included; - $grandtotal_tax_excluded += $total_tax_excluded; - $grandtotaltax_value += $totaltax_value; - $grandtotaldiscount += $totaldiscount; - my @gst_string = - map { Koha::Number::Price->new($_)->format . '%' } @gst; - push(@$arrbasket, - $basket->{contractname}, - $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')', - Koha::Number::Price->new( $total_rrp_tax_excluded )->format, - Koha::Number::Price->new( $total_rrp_tax_included )->format, - "@gst_string", - Koha::Number::Price->new( $totaltax_value )->format, - Koha::Number::Price->new( $totaldiscount )->format, - Koha::Number::Price->new( $total_tax_excluded )->format, - Koha::Number::Price->new( $total_tax_included )->format, - ); - push(@$abaskets, $arrbasket); - } - # now, push total - undef $arrbasket; - push @$arrbasket, - '', - 'Total', - Koha::Number::Price->new( $grandtotal_rrp_tax_excluded )->format, - Koha::Number::Price->new( $grandtotal_rrp_tax_included )->format, - '', - Koha::Number::Price->new( $grandtotaltax_value )->format, - Koha::Number::Price->new( $grandtotaldiscount )->format, - Koha::Number::Price->new( $grandtotal_tax_excluded )->format, - Koha::Number::Price->new( $grandtotal_tax_included )->format; - push @$abaskets,$arrbasket; - # height is width and width is height in this function, as the pdf is in landscape mode for the Tables. - - $pdftable->table($pdf, $page, $abaskets, - x => 5/mm, - w => ($width - 10)/mm, - start_y => 230/mm, - next_y => 230/mm, - start_h => 230/mm, - next_h => 230/mm, - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 3/mm, - padding => 5, - padding_right => 10, - background_color_odd => "lightgray", - header_props => { - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { - }, - { - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - ], - ); - $pdf->mediabox($height/mm, $width/mm); -} - -sub printhead { - my ($pdf, $basketgroup, $bookseller) = @_; - - # get library name - my $libraryname = C4::Context->preference("LibraryName"); - my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); - my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); - my $freedeliveryplace = $basketgroup->{freedeliveryplace}; - # get the subject - my $subject; - - # open 1st page (with the header) - my $page = $pdf->openpage(1); - - # create a text - my $text = $page->text; - - # print the libraryname in the header - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(30/mm, ($height-28.5)/mm); - $text->text($libraryname); - - # print order info, on the default PDF - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); - $text->translate(100/mm, ($height-5-48)/mm); - $text->text($basketgroup->{'id'}); - - # print the date - my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); - $text->translate(130/mm, ($height-5-48)/mm); - $text->text($today); - - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - - # print billing infos - $text->translate(100/mm, ($height-86)/mm); - $text->text($libraryname); - $text->translate(100/mm, ($height-97)/mm); - $text->text($billing_library->branchname); - $text->translate(100/mm, ($height-108.5)/mm); - $text->text($billing_library->branchphone); - $text->translate(100/mm, ($height-115.5)/mm); - $text->text($billing_library->branchfax); - $text->translate(100/mm, ($height-122.5)/mm); - $text->text($billing_library->branchaddress1); - $text->translate(100/mm, ($height-127.5)/mm); - $text->text($billing_library->branchaddress2); - $text->translate(100/mm, ($height-132.5)/mm); - $text->text($billing_library->branchaddress3); - $text->translate(100/mm, ($height-137.5)/mm); - $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); - $text->translate(100/mm, ($height-147.5)/mm); - $text->text($billing_library->branchemail); - - # print subject - $text->translate(100/mm, ($height-145.5)/mm); - $text->text($subject); - - # print bookseller infos - $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->name); - $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->postal); - $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->address1); - $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->address2); - $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->address3); - $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->accountnumber); - - # print delivery infos - $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); - $text->translate(50/mm, ($height-237)/mm); - if ($freedeliveryplace) { - my $start = 242; - my @fdp = split('\n', $freedeliveryplace); - foreach (@fdp) { - $text->text($_); - $text->translate( 50 / mm, ( $height - $start ) / mm ); - $start += 5; - } - } else { - $text->text($delivery_library->branchaddress1); - $text->translate(50/mm, ($height-242)/mm); - $text->text($delivery_library->branchaddress2); - $text->translate(50/mm, ($height-247)/mm); - $text->text($delivery_library->branchaddress3); - $text->translate(50/mm, ($height-252)/mm); - $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry)); - } - $text->translate(50/mm, ($height-262)/mm); - $text->text($basketgroup->{deliverycomment}); -} - -sub printfooters { - my ($pdf) = @_; - for (my $i=1;$i <= $pdf->pages;$i++) { - my $page = $pdf->openpage($i); - my $text = $page->text; - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); - $text->translate(10/mm, 10/mm); - $text->text("Page $i / ".$pdf->pages); - } -} - -sub printpdf { - my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; - # open the default PDF that will be used for base (1st page already filled) - my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout3pages.pdf'; - my $pdf = PDF::API2->open($pdf_template); - $pdf->pageLabel( 0, { - -style => 'roman', - } ); # start with roman numbering - # fill the 1st page (basketgroup information) - printhead($pdf, $basketgroup, $bookseller); - # fill the 2nd page (orders summary) - printbaskets($pdf, $basketgroup, $baskets, $bookseller, $GST, $orders); - # fill other pages (orders) - printorders($pdf, $basketgroup, $baskets, $orders); - # print something on each page (usually the footer, but you could also put a header - printfooters($pdf); - return $pdf->stringify; -} - -1; diff --git a/acqui/pdfformat/layout3pagesfr.pm b/acqui/pdfformat/layout3pagesfr.pm deleted file mode 100644 index 5568e01..0000000 --- a/acqui/pdfformat/layout3pagesfr.pm +++ /dev/null @@ -1,433 +0,0 @@ -#!/usr/bin/perl - -#example script to print a basketgroup -#written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com - -# Copyright 2008-2009, 2013 BibLibre SARL -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, see . - -#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout3pagesfr; -use vars qw(@ISA @EXPORT); -use MIME::Base64; -use List::MoreUtils qw/uniq/; -use Modern::Perl; -use utf8; - -use Koha::Number::Price; -use Koha::DateUtils; -use Koha::Libraries; - -BEGIN { - use Exporter (); - our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); - @ISA = qw(Exporter); - @EXPORT = qw(printpdf); -} - - -#be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2). -#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. -use constant mm => 25.4 / 72; -use constant in => 1 / 72; -use constant pt => 1; - -use PDF::API2; -#A4 paper specs -my ($height, $width) = (297, 210); -use PDF::Table; - -sub printorders { - my ($pdf, $basketgroup, $baskets, $orders) = @_; - - my $cur_format = C4::Context->preference("CurrencyFormat"); - - $pdf->mediabox($height/mm, $width/mm); - my $number = 3; - for my $basket (@$baskets){ - my $page = $pdf->page(); - my $billing_library = Koha::Libraries->find( $basket->{billingplace} ); - my $delivery_library = Koha::Libraries->find( $basket->{deliveryplace} ); - - # print basket header (box) - my $box = $page->gfx; - $box->rectxy(($width - 10)/mm, ($height - 5)/mm, 10/mm, ($height - 25)/mm); - $box->stroke; -# $box->restore(); - - # create a text - my $text = $page->text; - # add basketgroup number - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(20/mm, ($height-15)/mm); - $text->text("Commande N°".$basketgroup->{'id'}.". Panier N° ".$basket->{basketno}.". ".$basket->{booksellernote}); - $text->translate(20/mm, ($height-20)/mm); - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - $text->text( ( $billing_library ? "Facturation à " . $billing_library->branchname : "" ) - . ( $billing_library and $delivery_library ? " et " : "" ) - . ( $delivery_library ? "livraison à " . $delivery_library->branchname : "" ) - ); - - my $pdftable = new PDF::Table(); - my $abaskets; - my $arrbasket; - my @keys = ('Document', 'Qté', 'Prix', 'Prix net', '% Remise', 'Remise', 'Taux TVA', 'Total HT', 'Total TTC'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - push(@$abaskets, $arrbasket); - - my $titleinfo; - foreach my $line (@{$orders->{$basket->{basketno}}}) { - $arrbasket = undef; - $titleinfo = ""; - if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { - $titleinfo = $line->{title} . " / " . $line->{author} . - ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN : " . $line->{en} : '' ) . - ( $line->{itemtype} ? ", " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' publié par '. $line->{publishercode} : '') . - ( $line->{publicationyear} ? ', '. $line->{publicationyear} : ''); - } - else { # MARC21, NORMARC - $titleinfo = $line->{title} . " " . $line->{author} . - ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) . - ( $line->{en} ? " EN : " . $line->{en} : '' ) . - ( $line->{itemtype} ? " " . $line->{itemtype} : '' ) . - ( $line->{edition} ? ", " . $line->{edition} : '' ) . - ( $line->{publishercode} ? ' publié par '. $line->{publishercode} : '') . - ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); - } - - push( @$arrbasket, - $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote pour le fournisseur : ". $line->{order_vendornote} : '' ), - $line->{quantity}, - Koha::Number::Price->new( $line->{rrp_tax_excluded})->format, - Koha::Number::Price->new( $line->{rrp_tax_included})->format, - Koha::Number::Price->new( $line->{discount})->format.'%', - Koha::Number::Price->new( $line->{rrp_tax_excluded} - $line->{ecost_tax_excluded})->format, - Koha::Number::Price->new( $line->{tax_rate} * 100)->format.'%', - Koha::Number::Price->new( $line->{total_tax_excluded})->format, - Koha::Number::Price->new( $line->{total_tax_included})->format, - ); - push(@$abaskets, $arrbasket); - } - - $pdftable->table($pdf, $page, $abaskets, - x => 10/mm, - w => ($width - 20)/mm, - start_y => 270/mm, - next_y => 285/mm, - start_h => 250/mm, - next_h => 250/mm, - padding => 5, - padding_right => 5, - background_color_odd => "lightgray", - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 3/mm, - header_props => { - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 9, - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { - min_w => 85/mm, # Minimum column width. - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - { - justify => 'right', # One of left|right , - }, - ], - ); - } - $pdf->mediabox($width/mm, $height/mm); -} - -sub printbaskets { - my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_; - - # get library name - my $libraryname = C4::Context->preference("LibraryName"); - - my $cur_format = C4::Context->preference("CurrencyFormat"); - - $pdf->mediabox($width/mm, $height/mm); - my $page = $pdf->openpage(2); - # create a text - my $text = $page->text; - - # add basketgroup number - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(($width-40)/mm, ($height-53)/mm); - $text->text("".$basketgroup->{'id'}); - # print the libraryname in the header - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(30/mm, ($height-28.5)/mm); - $text->text($libraryname); - my $pdftable = new PDF::Table(); - my $abaskets; - my $arrbasket; - # header of the table - my @keys = ('Lot', 'Panier', 'Prix', 'Prix net', 'Taux TVA', 'TVA', 'Remise', 'Total HT', 'Total TTC'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - my ($grandtotal_rrp_tax_included, $grandtotal_rrp_tax_excluded, $grandtotal_tax_included, $grandtotal_tax_excluded, $grandtotaltax_value, $grandtotaldiscount); - # calculate each basket total - push(@$abaskets, $arrbasket); - for my $basket (@$hbaskets) { - my @gst; - $arrbasket = undef; - my ($total_rrp_tax_excluded, $total_rrp_tax_included, $total_tax_excluded, $total_tax_included, $totaltax_value, $totaldiscount); - my $ords = $orders->{$basket->{basketno}}; - my $ordlength = @$ords; - foreach my $ord (@$ords) { - $total_tax_excluded += $ord->{total_tax_excluded}; - $total_tax_included += $ord->{total_tax_included}; - $totaltax_value += $ord->{tax_value}; - $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity}; - $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity}; - $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity}; - push @gst, $ord->{tax_rate}; - } - @gst = uniq map { $_ * 100 } @gst; - $grandtotal_rrp_tax_excluded += $total_rrp_tax_excluded; - $grandtotal_rrp_tax_included += $total_rrp_tax_included; - $grandtotal_tax_included += $total_tax_included; - $grandtotal_tax_excluded += $total_tax_excluded; - $grandtotaltax_value += $totaltax_value; - $grandtotaldiscount += $totaldiscount; - my @gst_string = - map { Koha::Number::Price->new($_)->format . '%' } @gst; - push(@$arrbasket, - $basket->{contractname}, - $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')', - Koha::Number::Price->new( $total_rrp_tax_excluded )->format, - Koha::Number::Price->new( $total_rrp_tax_included )->format, - "@gst_string", - Koha::Number::Price->new( $totaltax_value )->format, - Koha::Number::Price->new( $totaldiscount )->format, - Koha::Number::Price->new( $total_tax_excluded )->format, - Koha::Number::Price->new( $total_tax_included )->format, - ); - push(@$abaskets, $arrbasket); - } - # now, push total - undef $arrbasket; - push @$arrbasket, - '', - 'Total', - Koha::Number::Price->new( $grandtotal_rrp_tax_excluded )->format, - Koha::Number::Price->new( $grandtotal_rrp_tax_included )->format, - '', - Koha::Number::Price->new( $grandtotaltax_value )->format, - Koha::Number::Price->new( $grandtotaldiscount )->format, - Koha::Number::Price->new( $grandtotal_tax_excluded )->format, - Koha::Number::Price->new( $grandtotal_tax_included )->format; - push @$abaskets,$arrbasket; - # height is width and width is height in this function, as the pdf is in landscape mode for the Tables. - - $pdftable->table($pdf, $page, $abaskets, - x => 5/mm, - w => ($width - 10)/mm, - start_y => 230/mm, - next_y => 230/mm, - start_h => 230/mm, - next_h => 230/mm, - font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 3/mm, - padding => 5, - padding_right => 10, - background_color_odd => "lightgray", - header_props => { - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { - }, - { - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - ], - ); - $pdf->mediabox($height/mm, $width/mm); -} - -sub printhead { - my ($pdf, $basketgroup, $bookseller) = @_; - - # get library name - my $libraryname = C4::Context->preference("LibraryName"); - my $billing_library = Koha::Libraries->find( $basketgroup->{billingplace} ); - my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} ); - my $freedeliveryplace = $basketgroup->{freedeliveryplace}; - # get the subject - my $subject; - - # open 1st page (with the header) - my $page = $pdf->openpage(1); - - # create a text - my $text = $page->text; - - # print the libraryname in the header - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); - $text->translate(30/mm, ($height-28.5)/mm); - $text->text($libraryname); - - # print order info, on the default PDF - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); - $text->translate(100/mm, ($height-5-48)/mm); - $text->text($basketgroup->{'id'}); - - # print the date - my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); - $text->translate(130/mm, ($height-5-48)/mm); - $text->text($today); - - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - - # print billing infos - $text->translate(100/mm, ($height-86)/mm); - $text->text($libraryname); - $text->translate(100/mm, ($height-97)/mm); - $text->text($billing_library->branchname); - $text->translate(100/mm, ($height-108.5)/mm); - $text->text($billing_library->branchphone); - $text->translate(100/mm, ($height-115.5)/mm); - $text->text($billing_library->branchfax); - $text->translate(100/mm, ($height-122.5)/mm); - $text->text($billing_library->branchaddress1); - $text->translate(100/mm, ($height-127.5)/mm); - $text->text($billing_library->branchaddress2); - $text->translate(100/mm, ($height-132.5)/mm); - $text->text($billing_library->branchaddress3); - $text->translate(100/mm, ($height-137.5)/mm); - $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); - $text->translate(100/mm, ($height-147.5)/mm); - $text->text($billing_library->branchemail); - - # print subject - $text->translate(100/mm, ($height-145.5)/mm); - $text->text($subject); - - # print bookseller infos - $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->name); - $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->postal); - $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->address1); - $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->address2); - $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->address3); - $text->translate(100/mm, ($height-205)/mm); - $text->text($bookseller->accountnumber); - - # print delivery infos - $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); - $text->translate(50/mm, ($height-237)/mm); - if ($freedeliveryplace) { - my $start = 242; - my @fdp = split('\n', $freedeliveryplace); - foreach (@fdp) { - $text->text($_); - $text->translate( 50 / mm, ( $height - $start ) / mm ); - $start += 5; - } - } else { - $text->text($delivery_library->branchaddress1); - $text->translate(50/mm, ($height-242)/mm); - $text->text($delivery_library->branchaddress2); - $text->translate(50/mm, ($height-247)/mm); - $text->text($delivery_library->branchaddress3); - $text->translate(50/mm, ($height-252)/mm); - $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry)); - } - $text->translate(50/mm, ($height-262)/mm); - $text->text($basketgroup->{deliverycomment}); -} - -sub printfooters { - my ($pdf) = @_; - for (my $i=1;$i <= $pdf->pages;$i++) { - my $page = $pdf->openpage($i); - my $text = $page->text; - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 3/mm ); - $text->translate(10/mm, 10/mm); - $text->text("Page $i / ".$pdf->pages); - } -} - -sub printpdf { - my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_; - # open the default PDF that will be used for base (1st page already filled) - my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout3pagesfr.pdf'; - my $pdf = PDF::API2->open($pdf_template); - $pdf->pageLabel( 0, { - -style => 'roman', - } ); # start with roman numbering - # fill the 1st page (basketgroup information) - printhead($pdf, $basketgroup, $bookseller); - # fill the 2nd page (orders summary) - printbaskets($pdf, $basketgroup, $baskets, $bookseller, $GST, $orders); - # fill other pages (orders) - printorders($pdf, $basketgroup, $baskets, $orders); - # print something on each page (usually the footer, but you could also put a header - printfooters($pdf); - return $pdf->stringify; -} - -1; -- 1.7.2.5