Bug 12164: On cloning budget periods, add a "reset all funds" option
This patch adds a checkbox "reset all funds" (budgets). If it is checked, the new created budgets (funds) will be reset. Signed-off-by: Paola Rossi <paola.rossi@cineca.it> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
cd191642cd
commit
c4d9b3dd52
4 changed files with 51 additions and 4 deletions
|
@ -1013,15 +1013,19 @@ sub ConvertCurrency {
|
||||||
|
|
||||||
my $new_budget_period_id = CloneBudgetPeriod({
|
my $new_budget_period_id = CloneBudgetPeriod({
|
||||||
budget_period_id => $budget_period_id,
|
budget_period_id => $budget_period_id,
|
||||||
budget_period_startdate => $budget_period_startdate;
|
budget_period_startdate => $budget_period_startdate,
|
||||||
budget_period_enddate => $budget_period_enddate;
|
budget_period_enddate => $budget_period_enddate,
|
||||||
mark_original_budget_as_inactive => 1
|
mark_original_budget_as_inactive => 1n
|
||||||
|
reset_all_budgets => 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
Clone a budget period with all budgets.
|
Clone a budget period with all budgets.
|
||||||
If the mark_origin_budget_as_inactive is set (0 by default),
|
If the mark_origin_budget_as_inactive is set (0 by default),
|
||||||
the original budget will be marked as inactive.
|
the original budget will be marked as inactive.
|
||||||
|
|
||||||
|
If the reset_all_budgets is set (0 by default), all budget (fund)
|
||||||
|
amounts will be reset.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub CloneBudgetPeriod {
|
sub CloneBudgetPeriod {
|
||||||
|
@ -1031,6 +1035,7 @@ sub CloneBudgetPeriod {
|
||||||
my $budget_period_enddate = $params->{budget_period_enddate};
|
my $budget_period_enddate = $params->{budget_period_enddate};
|
||||||
my $mark_original_budget_as_inactive =
|
my $mark_original_budget_as_inactive =
|
||||||
$params->{mark_original_budget_as_inactive} || 0;
|
$params->{mark_original_budget_as_inactive} || 0;
|
||||||
|
my $reset_all_budgets = $params->{reset_all_budgets} || 0;
|
||||||
|
|
||||||
my $budget_period = GetBudgetPeriod($budget_period_id);
|
my $budget_period = GetBudgetPeriod($budget_period_id);
|
||||||
|
|
||||||
|
@ -1057,6 +1062,14 @@ sub CloneBudgetPeriod {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $reset_all_budgets ) {
|
||||||
|
my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
|
||||||
|
for my $budget ( @$budgets ) {
|
||||||
|
$budget->{budget_amount} = 0;
|
||||||
|
ModBudget( $budget );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $new_budget_period_id;
|
return $new_budget_period_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,7 @@ elsif ( $op eq 'duplicate_budget' ){
|
||||||
my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
|
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_enddate = dt_from_string $input->param('budget_period_enddate');
|
||||||
my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
|
my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
|
||||||
|
my $reset_all_budgets = $input->param('reset_all_budgets');
|
||||||
|
|
||||||
my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
|
my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
|
||||||
{
|
{
|
||||||
|
@ -197,6 +198,7 @@ elsif ( $op eq 'duplicate_budget' ){
|
||||||
budget_period_startdate => $budget_period_startdate,
|
budget_period_startdate => $budget_period_startdate,
|
||||||
budget_period_enddate => $budget_period_enddate,
|
budget_period_enddate => $budget_period_enddate,
|
||||||
mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
|
mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
|
||||||
|
reset_all_budgets => $reset_all_budgets,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,11 @@
|
||||||
<input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
|
<input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<label for="reset_all_budgets">Set all funds to zero</label>
|
||||||
|
<input type="checkbox" id="reset_all_budgets" name="reset_all_budgets" />
|
||||||
|
</li>
|
||||||
|
|
||||||
</ol>
|
</ol>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
use Test::More tests => 69;
|
use Test::More tests => 71;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
use_ok('C4::Budgets')
|
use_ok('C4::Budgets')
|
||||||
|
@ -382,6 +382,14 @@ is( $budget_period->{budget_period_active}, 1,
|
||||||
'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
|
'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
|
||||||
|
my $number_of_budgets_not_reset = 0;
|
||||||
|
for my $budget (@$budget_hierarchy_cloned) {
|
||||||
|
$number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
|
||||||
|
}
|
||||||
|
is( $number_of_budgets_not_reset, 5,
|
||||||
|
'CloneBudgetPeriod does not reset budgets (funds) if not needed' );
|
||||||
|
|
||||||
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
|
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
|
||||||
{
|
{
|
||||||
budget_period_id => $budget_period_id,
|
budget_period_id => $budget_period_id,
|
||||||
|
@ -407,6 +415,25 @@ is( $budget_period->{budget_period_active}, 0,
|
||||||
'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
|
'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# CloneBudgetPeriod with param reset_all_budgets
|
||||||
|
$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',
|
||||||
|
reset_all_budgets => 1,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
|
||||||
|
$number_of_budgets_not_reset = 0;
|
||||||
|
for my $budget (@$budget_hierarchy_cloned) {
|
||||||
|
$number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
|
||||||
|
}
|
||||||
|
is( $number_of_budgets_not_reset, 0,
|
||||||
|
'CloneBudgetPeriod has reset all budgets (funds)' );
|
||||||
|
|
||||||
|
|
||||||
sub _get_dependencies {
|
sub _get_dependencies {
|
||||||
my ($budget_hierarchy) = @_;
|
my ($budget_hierarchy) = @_;
|
||||||
my $graph;
|
my $graph;
|
||||||
|
|
Loading…
Reference in a new issue