From 5afb6a30cac4b7df33e0123348734bb493e8d0a3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Sep 2014 11:32:14 +0200 Subject: [PATCH] Bug 12979: Price formatting should only be defined at one place There are some places where the price format is defined. All these occurrences should be removed use the way introduced by bug 12844. Test plan: 1/ Verify you don't see any price formatting change on the basketgroup pdf (for layout2pages, payout2pagesde, layout3pages and layout3pagesfr). 2/ On admin/aqbudgetperiods.pl, the budget total should be unchanged too. Signed-off-by: Paola Rossi Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- acqui/acqui-home.pl | 1 - acqui/addorderiso2709.pl | 1 - acqui/pdfformat/layout2pages.pm | 31 +++--------- acqui/pdfformat/layout2pagesde.pm | 31 +++--------- acqui/pdfformat/layout3pages.pm | 83 +++++++++++-------------------- acqui/pdfformat/layout3pagesfr.pm | 81 ++++++++++-------------------- admin/aqbudgetperiods.pl | 14 ++---- admin/aqbudgets.pl | 1 - admin/aqplan.pl | 1 - 9 files changed, 74 insertions(+), 170 deletions(-) diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl index 3231e62f1d..8741aa4857 100755 --- a/acqui/acqui-home.pl +++ b/acqui/acqui-home.pl @@ -28,7 +28,6 @@ this script is the main page for acqui use strict; use warnings; -use Number::Format; use CGI; use C4::Auth; diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 15c83eaec4..666e771ba6 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -24,7 +24,6 @@ use Modern::Perl; use CGI; use Carp; -use Number::Format qw(:all); use YAML qw/Load/; use C4::Context; diff --git a/acqui/pdfformat/layout2pages.pm b/acqui/pdfformat/layout2pages.pm index 29d6c4bb22..15b9838adc 100644 --- a/acqui/pdfformat/layout2pages.pm +++ b/acqui/pdfformat/layout2pages.pm @@ -23,7 +23,6 @@ #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($VERSION @ISA @EXPORT); -use Number::Format qw(format_price); use MIME::Base64; use strict; use warnings; @@ -31,6 +30,8 @@ use utf8; use C4::Branch qw(GetBranchDetail); +use Koha::Number::Price; + BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); @@ -56,24 +57,6 @@ 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 $page = $pdf->page(); @@ -115,11 +98,11 @@ sub printorders { $basket->{basketno}, $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), $line->{quantity}, - $num->format_price($line->{rrpgsti}), - $num->format_price($line->{discount}).'%', - $num->format_price($line->{gstrate} * 100).'%', - $num->format_price($line->{totalgste}), - $num->format_price($line->{totalgsti}), + Koha::Number::Price->new( $line->{rrpgsti} )->format, + Koha::Number::Price->new( $line->{discount} )->format . '%', + Koha::Number::Price->new( $line->{gstrate} * 100 )->format . '%', + Koha::Number::Price->new( $line->{totalgste} )->format, + Koha::Number::Price->new( $line->{totalgsti} )->format, ); push(@$abaskets, $arrbasket); } diff --git a/acqui/pdfformat/layout2pagesde.pm b/acqui/pdfformat/layout2pagesde.pm index 38a8400d3c..6ac57b03ff 100644 --- a/acqui/pdfformat/layout2pagesde.pm +++ b/acqui/pdfformat/layout2pagesde.pm @@ -23,7 +23,6 @@ #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($VERSION @ISA @EXPORT); -use Number::Format qw(format_price); use MIME::Base64; use strict; use warnings; @@ -31,6 +30,8 @@ use utf8; use C4::Branch qw(GetBranchDetail); +use Koha::Number::Price; + BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); @@ -56,24 +57,6 @@ 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 $page = $pdf->page(); @@ -115,11 +98,11 @@ sub printorders { $basket->{basketno}, $titleinfo. ($line->{order_vendornote} ? "\n----------------\nLieferantennotiz : ". $line->{order_vendornote} : '' ), $line->{quantity}, $line->{quantity}, - $num->format_price($line->{rrpgsti}), - $num->format_price($line->{discount}).'%', - $num->format_price($line->{gstrate} * 100).'%', - $num->format_price($line->{totalgste}), - $num->format_price($line->{totalgsti}), + Koha::Number::Price->new( $line->{rrpgsti} )->format, + Koha::Number::Price->new( $line->{discount} )->format . '%', + Koha::Number::Price->new( $line->{gstrate} * 100 )->format . '%', + Koha::Number::Price->new( $line->{totalgste} )->format, + Koha::Number::Price->new( $line->{totalgsti} )->format, ); push(@$abaskets, $arrbasket); } diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm index 5640a1cfc5..a38f4d3674 100644 --- a/acqui/pdfformat/layout3pages.pm +++ b/acqui/pdfformat/layout3pages.pm @@ -23,7 +23,6 @@ #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 List::MoreUtils qw/uniq/; use strict; @@ -32,6 +31,8 @@ use utf8; use C4::Branch qw(GetBranchDetail GetBranchName); +use Koha::Number::Price; + BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); @@ -57,24 +58,6 @@ 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; @@ -134,13 +117,13 @@ sub printorders { push( @$arrbasket, $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), $line->{quantity}, - $num->format_price($line->{rrpgste}), - $num->format_price($line->{rrpgsti}), - $num->format_price($line->{discount}).'%', - $num->format_price($line->{rrpgste} - $line->{ecostgste}), - $num->format_price($line->{gstrate} * 100).'%', - $num->format_price($line->{totalgste}), - $num->format_price($line->{totalgsti}), + Koha::Number::Price->new( $line->{rrpgste} )->format, + Koha::Number::Price->new( $line->{rrpgsti} )->format, + Koha::Number::Price->new( $line->{discount} )->format . '%', + Koha::Number::Price->new( $line->{rrpgste} - $line->{ecostgste})->format, + Koha::Number::Price->new( $line->{gstrate} * 100 )->format . '%', + Koha::Number::Price->new( $line->{totalgste} )->format, + Koha::Number::Price->new( $line->{totalgsti} )->format, ); push(@$abaskets, $arrbasket); } @@ -204,25 +187,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 @@ -263,31 +228,39 @@ sub printbaskets { push @gst, $ord->{gstrate}; } @gst = uniq map { $_ * 100 } @gst; - $totalgsti = $num->round($totalgsti); - $totalgste = $num->round($totalgste); $grandtotalrrpgste += $totalrrpgste; $grandtotalrrpgsti += $totalrrpgsti; $grandtotalgsti += $totalgsti; $grandtotalgste += $totalgste; $grandtotalgstvalue += $totalgstvalue; $grandtotaldiscount += $totaldiscount; - my @gst_string = map{$num->format_price( $_ ) . '%'} @gst; + my @gst_string = + map { Koha::Number::Price->new($_)->format . '%' } @gst; push(@$arrbasket, $basket->{contractname}, $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')', - $num->format_price($totalrrpgste), - $num->format_price($totalrrpgsti), + Koha::Number::Price->new( $totalrrpgste )->format, + Koha::Number::Price->new( $totalrrpgsti )->format, "@gst_string", - $num->format_price($totalgstvalue), - $num->format_price($totaldiscount), - $num->format_price($totalgste), - $num->format_price($totalgsti) + Koha::Number::Price->new( $totalgstvalue )->format, + Koha::Number::Price->new( $totaldiscount )->format, + Koha::Number::Price->new( $totalgste )->format, + Koha::Number::Price->new( $totalgsti )->format, ); push(@$abaskets, $arrbasket); } # now, push total undef $arrbasket; - push @$arrbasket,'','Total', $num->format_price($grandtotalrrpgste), $num->format_price($grandtotalrrpgsti), '', $num->format_price($grandtotalgstvalue), $num->format_price($grandtotaldiscount), $num->format_price($grandtotalgste), $num->format_price($grandtotalgsti); + push @$arrbasket, + '', + 'Total', + Koha::Number::Price->new( $grandtotalrrpgste )->format, + Koha::Number::Price->new( $grandtotalrrpgsti )->format, + '', + Koha::Number::Price->new( $grandtotalgstvalue )->format, + Koha::Number::Price->new( $grandtotaldiscount )->format, + Koha::Number::Price->new( $grandtotalgste )->format, + Koha::Number::Price->new( $grandtotalgsti )->format; push @$abaskets,$arrbasket; # height is width and width is height in this function, as the pdf is in landscape mode for the Tables. diff --git a/acqui/pdfformat/layout3pagesfr.pm b/acqui/pdfformat/layout3pagesfr.pm index 28ab804d94..6ddb87aa93 100644 --- a/acqui/pdfformat/layout3pagesfr.pm +++ b/acqui/pdfformat/layout3pagesfr.pm @@ -22,7 +22,6 @@ #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($VERSION @ISA @EXPORT); -use Number::Format qw(format_price); use MIME::Base64; use List::MoreUtils qw/uniq/; use strict; @@ -31,6 +30,8 @@ use utf8; use C4::Branch qw(GetBranchDetail GetBranchName); +use Koha::Number::Price; + BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); @@ -56,24 +57,6 @@ 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; @@ -134,13 +117,13 @@ sub printorders { push( @$arrbasket, $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote pour le fournisseur : ". $line->{order_vendornote} : '' ), $line->{quantity}, - $num->format_price($line->{rrpgste}), - $num->format_price($line->{rrpgsti}), - $num->format_price($line->{discount}).'%', - $num->format_price($line->{rrpgste} - $line->{ecostgste}), - $num->format_price($line->{gstrate} * 100).'%', - $num->format_price($line->{totalgste}), - $num->format_price($line->{totalgsti}), + Koha::Number::Price->new( $line->{rrpgste}), + Koha::Number::Price->new( $line->{rrpgsti}), + Koha::Number::Price->new( $line->{discount}).'%', + Koha::Number::Price->new( $line->{rrpgste} - $line->{ecostgste}), + Koha::Number::Price->new( $line->{gstrate} * 100).'%', + Koha::Number::Price->new( $line->{totalgste}), + Koha::Number::Price->new( $line->{totalgsti}), ); push(@$abaskets, $arrbasket); } @@ -204,24 +187,6 @@ 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); @@ -263,31 +228,39 @@ sub printbaskets { push @gst, $ord->{gstrate}; } @gst = uniq map { $_ * 100 } @gst; - $totalgsti = $num->round($totalgsti); - $totalgste = $num->round($totalgste); $grandtotalrrpgste += $totalrrpgste; $grandtotalrrpgsti += $totalrrpgsti; $grandtotalgsti += $totalgsti; $grandtotalgste += $totalgste; $grandtotalgstvalue += $totalgstvalue; $grandtotaldiscount += $totaldiscount; - my @gst_string = map{$num->format_price( $_ ) . '%'} @gst; + my @gst_string = + map { Koha::Number::Price->new($_)->format . '%' } @gst; push(@$arrbasket, $basket->{contractname}, $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')', - $num->format_price($totalrrpgste), - $num->format_price($totalrrpgsti), + Koha::Number::Price->new( $totalrrpgste )->format, + Koha::Number::Price->new( $totalrrpgsti )->format, "@gst_string", - $num->format_price($totalgstvalue), - $num->format_price($totaldiscount), - $num->format_price($totalgste), - $num->format_price($totalgsti) + Koha::Number::Price->new( $totalgstvalue )->format, + Koha::Number::Price->new( $totaldiscount )->format, + Koha::Number::Price->new( $totalgste )->format, + Koha::Number::Price->new( $totalgsti )->format, ); push(@$abaskets, $arrbasket); } # now, push total undef $arrbasket; - push @$arrbasket,'','Total', $num->format_price($grandtotalrrpgste), $num->format_price($grandtotalrrpgsti), '', $num->format_price($grandtotalgstvalue), $num->format_price($grandtotaldiscount), $num->format_price($grandtotalgste), $num->format_price($grandtotalgsti); + push @$arrbasket, + '', + 'Total', + Koha::Number::Price->new( $grandtotalrrpgste )->format, + Koha::Number::Price->new( $grandtotalrrpgsti )->format, + '', + Koha::Number::Price->new( $grandtotalgstvalue )->format, + Koha::Number::Price->new( $grandtotaldiscount )->format, + Koha::Number::Price->new( $grandtotalgste )->format, + Koha::Number::Price->new( $grandtotalgsti )->format; push @$abaskets,$arrbasket; # height is width and width is height in this function, as the pdf is in landscape mode for the Tables. diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 9084540712..119884ad99 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -46,7 +46,6 @@ script to administer the budget periods table use Modern::Perl; -use Number::Format qw(format_price); use CGI; use List::Util qw/min/; use Koha::DateUtils; @@ -59,6 +58,8 @@ use C4::Acquisition; use C4::Budgets; use C4::Debug; +use Koha::Number::Price; + my $dbh = C4::Context->dbh; my $input = new CGI; @@ -106,14 +107,9 @@ if ( $op eq 'add_form' ) { my $budgetperiod_hash=GetBudgetPeriod($budget_period_id); # get dropboxes - my $editnum = new Number::Format( - 'int_curr_symbol' => '', - 'thousands_sep' => '', - 'mon_thousands_sep' => '', - 'mon_decimal_point' => '.' - ); - - $$budgetperiod_hash{budget_period_total}= $editnum->format_price($$budgetperiod_hash{'budget_period_total'}); + $budgetperiod_hash->{budget_period_total} = + Koha::Number::Price->new( $budgetperiod_hash->{budget_period_total} ) + ->format; $template->param( %$budgetperiod_hash ); diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 1491561cec..8d3f3e8336 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -23,7 +23,6 @@ use Modern::Perl; use CGI; use List::Util qw/min/; -use Number::Format qw(format_price); use Koha::Database; use C4::Auth qw/get_user_subpermissions/; diff --git a/admin/aqplan.pl b/admin/aqplan.pl index 53fa415594..cc397fe197 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -27,7 +27,6 @@ use List::Util qw/min/; use Date::Calc qw/Delta_YMD Easter_Sunday Today Decode_Date_EU/; use Date::Manip qw/ ParseDate UnixDate DateCalc/; use C4::Dates qw/format_date format_date_in_iso/; -use Number::Format qw(format_price); use Text::CSV_XS; use C4::Acquisition; -- 2.39.2