1 package Koha
::Number
::Price
;
3 # This file is part of Koha.
5 # Copyright 2014 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Number
::Format
qw( format_price );
24 use Koha
::Acquisition
::Currencies
;
26 use base
qw( Class::Accessor );
27 __PACKAGE__
->mk_accessors(qw( value ));
30 my ( $class, $value ) = @_;
32 my $self->{value
} = $value || 0;
39 my ( $self, $params ) = @_;
40 return unless defined $self->value;
42 my $format_params = $self->_format_params( $params );
44 return Number
::Format
->new(%$format_params)->format_price($self->value);
47 sub format_for_editing
{
48 my ( $self, $params ) = @_;
49 return unless defined $self->value;
51 my $format_params = $self->_format_params( $params );
54 int_curr_symbol
=> '',
55 mon_thousands_sep
=> '',
56 mon_decimal_point
=> '.',
59 return Number
::Format
->new(%$format_params)->format_price($self->value);
63 my ( $self, $params ) = @_;
64 return unless defined $self->value;
66 my $format_params = $self->_format_params( $params );
68 return Number
::Format
->new(%$format_params)->unformat_number($self->value);
73 return unless defined $self->value;
75 my $format_params = $self->_format_params;
77 return Number
::Format
->new(%$format_params)->round($self->value);
81 my ( $self, $params ) = @_;
82 my $with_symbol = $params->{with_symbol
} || 0;
83 my $p_cs_precedes = $params->{p_cs_precedes
};
84 my $p_sep_by_space = $params->{p_sep_by_space
};
85 my $currency = Koha
::Acquisition
::Currencies
->get_active;
86 my $currency_format = C4
::Context
->preference("CurrencyFormat");
88 my $int_curr_symbol = q
||;
92 int_curr_symbol
=> $int_curr_symbol,
93 mon_thousands_sep
=> ',',
95 mon_decimal_point
=> '.'
98 if ( $currency_format eq 'FR' ) {
99 # FIXME This test should be done for all currencies
100 $int_curr_symbol = $currency->symbol if $with_symbol;
103 decimal_point
=> ',',
104 int_curr_symbol
=> $int_curr_symbol,
105 mon_thousands_sep
=> ' ',
106 thousands_sep
=> ' ',
107 mon_decimal_point
=> ','
111 if ( $currency_format eq 'CH' ) {
112 $int_curr_symbol = $currency->symbol if $with_symbol;
115 decimal_point
=> '.',
116 int_curr_symbol
=> $int_curr_symbol,
117 mon_thousands_sep
=> '\'',
118 thousands_sep
=> '\'',
119 mon_decimal_point
=> '.'
124 $format_params{p_cs_precedes
} = $p_cs_precedes if defined $p_cs_precedes;
125 $format_params{p_sep_by_space
} = ( $int_curr_symbol and defined $p_sep_by_space ) ?
$p_sep_by_space : 0;
127 return \
%format_params;