X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fpdfformat%2Flayout3pages.pm;h=8f80fe26a6466f01d4630ca4d6f637187b63a324;hb=91790fdd90c8dc59b70f6defd63b088febf5b39d;hp=7dab18fc3936d089bace6db82d27a7c3b044c11f;hpb=7aa3a055914d4c8757455898208848619f5aaec5;p=koha.git diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm old mode 100755 new mode 100644 index 7dab18fc39..8f80fe26a6 --- a/acqui/pdfformat/layout3pages.pm +++ b/acqui/pdfformat/layout3pages.pm @@ -7,42 +7,41 @@ # # 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 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. +# 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# 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($VERSION @ISA @EXPORT); -use Number::Format qw(format_price); +use vars qw(@ISA @EXPORT); use MIME::Base64; -use strict; -use warnings; +use List::MoreUtils qw/uniq/; +use Modern::Perl; use utf8; -use C4::Branch qw(GetBranchDetail); +use Koha::Number::Price; +use Koha::DateUtils; +use Koha::Libraries; BEGIN { use Exporter (); - our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); - # set the version for version checking - $VERSION = 1.00; + 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 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. +#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; @@ -56,30 +55,14 @@ 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(); - + 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); @@ -91,23 +74,59 @@ sub printorders { # 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}); - + $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','RRT GST Inc.','Discount','Discount price GST Exc.','GST', 'Total GST Inc.'); + 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); -# @{$orders->{$basket->{basketno}}}); + + my $titleinfo; 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])); + $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, @@ -122,13 +141,19 @@ sub printorders { font_size => 3/mm, header_props => { font => $pdf->corefont("Times", -encoding => "utf8"), - font_size => 10, + font_size => 9, bg_color => 'gray', repeat => 1, }, column_props => [ { - min_w => 100/mm, # Minimum column width. + 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 , @@ -161,25 +186,7 @@ sub printbaskets { 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 @@ -197,34 +204,62 @@ sub printbaskets { 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.'); + 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=0; - my $grandgst=0; + 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, $gst, $totallist) = (0, 0, 0); + 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 += @$ord[5] * @$ord[7]; - $gst += (@$ord[5] * @$ord[7]) * $GSTrate/(1+$GSTrate); - $totallist += @$ord[5]*@$ord[6]; + $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}; } - $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)); + @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',$num->format_price($grandtotal),'',$num->format_price($grandtotal-$grandgst), $num->format_price($grandgst),$num->format_price($grandtotal); + 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. @@ -264,12 +299,6 @@ sub printbaskets { { justify => 'right', }, - { - justify => 'right', - }, - { - justify => 'right', - }, ], ); $pdf->mediabox($height/mm, $width/mm); @@ -280,9 +309,8 @@ sub printhead { # get library name my $libraryname = C4::Context->preference("LibraryName"); - # get branch details - my $billingdetails = GetBranchDetail( $basketgroup->{billingplace} ); - my $deliverydetails = GetBranchDetail( $basketgroup->{deliveryplace} ); + 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; @@ -304,7 +332,7 @@ sub printhead { $text->text($basketgroup->{'id'}); # print the date - my $today = C4::Dates->today(); + my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); $text->translate(130/mm, ($height-5-48)/mm); $text->text($today); @@ -314,21 +342,21 @@ sub printhead { $text->translate(100/mm, ($height-86)/mm); $text->text($libraryname); $text->translate(100/mm, ($height-97)/mm); - $text->text($billingdetails->{branchname}); + $text->text($billing_library->branchname); $text->translate(100/mm, ($height-108.5)/mm); - $text->text($billingdetails->{branchphone}); + $text->text($billing_library->branchphone); $text->translate(100/mm, ($height-115.5)/mm); - $text->text($billingdetails->{branchfax}); + $text->text($billing_library->branchfax); $text->translate(100/mm, ($height-122.5)/mm); - $text->text($billingdetails->{branchaddress1}); + $text->text($billing_library->branchaddress1); $text->translate(100/mm, ($height-127.5)/mm); - $text->text($billingdetails->{branchaddress2}); + $text->text($billing_library->branchaddress2); $text->translate(100/mm, ($height-132.5)/mm); - $text->text($billingdetails->{branchaddress3}); + $text->text($billing_library->branchaddress3); $text->translate(100/mm, ($height-137.5)/mm); - $text->text(join(' ', $billingdetails->{branchzip}, $billingdetails->{branchcity}, $billingdetails->{branchcountry})); + $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); $text->translate(100/mm, ($height-147.5)/mm); - $text->text($billingdetails->{branchemail}); + $text->text($billing_library->branchemail); # print subject $text->translate(100/mm, ($height-145.5)/mm); @@ -336,15 +364,17 @@ sub printhead { # print bookseller infos $text->translate(100/mm, ($height-180)/mm); - $text->text($bookseller->{name}); + $text->text($bookseller->name); $text->translate(100/mm, ($height-185)/mm); - $text->text($bookseller->{postal}); + $text->text($bookseller->postal); $text->translate(100/mm, ($height-190)/mm); - $text->text($bookseller->{address1}); + $text->text($bookseller->address1); $text->translate(100/mm, ($height-195)/mm); - $text->text($bookseller->{address2}); + $text->text($bookseller->address2); $text->translate(100/mm, ($height-200)/mm); - $text->text($bookseller->{address3}); + $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 ); @@ -358,13 +388,13 @@ sub printhead { $start += 5; } } else { - $text->text($deliverydetails->{branchaddress1}); + $text->text($delivery_library->branchaddress1); $text->translate(50/mm, ($height-242)/mm); - $text->text($deliverydetails->{branchaddress2}); + $text->text($delivery_library->branchaddress2); $text->translate(50/mm, ($height-247)/mm); - $text->text($deliverydetails->{branchaddress3}); + $text->text($delivery_library->branchaddress3); $text->translate(50/mm, ($height-252)/mm); - $text->text(join(' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry})); + $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry)); } $text->translate(50/mm, ($height-262)/mm); $text->text($basketgroup->{deliverycomment});