View | Details | Raw Unified | Return to bug 13352
Collapse All | Expand All

(-)a/Koha/Number/Price.pm (+15 lines)
Lines 44-49 sub format { Link Here
44
    return Number::Format->new(%$format_params)->format_price($self->value);
44
    return Number::Format->new(%$format_params)->format_price($self->value);
45
}
45
}
46
46
47
sub format_for_editing {
48
    my ( $self, $params ) = @_;
49
    return unless defined $self->value;
50
51
    my $format_params = $self->_format_params( $params );
52
    $format_params = {
53
        %$format_params,
54
        int_curr_symbol   => '',
55
        mon_thousands_sep => '',
56
        mon_decimal_point => '.',
57
    };
58
59
    return Number::Format->new(%$format_params)->format_price($self->value);
60
}
61
47
sub unformat {
62
sub unformat {
48
    my ( $self, $params ) = @_;
63
    my ( $self, $params ) = @_;
49
    return unless defined $self->value;
64
    return unless defined $self->value;
(-)a/Koha/Template/Plugin/Price.pm (-2 / +7 lines)
Lines 23-33 use Template::Plugin::Filter; Link Here
23
use base qw( Template::Plugin::Filter );
23
use base qw( Template::Plugin::Filter );
24
24
25
use Koha::Number::Price;
25
use Koha::Number::Price;
26
our $DYNAMIC = 1;
26
27
27
sub filter {
28
sub filter {
28
    my ( $self, $value ) = @_;
29
    my ( $self, $value, $args, $config ) = @_;
29
    $value ||= 0;
30
    $value ||= 0;
30
    return Koha::Number::Price->new( $value )->format;
31
    $config->{on_editing} //= 0;
32
    my $formatted_price;
33
    return $config->{on_editing}
34
        ? Koha::Number::Price->new( $value )->format_for_editing
35
        : Koha::Number::Price->new( $value )->format;
31
}
36
}
32
37
33
1;
38
1;
(-)a/admin/aqbudgetperiods.pl (-6 lines)
Lines 46-52 script to administer the budget periods table Link Here
46
46
47
use Modern::Perl;
47
use Modern::Perl;
48
48
49
use Number::Format qw(format_price);
50
use CGI qw ( -utf8 );
49
use CGI qw ( -utf8 );
51
use List::Util qw/min/;
50
use List::Util qw/min/;
52
use Koha::DateUtils;
51
use Koha::DateUtils;
Lines 59-66 use C4::Acquisition; Link Here
59
use C4::Budgets;
58
use C4::Budgets;
60
use C4::Debug;
59
use C4::Debug;
61
60
62
use Koha::Number::Price;
63
64
my $dbh = C4::Context->dbh;
61
my $dbh = C4::Context->dbh;
65
62
66
my $input       = new CGI;
63
my $input       = new CGI;
Lines 108-116 if ( $op eq 'add_form' ) { Link Here
108
		my $budgetperiod_hash=GetBudgetPeriod($budget_period_id);
105
		my $budgetperiod_hash=GetBudgetPeriod($budget_period_id);
109
        # get dropboxes
106
        # get dropboxes
110
107
111
        $budgetperiod_hash->{budget_period_total} =
112
          Koha::Number::Price->new( $budgetperiod_hash->{budget_period_total} )
113
          ->format;
114
        $template->param(
108
        $template->param(
115
			%$budgetperiod_hash
109
			%$budgetperiod_hash
116
        );
110
        );
(-)a/admin/aqbudgets.pl (-1 lines)
Lines 130-136 if ($op eq 'add_form') { Link Here
130
        $dropbox_disabled = BudgetHasChildren($budget_id);
130
        $dropbox_disabled = BudgetHasChildren($budget_id);
131
        my $borrower = &GetMember( borrowernumber=>$budget->{budget_owner_id} );
131
        my $borrower = &GetMember( borrowernumber=>$budget->{budget_owner_id} );
132
        $budget->{budget_owner_name} = ( $borrower ? $borrower->{'firstname'} . ' ' . $borrower->{'surname'} : '' );
132
        $budget->{budget_owner_name} = ( $borrower ? $borrower->{'firstname'} . ' ' . $borrower->{'surname'} : '' );
133
        $$budget{$_}= sprintf("%.2f", $budget->{$_}) for grep{ /amount|encumb|expend/ } keys %$budget;
134
    }
133
    }
135
134
136
    # build budget hierarchy
135
    # build budget hierarchy
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt (-4 / +3 lines)
Lines 1-5 Link Here
1
[% USE KohaDates %]
1
[% USE KohaDates %]
2
[% USE format %]
3
[% USE Price %]
2
[% USE Price %]
4
3
5
[%- BLOCK action_menu %]
4
[%- BLOCK action_menu %]
Lines 360-366 Link Here
360
        <!-- ############################## -->
359
        <!-- ############################## -->
361
        <label for="budget_period_total">Total amount: </label>
360
        <label for="budget_period_total">Total amount: </label>
362
        <input type="text" id="budget_period_total" name="budget_period_total"
361
        <input type="text" id="budget_period_total" name="budget_period_total"
363
        size="10" maxlength="80" value="[% budget_period_total %]" />
362
        size="10" maxlength="80" value="[% budget_period_total | $Price on_editing => 1 %]" />
364
    </li>
363
    </li>
365
364
366
    <li>
365
    <li>
Lines 498-504 Link Here
498
            [% IF r.orders_moved.size > 0 %]
497
            [% IF r.orders_moved.size > 0 %]
499
              [% FOR order IN r.orders_moved %]
498
              [% FOR order IN r.orders_moved %]
500
                <tr>
499
                <tr>
501
                  <td>[% r.budget.budget_name %] (id=[% r.budget.budget_id %]) Amount=[% r.budget.budget_amount | format ("%.2f") %][% IF r.unspent_moved %] ([% r.unspent_moved | format ("%.2f")%] remaining has been moved)[% END %]</td>
500
                  <td>[% r.budget.budget_name %] (id=[% r.budget.budget_id %]) Amount=[% r.budget.budget_amount | $Price %][% IF r.unspent_moved %] ([% r.unspent_moved | $Price %] remaining has been moved)[% END %]</td>
502
                  <td>[% order.basketname %]</td>
501
                  <td>[% order.basketname %]</td>
503
                  <td>[% order.ordernumber %]</td>
502
                  <td>[% order.ordernumber %]</td>
504
                  <td>Moved!</td>
503
                  <td>Moved!</td>
Lines 515-521 Link Here
515
          [% ELSE %]
514
          [% ELSE %]
516
            [% IF r.error == 'budget_code_not_exists' %]
515
            [% IF r.error == 'budget_code_not_exists' %]
517
              <tr>
516
              <tr>
518
                <td>[% r.budget.budget_id %] [% r.budget.budget_amount | format ("%.2f") %][% IF r.unspent_moved %] ([% r.unspent_moved | format ("%.2f") %] remaining has been moved)[% END %]</td>
517
                <td>[% r.budget.budget_id %] [% r.budget.budget_amount | $Price %][% IF r.unspent_moved %] ([% r.unspent_moved | $Price %] remaining has been moved)[% END %]</td>
519
                <td></td>
518
                <td></td>
520
                <td></td>
519
                <td></td>
521
                <td>This fund code does not exist in the destination budget.</td>
520
                <td>This fund code does not exist in the destination budget.</td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (-3 / +3 lines)
Lines 449-466 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
449
449
450
    <li>
450
    <li>
451
    <label style="white-space: nowrap;" for="budget_amount" class="required">Amount: </label>
451
    <label style="white-space: nowrap;" for="budget_amount" class="required">Amount: </label>
452
    <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount %]" size="8" />
452
    <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount | $Price on_editing => 1 %]" size="8" />
453
    </li>
453
    </li>
454
454
455
    <li>
455
    <li>
456
      <label for="budget_encumb">Warning at (%): </label>
456
      <label for="budget_encumb">Warning at (%): </label>
457
      <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb %]" size="10" />
457
      <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb | $Price on_editing => 1 %]" size="10" />
458
      <span class="hint">0 to disable</span>
458
      <span class="hint">0 to disable</span>
459
    </li>
459
    </li>
460
460
461
    <li>
461
    <li>
462
      <label for="budget_expend">Warning at (amount): </label>
462
      <label for="budget_expend">Warning at (amount): </label>
463
      <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend %]" size="10" />
463
      <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend | $Price on_editing => 1 %]" size="10" />
464
      <span class="hint">0 to disable</span>
464
      <span class="hint">0 to disable</span>
465
    </li>
465
    </li>
466
466
(-)a/t/Prices.t (-2 / +8 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 12;
2
use Test::More tests => 16;
3
use Test::MockModule;
3
use Test::MockModule;
4
4
5
use t::lib::Mocks;
5
use t::lib::Mocks;
Lines 403-405 sub compare { Link Here
403
"configuration $params->{conf}: $params->{field} should be correctly calculated"
403
"configuration $params->{conf}: $params->{field} should be correctly calculated"
404
    );
404
    );
405
}
405
}
406
- 
406
407
# format_for_editing
408
for my $currency_format ( qw( US FR ) ) {
409
    t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
410
    is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
411
    is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );
412
}

Return to bug 13352