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

(-)a/C4/Budgets.pm (+28 lines)
Lines 1005-1010 sub ConvertCurrency { Link Here
1005
    return ( $price / $cur );
1005
    return ( $price / $cur );
1006
}
1006
}
1007
1007
1008
sub _round {
1009
    my ($value, $increment) = @_;
1010
1011
    if ($increment && $increment != 0) {
1012
        $value = int($value / $increment) * $increment;
1013
    }
1014
1015
    return $value;
1016
}
1008
1017
1009
=head2 CloneBudgetPeriod
1018
=head2 CloneBudgetPeriod
1010
1019
Lines 1031-1036 sub CloneBudgetPeriod { Link Here
1031
    my $budget_period_startdate   = $params->{budget_period_startdate};
1040
    my $budget_period_startdate   = $params->{budget_period_startdate};
1032
    my $budget_period_enddate     = $params->{budget_period_enddate};
1041
    my $budget_period_enddate     = $params->{budget_period_enddate};
1033
    my $budget_period_description = $params->{budget_period_description};
1042
    my $budget_period_description = $params->{budget_period_description};
1043
    my $amount_change_percentage  = $params->{amount_change_percentage};
1044
    my $amount_change_round_increment = $params->{amount_change_round_increment};
1034
    my $mark_original_budget_as_inactive =
1045
    my $mark_original_budget_as_inactive =
1035
      $params->{mark_original_budget_as_inactive} || 0;
1046
      $params->{mark_original_budget_as_inactive} || 0;
1036
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
1047
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
Lines 1042-1047 sub CloneBudgetPeriod { Link Here
1042
    $budget_period->{budget_period_description} = $budget_period_description;
1053
    $budget_period->{budget_period_description} = $budget_period_description;
1043
    # The new budget (budget_period) should be active by default
1054
    # The new budget (budget_period) should be active by default
1044
    $budget_period->{budget_period_active}    = 1;
1055
    $budget_period->{budget_period_active}    = 1;
1056
1057
    if ($amount_change_percentage) {
1058
        my $total = $budget_period->{budget_period_total};
1059
        $total += $total * $amount_change_percentage / 100;
1060
        $total = _round($total, $amount_change_round_increment);
1061
        $budget_period->{budget_period_total} = $total;
1062
    }
1063
1045
    my $original_budget_period_id = $budget_period->{budget_period_id};
1064
    my $original_budget_period_id = $budget_period->{budget_period_id};
1046
    delete $budget_period->{budget_period_id};
1065
    delete $budget_period->{budget_period_id};
1047
    my $new_budget_period_id = AddBudgetPeriod( $budget_period );
1066
    my $new_budget_period_id = AddBudgetPeriod( $budget_period );
Lines 1069-1074 sub CloneBudgetPeriod { Link Here
1069
            $budget->{budget_amount} = 0;
1088
            $budget->{budget_amount} = 0;
1070
            ModBudget( $budget );
1089
            ModBudget( $budget );
1071
        }
1090
        }
1091
    } elsif ($amount_change_percentage) {
1092
        my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
1093
        for my $budget ( @$budgets ) {
1094
            my $amount = $budget->{budget_amount};
1095
            $amount += $amount * $amount_change_percentage / 100;
1096
            $amount = _round($amount, $amount_change_round_increment);
1097
            $budget->{budget_amount} = $amount;
1098
            ModBudget( $budget );
1099
        }
1072
    }
1100
    }
1073
1101
1074
    return $new_budget_period_id;
1102
    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 => 120;
2
use Test::More tests => 127;
3
3
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
Lines 461-466 is( $number_of_budgets_not_reset, 0, Link Here
461
    'CloneBudgetPeriod has reset all budgets (funds)' );
461
    'CloneBudgetPeriod has reset all budgets (funds)' );
462
462
463
463
464
# CloneBudgetPeriod with param amount_change_*
465
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
466
    {
467
        budget_period_id        => $budget_period_id,
468
        budget_period_startdate => '2014-01-01',
469
        budget_period_enddate   => '2014-12-31',
470
        amount_change_percentage => 16,
471
        amount_change_round_increment => 5,
472
    }
473
);
474
475
$budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned);
476
cmp_ok($budget_period_cloned->{budget_period_total}, '==', 11600, "CloneBudgetPeriod changed correctly budget amount");
477
$budget_hierarchy_cloned     = GetBudgetHierarchy($budget_period_id_cloned);
478
cmp_ok($budget_hierarchy_cloned->[0]->{budget_amount}, '==', 1160, "CloneBudgetPeriod changed correctly funds amounts");
479
cmp_ok($budget_hierarchy_cloned->[1]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
480
cmp_ok($budget_hierarchy_cloned->[2]->{budget_amount}, '==', 55, "CloneBudgetPeriod changed correctly funds amounts");
481
cmp_ok($budget_hierarchy_cloned->[3]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
482
cmp_ok($budget_hierarchy_cloned->[4]->{budget_amount}, '==', 2320, "CloneBudgetPeriod changed correctly funds amounts");
483
cmp_ok($budget_hierarchy_cloned->[5]->{budget_amount}, '==', 0, "CloneBudgetPeriod changed correctly funds amounts");
484
464
# MoveOrders
485
# MoveOrders
465
my $number_orders_moved = C4::Budgets::MoveOrders();
486
my $number_orders_moved = C4::Budgets::MoveOrders();
466
is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
487
is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
467
- 

Return to bug 15004