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

(-)a/C4/Budgets.pm (+28 lines)
Lines 985-990 sub ConvertCurrency { Link Here
985
    return ( $price / $cur );
985
    return ( $price / $cur );
986
}
986
}
987
987
988
sub _round {
989
    my ($value, $increment) = @_;
990
991
    if ($increment && $increment != 0) {
992
        $value = int($value / $increment) * $increment;
993
    }
994
995
    return $value;
996
}
988
997
989
=head2 CloneBudgetPeriod
998
=head2 CloneBudgetPeriod
990
999
Lines 1011-1016 sub CloneBudgetPeriod { Link Here
1011
    my $budget_period_startdate   = $params->{budget_period_startdate};
1020
    my $budget_period_startdate   = $params->{budget_period_startdate};
1012
    my $budget_period_enddate     = $params->{budget_period_enddate};
1021
    my $budget_period_enddate     = $params->{budget_period_enddate};
1013
    my $budget_period_description = $params->{budget_period_description};
1022
    my $budget_period_description = $params->{budget_period_description};
1023
    my $amount_change_percentage  = $params->{amount_change_percentage};
1024
    my $amount_change_round_increment = $params->{amount_change_round_increment};
1014
    my $mark_original_budget_as_inactive =
1025
    my $mark_original_budget_as_inactive =
1015
      $params->{mark_original_budget_as_inactive} || 0;
1026
      $params->{mark_original_budget_as_inactive} || 0;
1016
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
1027
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
Lines 1022-1027 sub CloneBudgetPeriod { Link Here
1022
    $budget_period->{budget_period_description} = $budget_period_description;
1033
    $budget_period->{budget_period_description} = $budget_period_description;
1023
    # The new budget (budget_period) should be active by default
1034
    # The new budget (budget_period) should be active by default
1024
    $budget_period->{budget_period_active}    = 1;
1035
    $budget_period->{budget_period_active}    = 1;
1036
1037
    if ($amount_change_percentage) {
1038
        my $total = $budget_period->{budget_period_total};
1039
        $total += $total * $amount_change_percentage / 100;
1040
        $total = _round($total, $amount_change_round_increment);
1041
        $budget_period->{budget_period_total} = $total;
1042
    }
1043
1025
    my $original_budget_period_id = $budget_period->{budget_period_id};
1044
    my $original_budget_period_id = $budget_period->{budget_period_id};
1026
    delete $budget_period->{budget_period_id};
1045
    delete $budget_period->{budget_period_id};
1027
    my $new_budget_period_id = AddBudgetPeriod( $budget_period );
1046
    my $new_budget_period_id = AddBudgetPeriod( $budget_period );
Lines 1049-1054 sub CloneBudgetPeriod { Link Here
1049
            $budget->{budget_amount} = 0;
1068
            $budget->{budget_amount} = 0;
1050
            ModBudget( $budget );
1069
            ModBudget( $budget );
1051
        }
1070
        }
1071
    } elsif ($amount_change_percentage) {
1072
        my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
1073
        for my $budget ( @$budgets ) {
1074
            my $amount = $budget->{budget_amount};
1075
            $amount += $amount * $amount_change_percentage / 100;
1076
            $amount = _round($amount, $amount_change_round_increment);
1077
            $budget->{budget_amount} = $amount;
1078
            ModBudget( $budget );
1079
        }
1052
    }
1080
    }
1053
1081
1054
    return $new_budget_period_id;
1082
    return $new_budget_period_id;
(-)a/admin/aqbudgetperiods.pl (+4 lines)
Lines 163-168 elsif ( $op eq 'duplicate_budget' ){ Link Here
163
    my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
163
    my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
164
    my $budget_period_enddate   = dt_from_string $input->param('budget_period_enddate');
164
    my $budget_period_enddate   = dt_from_string $input->param('budget_period_enddate');
165
    my $budget_period_description = $input->param('budget_period_description');
165
    my $budget_period_description = $input->param('budget_period_description');
166
    my $amount_change_percentage = $input->param('amount_change_percentage');
167
    my $amount_change_round_increment = $input->param('amount_change_round_increment');
166
    my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
168
    my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
167
    my $reset_all_budgets = $input->param('reset_all_budgets');
169
    my $reset_all_budgets = $input->param('reset_all_budgets');
168
170
Lines 172-177 elsif ( $op eq 'duplicate_budget' ){ Link Here
172
            budget_period_startdate => $budget_period_startdate,
174
            budget_period_startdate => $budget_period_startdate,
173
            budget_period_enddate   => $budget_period_enddate,
175
            budget_period_enddate   => $budget_period_enddate,
174
            budget_period_description => $budget_period_description,
176
            budget_period_description => $budget_period_description,
177
            amount_change_percentage => $amount_change_percentage,
178
            amount_change_round_increment => $amount_change_round_increment,
175
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
179
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
176
            reset_all_budgets => $reset_all_budgets,
180
            reset_all_budgets => $reset_all_budgets,
177
        }
181
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt (+12 lines)
Lines 285-290 Link Here
285
    </li>
285
    </li>
286
286
287
    <li>
287
    <li>
288
      <label for="amount_change_percentage">Change amounts by</label>
289
      <input type="text" id="amount_change_percentage" name="amount_change_percentage" /> %
290
      <div class="hint">(can be positive or negative)</div>
291
    </li>
292
293
    <li>
294
      <label for="amount_change_round_increment">If amounts changed, round to a multiple of</label>
295
      <input type="text" id="amount_change_round_increment" name="amount_change_round_increment" />
296
      <div class="hint">(amounts will be rounded down)</div>
297
    </li>
298
299
    <li>
288
      <label for="mark_as_inactive">Mark the original budget as inactive</label>
300
      <label for="mark_as_inactive">Mark the original budget as inactive</label>
289
      <input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
301
      <input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
290
    </li>
302
    </li>
(-)a/t/db_dependent/Budgets.t (-2 / +22 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 122;
2
use Test::More tests => 129;
3
3
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
Lines 469-474 is( $number_of_budgets_not_reset, 0, Link Here
469
    'CloneBudgetPeriod has reset all budgets (funds)' );
469
    'CloneBudgetPeriod has reset all budgets (funds)' );
470
470
471
471
472
# CloneBudgetPeriod with param amount_change_*
473
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
474
    {
475
        budget_period_id        => $budget_period_id,
476
        budget_period_startdate => '2014-01-01',
477
        budget_period_enddate   => '2014-12-31',
478
        amount_change_percentage => 16,
479
        amount_change_round_increment => 5,
480
    }
481
);
482
483
$budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned);
484
cmp_ok($budget_period_cloned->{budget_period_total}, '==', 11600, "CloneBudgetPeriod changed correctly budget amount");
485
$budget_hierarchy_cloned     = GetBudgetHierarchy($budget_period_id_cloned);
486
cmp_ok($budget_hierarchy_cloned->[0]->{budget_amount}, '==', 1160, "CloneBudgetPeriod changed correctly funds amounts");
487
cmp_ok($budget_hierarchy_cloned->[1]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
488
cmp_ok($budget_hierarchy_cloned->[2]->{budget_amount}, '==', 55, "CloneBudgetPeriod changed correctly funds amounts");
489
cmp_ok($budget_hierarchy_cloned->[3]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
490
cmp_ok($budget_hierarchy_cloned->[4]->{budget_amount}, '==', 2320, "CloneBudgetPeriod changed correctly funds amounts");
491
cmp_ok($budget_hierarchy_cloned->[5]->{budget_amount}, '==', 0, "CloneBudgetPeriod changed correctly funds amounts");
492
472
# MoveOrders
493
# MoveOrders
473
my $number_orders_moved = C4::Budgets::MoveOrders();
494
my $number_orders_moved = C4::Budgets::MoveOrders();
474
is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
495
is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
475
- 

Return to bug 15004