Bug 12979: Price formatting should only be defined at one place
authorJonathan Druart <jonathan.druart@biblibre.com>
Tue, 23 Sep 2014 09:32:14 +0000 (11:32 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Fri, 7 Nov 2014 18:03:30 +0000 (15:03 -0300)
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 <paola.rossi@cineca.it>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

acqui/acqui-home.pl
acqui/addorderiso2709.pl
acqui/pdfformat/layout2pages.pm
acqui/pdfformat/layout2pagesde.pm
acqui/pdfformat/layout3pages.pm
acqui/pdfformat/layout3pagesfr.pm
admin/aqbudgetperiods.pl
admin/aqbudgets.pl
admin/aqplan.pl

index 3231e62..8741aa4 100755 (executable)
@@ -28,7 +28,6 @@ this script is the main page for acqui
 
 use strict;
 use warnings;
-use Number::Format;
 
 use CGI;
 use C4::Auth;
index 15c83ea..666e771 100755 (executable)
@@ -24,7 +24,6 @@
 use Modern::Perl;
 use CGI;
 use Carp;
-use Number::Format qw(:all);
 use YAML qw/Load/;
 
 use C4::Context;
index 29d6c4b..15b9838 100644 (file)
@@ -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);
         }
index 38a8400..6ac57b0 100644 (file)
@@ -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);
         }
index 5640a1c..a38f4d3 100644 (file)
@@ -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.
 
index 28ab804..6ddb87a 100644 (file)
@@ -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.
 
index 9084540..119884a 100755 (executable)
@@ -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
         );
index 1491561..8d3f3e8 100755 (executable)
@@ -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/;
index 53fa415..cc397fe 100755 (executable)
@@ -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;