From: Jean-André Santoni Date: Tue, 3 Nov 2009 15:23:37 +0000 (+0100) Subject: [3.2.x](bug #3623) PDF printing enhancements X-Git-Tag: v3.02.00-alpha~54^2~103 X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=7e872e0a1ff0b2f06ca9e77c49375732f523f0bc;p=koha.git [3.2.x](bug #3623) PDF printing enhancements Renamed pdfformat to OrderPdfFormat and created OrderPdfTemplate to stock the PDF in the database. Added a new type of syspref nammed "Upload". Rewritte, translation and cleaning of the PDF template. --- diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 17d8948a31..bd56ace880 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -182,7 +182,7 @@ sub displaybasketgroups { sub printbasketgrouppdf{ my ($basketgroupid) = @_; - my $pdfformat = C4::Context->preference("pdfformat"); + my $pdfformat = C4::Context->preference("OrderPdfFormat"); eval "use $pdfformat" ; warn @_; eval "use C4::Branch"; diff --git a/acqui/pdfformat/example.odt b/acqui/pdfformat/example.odt deleted file mode 100644 index cf1d850e69..0000000000 Binary files a/acqui/pdfformat/example.odt and /dev/null differ diff --git a/acqui/pdfformat/example.pdf b/acqui/pdfformat/example.pdf deleted file mode 100644 index 03a3a9b4e2..0000000000 Binary files a/acqui/pdfformat/example.pdf and /dev/null differ diff --git a/acqui/pdfformat/example.pm b/acqui/pdfformat/example.pm deleted file mode 100644 index 34f3b058a5..0000000000 --- a/acqui/pdfformat/example.pm +++ /dev/null @@ -1,344 +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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA - -#you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::example; -use vars qw($VERSION @ISA @EXPORT); -use Number::Format qw(format_price); -use strict; -use warnings; -use utf8; - -use C4::Branch qw(GetBranchDetail); - -BEGIN { - use Exporter (); - our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); - # set the version for version checking - $VERSION = 1.00; - @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 tranform 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"); - my $num; - - if ( $cur_format eq 'FR' ) { - $num = new Number::Format( - 'decimal_fill' => '2', - 'decimal_point' => ',', - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ' ', - 'thousands_sep' => ' ', - 'mon_decimal_point' => ',' - ); - } else { # US by default.. - $num = new Number::Format( - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ',', - 'mon_decimal_point' => '.' - ); - } - - $pdf->mediabox($height/mm, $width/mm); - my $number = 3; - for my $basket (@$baskets){ - my $page = $pdf->page(); - - # 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}); - - my $pdftable = new PDF::Table(); - my $abaskets; - my $arrbasket; - my @keys = ('Document','Qté','Prix public TTC','Remise','Prix remisé HT','TVA', 'Total TTC'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - push(@$abaskets, $arrbasket); -# @{$orders->{$basket->{basketno}}}); - foreach my $line (@{$orders->{$basket->{basketno}}}) { - $arrbasket = undef; - push(@$arrbasket, @$line[3]." / ".@$line[2].(@$line[0]?" ISBN : ".@$line[0]:'').(@$line[10]?" EN : ".@$line[10]:'').", ".@$line[1].(@$line[4]?' publié par '.@$line[4]:''), @$line[5],$num->format_price(@$line[6]),$num->format_price(@$line[8]).'%',$num->format_price(@$line[7]/(1+@$line[9]/100)),$num->format_price(@$line[9]).'%',$num->format_price($num->round(@$line[7])*@$line[5])); - 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 => 10, - bg_color => 'gray', - repeat => 1, - }, - column_props => [ - { - min_w => 100/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 , - }, - ], - ); - } - $pdf->mediabox($width/mm, $height/mm); -} - -sub printbaskets { - my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_; - - my $cur_format = C4::Context->preference("CurrencyFormat"); - my $num; - - if ( $cur_format eq 'FR' ) { - $num = new Number::Format( - 'decimal_fill' => '2', - 'decimal_point' => ',', - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ' ', - 'thousands_sep' => ' ', - 'mon_decimal_point' => ',' - ); - } else { # US by default.. - $num = new Number::Format( - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ',', - 'mon_decimal_point' => '.' - ); - } - - $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-50)/mm); - $text->text("".$basketgroup->{'id'}); - - my $pdftable = new PDF::Table(); - my $abaskets; - my $arrbasket; - # header of the table - my @keys = ('Lot', 'Panier (N°)', 'Prix public TTC', 'Remise', 'Prix remisé','taux TVA', 'Total HT','TVA', 'Total TTC'); - for my $bkey (@keys) { - push(@$arrbasket, $bkey); - } - my $grandtotal=0; - my $grandgst=0; - # calculate each basket total - push(@$abaskets, $arrbasket); - for my $basket (@$hbaskets) { - $arrbasket = undef; - my ($total, $gst, $totallist) = (0, 0, 0); - my $ords = $orders->{$basket->{basketno}}; - my $ordlength = @$ords; - foreach my $ord (@$ords) { - $total += @$ord[5] * @$ord[7]; - $gst += (@$ord[5] * @$ord[7]) * $GSTrate/(1+$GSTrate); - $totallist += @$ord[5]*@$ord[6]; - } - $total=$num->round($total); - $gst=$num->round($gst); - $grandtotal +=$total; - $grandgst +=$gst; - push(@$arrbasket, $basket->{contractname}, $basket->{basketname}.'(N°'.$basket->{basketno}.')',$num->format_price($totallist), $num->format_price($bookseller->{discount}).'%', $num->format_price($total), $num->format_price($GSTrate*100).'%', $num->format_price($total-$gst), $num->format_price($gst), $num->format_price($total)); - push(@$abaskets, $arrbasket); - } - # now, push total - undef $arrbasket; - push @$arrbasket,'','','','Total',$num->format_price($grandtotal),'',$num->format_price($grandtotal-$grandgst), $num->format_price($grandgst),$num->format_price($grandtotal); - 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', - }, - { - justify => 'right', - }, - { - justify => 'right', - }, - ], - ); - $pdf->mediabox($height/mm, $width/mm); -} - -sub printhead { - my ($pdf, $basketgroup, $bookseller, $branch) = @_; - - # get branch details - my $branchdetails = GetBranchDetail( $basketgroup->{'deliveryplace'} ); - - # open 1st page (with the header) - my $page = $pdf->openpage(1); - - # create a text - my $text = $page->text; - - # 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 = C4::Dates->today(); - $text->translate(130/mm, ($height-5-48)/mm); - $text->text($today); - # print bookseller infos - $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - $text->translate(110/mm, ($height-170)/mm); - $text->text($bookseller->{name}); - $text->translate(110/mm, ($height-175)/mm); - $text->text($bookseller->{postal}); - $text->translate(110/mm, ($height-180)/mm); - $text->text($bookseller->{address1}); - $text->translate(110/mm, ($height-185)/mm); - $text->text($bookseller->{address2}); - $text->translate(110/mm, ($height-190)/mm); - $text->text($bookseller->{address3}); - # print delivery infos - $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); - $text->translate(50/mm, ($height-230)/mm); - $text->text($branchdetails->{branchaddress1}); - $text->translate(50/mm, ($height-235)/mm); - $text->text($branchdetails->{branchaddress2}); - $text->translate(50/mm, ($height-240)/mm); - $text->text($branchdetails->{branchaddress3}); - $text->translate(50/mm, ($height-245)/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, $branch, $orders, $GST) = @_; - # open the default PDF that will be used for base (1st page already filled) - my $pdf = PDF::API2->open('pdfformat/example.pdf'); - $pdf->pageLabel( 0, { - -style => 'roman', - } ); # start with roman numbering - # fill the 1st page (basketgroup information) - printhead($pdf, $basketgroup, $bookseller, $branch); - # 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/layout3pages.odt b/acqui/pdfformat/layout3pages.odt new file mode 100644 index 0000000000..d1071e34b7 Binary files /dev/null and b/acqui/pdfformat/layout3pages.odt differ diff --git a/acqui/pdfformat/layout3pages.pdf b/acqui/pdfformat/layout3pages.pdf new file mode 100644 index 0000000000..8e09d1bbf7 Binary files /dev/null and b/acqui/pdfformat/layout3pages.pdf differ diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm new file mode 100755 index 0000000000..3cb35a5f47 --- /dev/null +++ b/acqui/pdfformat/layout3pages.pm @@ -0,0 +1,388 @@ +#!/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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +#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($VERSION @ISA @EXPORT); +use Number::Format qw(format_price); +use MIME::Base64; +use strict; +use warnings; +use utf8; + +use C4::Branch qw(GetBranchDetail); + +BEGIN { + use Exporter (); + our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + # set the version for version checking + $VERSION = 1.00; + @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 tranform 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"); + my $num; + + if ( $cur_format eq 'FR' ) { + $num = new Number::Format( + 'decimal_fill' => '2', + 'decimal_point' => ',', + 'int_curr_symbol' => '', + 'mon_thousands_sep' => ' ', + 'thousands_sep' => ' ', + 'mon_decimal_point' => ',' + ); + } else { # US by default.. + $num = new Number::Format( + 'int_curr_symbol' => '', + 'mon_thousands_sep' => ',', + 'mon_decimal_point' => '.' + ); + } + + $pdf->mediabox($height/mm, $width/mm); + my $number = 3; + for my $basket (@$baskets){ + my $page = $pdf->page(); + + # 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 N°".$basketgroup->{'id'}.". Basket N° ".$basket->{basketno}.". ".$basket->{booksellernote}); + + my $pdftable = new PDF::Table(); + my $abaskets; + my $arrbasket; + my @keys = ('Document','Qty','RRT GST Inc.','Discount','Discount price GST Exc.','GST', 'Total GST Inc.'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + push(@$abaskets, $arrbasket); +# @{$orders->{$basket->{basketno}}}); + foreach my $line (@{$orders->{$basket->{basketno}}}) { + $arrbasket = undef; + push(@$arrbasket, @$line[3]." / ".@$line[2].(@$line[0]?" ISBN : ".@$line[0]:'').(@$line[10]?" EN : ".@$line[10]:'').", ".@$line[1].(@$line[4]?' publié par '.@$line[4]:''), @$line[5],$num->format_price(@$line[6]),$num->format_price(@$line[8]).'%',$num->format_price(@$line[7]/(1+@$line[9]/100)),$num->format_price(@$line[9]).'%',$num->format_price($num->round(@$line[7])*@$line[5])); + 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 => 10, + bg_color => 'gray', + repeat => 1, + }, + column_props => [ + { + min_w => 100/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 , + }, + ], + ); + } + $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"); + my $num; + + if ( $cur_format eq 'FR' ) { + $num = new Number::Format( + 'decimal_fill' => '2', + 'decimal_point' => ',', + 'int_curr_symbol' => '', + 'mon_thousands_sep' => ' ', + 'thousands_sep' => ' ', + 'mon_decimal_point' => ',' + ); + } else { # US by default.. + $num = new Number::Format( + 'int_curr_symbol' => '', + 'mon_thousands_sep' => ',', + 'mon_decimal_point' => '.' + ); + } + + $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 (N°)', 'RRT GST Inc.', 'Discount', 'Discount price','GST rate', 'Total GST exc.','GST', 'Total GST Inc.'); + for my $bkey (@keys) { + push(@$arrbasket, $bkey); + } + my $grandtotal=0; + my $grandgst=0; + # calculate each basket total + push(@$abaskets, $arrbasket); + for my $basket (@$hbaskets) { + $arrbasket = undef; + my ($total, $gst, $totallist) = (0, 0, 0); + my $ords = $orders->{$basket->{basketno}}; + my $ordlength = @$ords; + foreach my $ord (@$ords) { + $total += @$ord[5] * @$ord[7]; + $gst += (@$ord[5] * @$ord[7]) * $GSTrate/(1+$GSTrate); + $totallist += @$ord[5]*@$ord[6]; + } + $total=$num->round($total); + $gst=$num->round($gst); + $grandtotal +=$total; + $grandgst +=$gst; + push(@$arrbasket, $basket->{contractname}, $basket->{basketname}.'(N°'.$basket->{basketno}.')',$num->format_price($totallist), $num->format_price($bookseller->{discount}).'%', $num->format_price($total), $num->format_price($GSTrate*100).'%', $num->format_price($total-$gst), $num->format_price($gst), $num->format_price($total)); + push(@$abaskets, $arrbasket); + } + # now, push total + undef $arrbasket; + push @$arrbasket,'','','','Total',$num->format_price($grandtotal),'',$num->format_price($grandtotal-$grandgst), $num->format_price($grandgst),$num->format_price($grandtotal); + 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', + }, + { + justify => 'right', + }, + { + justify => 'right', + }, + ], + ); + $pdf->mediabox($height/mm, $width/mm); +} + +sub printhead { + my ($pdf, $basketgroup, $bookseller, $branch) = @_; + + # get library name + my $libraryname = C4::Context->preference("LibraryName"); + # get branch details + my $branchdetails = GetBranchDetail( $basketgroup->{'deliveryplace'} ); + # 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 = C4::Dates->today(); + $text->translate(130/mm, ($height-5-48)/mm); + $text->text($today); + + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); + + # print branch infos + $text->translate(100/mm, ($height-86)/mm); + $text->text($libraryname); + $text->translate(100/mm, ($height-97)/mm); + $text->text($branch->{branchname}); + $text->translate(100/mm, ($height-108.5)/mm); + $text->text($branch->{branchphone}); + $text->translate(100/mm, ($height-115.5)/mm); + $text->text($branch->{branchfax}); + $text->translate(100/mm, ($height-122.5)/mm); + $text->text($branch->{branchaddress1}); + $text->translate(100/mm, ($height-127.5)/mm); + $text->text($branch->{branchaddress2}); + $text->translate(100/mm, ($height-132)/mm); + $text->text($branch->{branchaddress3}); + $text->translate(100/mm, ($height-138.5)/mm); + $text->text($branch->{branchemail}); + + # print subject + $text->translate(100/mm, ($height-145.5)/mm); + $text->text($subject); + + # print bookseller infos + $text->translate(100/mm, ($height-177)/mm); + $text->text($bookseller->{name}); + $text->translate(100/mm, ($height-182)/mm); + $text->text($bookseller->{postal}); + $text->translate(100/mm, ($height-187)/mm); + $text->text($bookseller->{address1}); + $text->translate(100/mm, ($height-197)/mm); + $text->text($bookseller->{address2}); + $text->translate(100/mm, ($height-202)/mm); + $text->text($bookseller->{address3}); + + # print delivery infos + $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); + $text->translate(50/mm, ($height-237)/mm); + $text->text($branchdetails->{branchaddress1}); + $text->translate(50/mm, ($height-242)/mm); + $text->text($branchdetails->{branchaddress2}); + $text->translate(50/mm, ($height-247)/mm); + $text->text($branchdetails->{branchaddress3}); + $text->translate(50/mm, ($height-252)/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, $branch, $orders, $GST) = @_; + # open the default PDF that will be used for base (1st page already filled) + my $template = C4::Context->preference("OrderPdfTemplate"); + $template = decode_base64($template); + my $pdf = PDF::API2->openScalar($template); + $pdf->pageLabel( 0, { + -style => 'roman', + } ); # start with roman numbering + # fill the 1st page (basketgroup information) + printhead($pdf, $basketgroup, $bookseller, $branch); + # 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/admin/systempreferences.pl b/admin/systempreferences.pl index b7e1df46e2..b81c2ad820 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -44,6 +44,7 @@ use strict; use warnings; use CGI; +use MIME::Base64; use C4::Auth; use C4::Context; use C4::Koha; @@ -72,7 +73,8 @@ my %tabsysprefs; $tabsysprefs{emailPurchaseSuggestions}="Acquisitions"; $tabsysprefs{RenewSerialAddsSuggestion}="Acquisitions"; $tabsysprefs{AcqCreateItem}="Acquisitions"; - $tabsysprefs{pdfformat}="Acquisitions"; + $tabsysprefs{OrderPdfFormat}="Acquisitions"; + $tabsysprefs{OrderPdfTemplate}="Acquisitions"; $tabsysprefs{CurrencyFormat}="Acquisitions"; # Admin @@ -456,6 +458,8 @@ sub GetPrefParams { if ( not defined( $data->{'type'} ) ) { $params->{'type-free'} = 1; $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ); + } elsif ( $data->{'type'} eq 'Upload' ) { + $params->{'type-upload'} = 1; } elsif ( $data->{'type'} eq 'Choice' ) { $params->{'type-choice'} = 1; } elsif ( $data->{'type'} eq 'YesNo' ) { @@ -688,6 +692,13 @@ if ( $op eq 'add_form' ) { $value = $params->{'value'}; } } + + if ( $input->param('preftype') eq 'Upload' ) { + my $lgtfh = $input->upload('value'); + $value = join '', <$lgtfh>; + $value = encode_base64($value); + } + if ( $sth->rows ) { unless ( C4::Context->config('demo') ) { my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?"); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 33fda1f3d9..f5215ecbdc 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -3192,6 +3192,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.01.00.126"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OrderPdfTemplate','','Uploads a PDF template','NULL','Upload')"); + $dbh->do("UPDATE systempreferences SET variable='OrderPdfFormat' WHERE variable='pdfformat'"); + print "Upgrade to $DBversion done (PDF orders system preferences added and updated)\n"; + SetVersion ($DBversion); +} + =item DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl index bfe30b0939..8f95aa67ee 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl @@ -88,7 +88,7 @@ -
" name="Aform" method="post"> + " name="Aform" method="post" enctype="multipart/form-data">
Modify @@ -100,6 +100,8 @@
  • + + @@ -258,11 +260,14 @@ - + enctype="multipart/form-data"> " value="" /> + + " /> + diff --git a/kohaversion.pl b/kohaversion.pl index de92273ea4..9c71819459 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -10,7 +10,7 @@ use strict; sub kohaversion { - our $VERSION = '3.01.00.125'; + our $VERSION = '3.01.00.126'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install