Bug 15004: Allow to change amounts of duplicated budgets
When duplicating a budget we now have the possibility to change amounts of budget and funds by a given percentage. Additionally, we can configure how to round the amounts. Test plan: 1. Create a budget and several funds with different amounts 2. Duplicate it using the 2 new options 3. Check that the amounts are correct Signed-off-by: Frederic Demians <f.demians@tamil.fr> It works exactly as advertised. Was happy to see that decimal point can be used: for example, increase a budget by 2.6%, and round the amound to 0.5. Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
parent
3ea6e78909
commit
9c81343bf6
4 changed files with 66 additions and 1 deletions
|
@ -985,6 +985,15 @@ sub ConvertCurrency {
|
|||
return ( $price / $cur );
|
||||
}
|
||||
|
||||
sub _round {
|
||||
my ($value, $increment) = @_;
|
||||
|
||||
if ($increment && $increment != 0) {
|
||||
$value = int($value / $increment) * $increment;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
=head2 CloneBudgetPeriod
|
||||
|
||||
|
@ -1011,6 +1020,8 @@ sub CloneBudgetPeriod {
|
|||
my $budget_period_startdate = $params->{budget_period_startdate};
|
||||
my $budget_period_enddate = $params->{budget_period_enddate};
|
||||
my $budget_period_description = $params->{budget_period_description};
|
||||
my $amount_change_percentage = $params->{amount_change_percentage};
|
||||
my $amount_change_round_increment = $params->{amount_change_round_increment};
|
||||
my $mark_original_budget_as_inactive =
|
||||
$params->{mark_original_budget_as_inactive} || 0;
|
||||
my $reset_all_budgets = $params->{reset_all_budgets} || 0;
|
||||
|
@ -1022,6 +1033,14 @@ sub CloneBudgetPeriod {
|
|||
$budget_period->{budget_period_description} = $budget_period_description;
|
||||
# The new budget (budget_period) should be active by default
|
||||
$budget_period->{budget_period_active} = 1;
|
||||
|
||||
if ($amount_change_percentage) {
|
||||
my $total = $budget_period->{budget_period_total};
|
||||
$total += $total * $amount_change_percentage / 100;
|
||||
$total = _round($total, $amount_change_round_increment);
|
||||
$budget_period->{budget_period_total} = $total;
|
||||
}
|
||||
|
||||
my $original_budget_period_id = $budget_period->{budget_period_id};
|
||||
delete $budget_period->{budget_period_id};
|
||||
my $new_budget_period_id = AddBudgetPeriod( $budget_period );
|
||||
|
@ -1049,6 +1068,15 @@ sub CloneBudgetPeriod {
|
|||
$budget->{budget_amount} = 0;
|
||||
ModBudget( $budget );
|
||||
}
|
||||
} elsif ($amount_change_percentage) {
|
||||
my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
|
||||
for my $budget ( @$budgets ) {
|
||||
my $amount = $budget->{budget_amount};
|
||||
$amount += $amount * $amount_change_percentage / 100;
|
||||
$amount = _round($amount, $amount_change_round_increment);
|
||||
$budget->{budget_amount} = $amount;
|
||||
ModBudget( $budget );
|
||||
}
|
||||
}
|
||||
|
||||
return $new_budget_period_id;
|
||||
|
|
|
@ -163,6 +163,8 @@ elsif ( $op eq 'duplicate_budget' ){
|
|||
my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
|
||||
my $budget_period_enddate = dt_from_string $input->param('budget_period_enddate');
|
||||
my $budget_period_description = $input->param('budget_period_description');
|
||||
my $amount_change_percentage = $input->param('amount_change_percentage');
|
||||
my $amount_change_round_increment = $input->param('amount_change_round_increment');
|
||||
my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
|
||||
my $reset_all_budgets = $input->param('reset_all_budgets');
|
||||
|
||||
|
@ -172,6 +174,8 @@ elsif ( $op eq 'duplicate_budget' ){
|
|||
budget_period_startdate => $budget_period_startdate,
|
||||
budget_period_enddate => $budget_period_enddate,
|
||||
budget_period_description => $budget_period_description,
|
||||
amount_change_percentage => $amount_change_percentage,
|
||||
amount_change_round_increment => $amount_change_round_increment,
|
||||
mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
|
||||
reset_all_budgets => $reset_all_budgets,
|
||||
}
|
||||
|
|
|
@ -284,6 +284,18 @@
|
|||
<input type="text" id="budget_period_description" name="budget_period_description" value="[% budgetperiod.budget_period_description %]" />
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label for="amount_change_percentage">Change amounts by</label>
|
||||
<input type="text" id="amount_change_percentage" name="amount_change_percentage" /> %
|
||||
<div class="hint">(can be positive or negative)</div>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label for="amount_change_round_increment">If amounts changed, round to a multiple of</label>
|
||||
<input type="text" id="amount_change_round_increment" name="amount_change_round_increment" />
|
||||
<div class="hint">(amounts will be rounded down)</div>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label for="mark_as_inactive">Mark the original budget as inactive</label>
|
||||
<input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use Modern::Perl;
|
||||
use Test::More tests => 122;
|
||||
use Test::More tests => 129;
|
||||
|
||||
BEGIN {
|
||||
use_ok('C4::Budgets')
|
||||
|
@ -469,6 +469,27 @@ is( $number_of_budgets_not_reset, 0,
|
|||
'CloneBudgetPeriod has reset all budgets (funds)' );
|
||||
|
||||
|
||||
# CloneBudgetPeriod with param amount_change_*
|
||||
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
|
||||
{
|
||||
budget_period_id => $budget_period_id,
|
||||
budget_period_startdate => '2014-01-01',
|
||||
budget_period_enddate => '2014-12-31',
|
||||
amount_change_percentage => 16,
|
||||
amount_change_round_increment => 5,
|
||||
}
|
||||
);
|
||||
|
||||
$budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned);
|
||||
cmp_ok($budget_period_cloned->{budget_period_total}, '==', 11600, "CloneBudgetPeriod changed correctly budget amount");
|
||||
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
|
||||
cmp_ok($budget_hierarchy_cloned->[0]->{budget_amount}, '==', 1160, "CloneBudgetPeriod changed correctly funds amounts");
|
||||
cmp_ok($budget_hierarchy_cloned->[1]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
|
||||
cmp_ok($budget_hierarchy_cloned->[2]->{budget_amount}, '==', 55, "CloneBudgetPeriod changed correctly funds amounts");
|
||||
cmp_ok($budget_hierarchy_cloned->[3]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
|
||||
cmp_ok($budget_hierarchy_cloned->[4]->{budget_amount}, '==', 2320, "CloneBudgetPeriod changed correctly funds amounts");
|
||||
cmp_ok($budget_hierarchy_cloned->[5]->{budget_amount}, '==', 0, "CloneBudgetPeriod changed correctly funds amounts");
|
||||
|
||||
# MoveOrders
|
||||
my $number_orders_moved = C4::Budgets::MoveOrders();
|
||||
is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
|
||||
|
|
Loading…
Reference in a new issue