From 4bdc80312017732dfa6d21671382cdc89ef4e0ad Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 28 Aug 2014 16:20:27 +0200 Subject: [PATCH] Bug 12844: Use Koha::Number::Price where it can be useful This patch use the new module into pl and tt script. Note that we could use it in the acqui/pdfformat/layout*.pm files. Test plan: 1/ Verify that the acquisition home page displayes the prices as before. 2/ Verify that the budgets page displayes the prices as before. 3/ Verify that the funds page displayes the prices as before. 4/ Verify that the planning page displayes the prices as before. (Note that 1 price is now formatted: 'Fund remaining'). 5/ Create an order from a staged file. This stage file should contain a formatted price. Signed-off-by: Paola Rossi Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- acqui/acqui-home.pl | 43 ++++--------------- acqui/addorderiso2709.pl | 3 +- admin/aqbudgetperiods.pl | 24 +---------- admin/aqbudgets.pl | 20 ++------- admin/aqplan.pl | 22 ---------- .../prog/en/modules/acqui/acqui-home.tt | 25 +++++------ .../prog/en/modules/admin/aqbudgetperiods.tt | 7 ++- .../prog/en/modules/admin/aqbudgets.tt | 39 +++++++++-------- .../prog/en/modules/admin/aqplan.tt | 5 ++- 9 files changed, 55 insertions(+), 133 deletions(-) diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl index 8cffc26ca3..348174511d 100755 --- a/acqui/acqui-home.pl +++ b/acqui/acqui-home.pl @@ -54,27 +54,6 @@ my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( my $user = GetMember( 'borrowernumber' => $loggedinuser ); my $branchname = GetBranchName($user->{branchcode}); - -my $num_formatter; - -my $cur_format = C4::Context->preference("CurrencyFormat"); -if ( $cur_format eq 'FR' ) { - $num_formatter = Number::Format->new( - 'decimal_fill' => '2', - 'decimal_point' => ',', - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ' ', - 'thousands_sep' => ' ', - 'mon_decimal_point' => ',' - ); -} else { # US by default.. - $num_formatter = Number::Format->new( - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ',', - 'mon_decimal_point' => '.' - ); -} - my $status = $query->param('status') || "ASKED"; my $suggestions_count = CountSuggestion($status); @@ -134,10 +113,6 @@ foreach my $budget ( @{$budget_arr} ) { $totavail_active += $budget->{'budget_avail'}; } - for my $field (qw( budget_amount budget_spent budget_ordered budget_avail ) ) { - $budget->{"formatted_$field"} = $num_formatter->format_price( $budget->{$field} ); - } - push @budget_loop, $budget; } @@ -145,15 +120,15 @@ $template->param( type => 'intranet', loop_budget => \@budget_loop, branchname => $branchname, - total => $num_formatter->format_price($total), - totspent => $num_formatter->format_price($totspent), - totordered => $num_formatter->format_price($totordered), - totcomtd => $num_formatter->format_price($totcomtd), - totavail => $num_formatter->format_price($totavail), - total_active => $num_formatter->format_price($total_active), - totspent_active => $num_formatter->format_price($totspent_active), - totordered_active => $num_formatter->format_price($totordered_active), - totavail_active => $num_formatter->format_price($totavail_active), + total => $total, + totspent => $totspent, + totordered => $totordered, + totcomtd => $totcomtd, + totavail => $totavail, + total_active => $total_active, + totspent_active => $totspent_active, + totordered_active => $totordered_active, + totavail_active => $totavail_active, suggestions_count => $suggestions_count, ); diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 601482ab9c..d5e99ecab7 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -141,7 +141,6 @@ if ($op eq ""){ # 3rd step = import the records # } elsif ( $op eq 'import_records' ) { - my $num=FormatNumber(); #import selected lines $template->param('basketno' => $cgiparams->{'basketno'}); # Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards @@ -227,7 +226,7 @@ if ($op eq ""){ # in France, the cents separator is the , but sometimes, ppl use a . # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; - $price = $num->unformat_number($price); + $price = Koha::Number::Price->new($price)->unformat; $orderinfo{gstrate} = $bookseller->{gstrate}; my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; if ( $bookseller->{listincgst} ) { diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index d92ce3755b..9084540712 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -91,30 +91,11 @@ my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( ); +# This is used in incbudgets-active-currency.inc my $cur = GetCurrency(); $template->param( symbol => $cur->{symbol}, currency => $cur->{currency} ); -my $cur_format = C4::Context->preference("CurrencyFormat"); -my $num; - -if ( $cur_format eq 'US' ) { - $num = new Number::Format( - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ',', - 'mon_decimal_point' => '.' - ); -} elsif ( $cur_format eq 'FR' ) { - $num = new Number::Format( - 'decimal_fill' => '2', - 'decimal_point' => ',', - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ' ', - 'thousands_sep' => ' ', - 'mon_decimal_point' => ',' - ); -} - # ADD OR MODIFY A BUDGET PERIOD - BUILD SCREEN if ( $op eq 'add_form' ) { @@ -161,7 +142,6 @@ elsif ( $op eq 'delete_confirm' ) { my $total = 0; my $data = GetBudgetPeriod( $budget_period_id); - $$data{'budget_period_total'}=$num->format_price( $data->{'budget_period_total'}); $template->param( %$data ); @@ -291,7 +271,6 @@ my @period_active_loop; foreach my $result ( @{$results}[ $first .. $last ] ) { my $budgetperiod = $result; - $budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} ); $budgetperiod->{budget_active} = 1; push( @period_active_loop, $budgetperiod ); } @@ -310,7 +289,6 @@ $last = min( $first + $inactivepagesize - 1, scalar @{$results} - 1, ); my @period_inactive_loop; foreach my $result ( @{$results}[ $first .. $last ] ) { my $budgetperiod = $result; - $budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} ); $budgetperiod->{budget_active} = 1; push( @period_inactive_loop, $budgetperiod ); } diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index accdb78012..fa914d5917 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -67,7 +67,6 @@ if (not defined $template->{VARS}->{'CAN_user_acquisition_budget_add_del'} { $op = 'list'; } -my $num=FormatNumber; # get only the columns of aqbudgets in budget_hash my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns; @@ -228,7 +227,7 @@ if ($op eq 'add_form') { budget_id => $budget->{'budget_id'}, budget_code => $budget->{'budget_code'}, budget_name => $budget->{'budget_name'}, - budget_amount => $num->format_price( $budget->{'budget_amount'} ), + budget_amount => $budget->{'budget_amount'}, ); # END $OP eq DELETE_CONFIRM # called by delete_confirm, used to effectively confirm deletion of data in DB @@ -307,18 +306,9 @@ if ( $op eq 'list' ) { if (!defined $budget->{'budget_unalloc_sublevel'} or $budget->{'budget_unalloc_sublevel'} == 0); - for (grep {/total_spent|budget_spent|total_ordered|budget_ordered|budget_amount/} keys %$budget){ - $budget->{$_} = $num->format_price( $budget->{$_} ) if defined($budget->{$_}) - } - for (qw/budget_remaining total_remaining/) { - if (defined $budget->{$_}) { - $budget->{$_.'_display'} = $num->format_price($budget->{$_}); - } - } - # Value of budget_spent equals 0 instead of undefined value - $budget->{"budget_spent"} = $num->format_price(0) unless defined($budget->{"budget_spent"}); - $budget->{budget_ordered} = $num->format_price(0) unless defined($budget->{"budget_ordered"}); + $budget->{budget_spent} = 0 unless defined($budget->{budget_spent}); + $budget->{budget_ordered} = 0 unless defined($budget->{budget_ordered}); #Make a list of parents of the bugdet my @budget_hierarchy; @@ -337,10 +327,6 @@ if ( $op eq 'list' ) { my $budget_period_total = $period->{budget_period_total}; - foreach ($budget_period_total, $period_alloc_total, $spent_total, $ordered_total, $available_total) { - $_ = $num->format_price($_); - } - my $periods = GetBudgetPeriods(); $template->param( diff --git a/admin/aqplan.pl b/admin/aqplan.pl index 4be57a6dfb..53fa415594 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -101,26 +101,6 @@ my $show_mine = $input->param('show_mine') ; my @hide_cols = $input->param('hide_cols'); -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' => '.' - ); -} - if ( $budget_period_locked == 1 && not defined $show_actual ) { $show_actual = 1; } @@ -395,7 +375,6 @@ foreach my $budget (@budgets) { %budget_line = ( lines => \@cells_line, budget_name_indent => $budget->{budget_name_indent}, - budget_amount_formatted => $num->format_price( $budget->{budget_amount} ), budget_amount => $budget->{budget_amount}, budget_alloc => $budget->{budget_alloc}, budget_act_remain => sprintf( "%.2f", $budget_act_remain ), @@ -433,7 +412,6 @@ $template->param( show_actual => $show_actual, show_percent => $show_percent, show_mine => $show_mine, - cur_format => $cur_format, CGIextChoice => $CGIextChoice, CGIsepChoice => $CGIsepChoice, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt index 3a4cf903a3..3c1df1020e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt @@ -1,3 +1,4 @@ +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions @@ -123,10 +124,10 @@ $(document).ready(function() {       - [% total %][% total_active %] - [% totordered %][% totordered_active %] - [% totspent %][% totspent_active %] - [% totavail %][% totavail_active %] + [% total %][% total_active | $Price %] + [% totordered %][% totordered_active | $Price %] + [% totspent %][% totspent_active | $Price %] + [% totavail %][% totavail_active | $Price %] @@ -149,10 +150,10 @@ $(document).ready(function() { [% END %] [% loop_budge.budget_branchname %] - [% loop_budge.formatted_budget_amount %] - [% loop_budge.formatted_budget_ordered %] - [% loop_budge.formatted_budget_spent %] - [% loop_budge.formatted_budget_avail %] + [% loop_budge.budget_amount | $Price %] + [% loop_budge.budget_ordered | $Price %] + [% loop_budge.budget_spent | $Price %] + [% loop_budge.budget_avail | $Price %] [% ELSE %] @@ -172,10 +173,10 @@ $(document).ready(function() { [% END %] [% loop_budge.budget_branchname %] - [% loop_budge.formatted_budget_amount %] - [% loop_budge.formatted_budget_ordered %] - [% loop_budge.formatted_budget_spent %] - [% loop_budge.formatted_budget_avail %] + [% loop_budge.budget_amount | $Price %] + [% loop_budge.budget_ordered | $Price %] + [% loop_budge.budget_spent | $Price %] + [% loop_budge.budget_avail | $Price %] [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt index fab8c92faf..b2184c5355 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt @@ -1,5 +1,7 @@ [% USE KohaDates %] [% USE format %] +[% USE Price %] + [%- BLOCK action_menu %] [% END -%] + [% INCLUDE 'doc-head-open.inc' %] [% INCLUDE 'doc-head-close.inc' %] @@ -562,7 +565,7 @@ Locked  [% END %] - [% period_active.budget_period_total %] + [% period_active.budget_period_total | $Price %] [% PROCESS action_menu block_budget_id=period_active.budget_period_id %] @@ -595,7 +598,7 @@ [% period_loo.budget_period_startdate | $KohaDates %] [% period_loo.budget_period_enddate | $KohaDates %] [% IF ( period_loo.budget_period_locked ) %]Locked [% ELSE %][% END %] - [% period_loo.budget_period_total %] + [% period_loo.budget_period_total | $Price %] [% PROCESS action_menu block_budget_id=period_loo.budget_period_id %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index b0c434409b..bec6272ffd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -1,3 +1,4 @@ +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Funds[% IF op == 'add_form' %] › [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -294,14 +295,14 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") - Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %] - [% period_alloc_total %] + Period allocated [% IF budget_period_total %][% budget_period_total | $Price %][% END %] + [% period_alloc_total | $Price %] - [% ordered_total %] + [% ordered_total | $Price %] - [% spent_total %] + [% spent_total | $Price %] - [% available_total %] + [% available_total | $Price %] @@ -318,37 +319,37 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") [% budget.budget_name %] [% IF budget.budget_parent_id %] - [% budget.budget_amount %] + [% budget.budget_amount | $Price %] [% ELSE %] - [% budget.budget_amount %] + [% budget.budget_amount | $Price %] [% END %] [% IF budget.budget_parent_id %] - [% budget.budget_ordered %] + [% budget.budget_ordered | $Price %] [% ELSE %] - [% budget.budget_ordered %] + [% budget.budget_ordered | $Price %] [% END %] [% IF budget.budget_parent_id %] - [% budget.total_ordered %] + [% budget.total_ordered | $Price %] [% ELSE %] - [% budget.total_ordered %] + [% budget.total_ordered | $Price %] [% END %] [% IF budget.budget_parent_id %] - [% budget.budget_spent %] + [% budget.budget_spent | $Price %] [% ELSE %] - [% budget.budget_spent %] + [% budget.budget_spent | $Price %] [% END %] [% IF budget.budget_parent_id %] - [% budget.total_spent %] + [% budget.total_spent | $Price %] [% ELSE %] - [% budget.total_spent %] + [% budget.total_spent | $Price %] [% END %] @@ -371,14 +372,14 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") [% END %] [% END %] - [% text %] + [% value | $Price %] [% END %] - [% INCLUDE colorcellvalue value=budget.budget_remaining text=budget.budget_remaining_display parent=budget.budget_parent_id %] + [% INCLUDE colorcellvalue value=budget.budget_remaining parent=budget.budget_parent_id %] - [% INCLUDE colorcellvalue value=budget.total_remaining text=budget.total_remaining_display parent=budget.budget_parent_id %] + [% INCLUDE colorcellvalue value=budget.total_remaining parent=budget.budget_parent_id %] [% IF ( budget.budget_lock ) %] @@ -596,7 +597,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") - +
Fund amount:[% budget_amount %][% budget_amount | $Price %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqplan.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqplan.tt index 65cd9c4e18..7f1c65d46d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqplan.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqplan.tt @@ -1,3 +1,4 @@ +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Budgets › Funds › Planning for [% budget_period_description %] by [% authcat %] [% INCLUDE 'doc-head-close.inc' %] @@ -132,7 +133,7 @@ [% END %]
[% budget_line.budget_name_indent %] - [% budget_line.budget_amount_formatted %]  + [% budget_line.budget_amount | $Price %]  @@ -185,7 +186,7 @@ [% ELSE %] [% END %] - [% budget_line.budget_est_remain %]  + [% budget_line.budget_est_remain | $Price %]  -- 2.39.5