- $data->{'budget_period_startdate'} = $startdate;
- $data->{'budget_period_enddate'} = $enddate;
- delete $data->{'budget_period_id'};
- my $new_budget_period_id = C4::SQLHelper::InsertInTable('aqbudgetperiods', $data);
-
- my $tree = GetBudgetHierarchy( $budget_period_id );
-
- # hash mapping old ids to new
- my %old_new;
- # hash mapping old parent ids to list of new children ids
- # only store a child here if the parents old id isnt in the old_new map
- # when the parent is found, this map will be used, and then the entry removed and their id placed in old_new
- my %parent_children;
-
- for my $entry( @$tree ){
- die "serious errors, parent period $budget_period_id doesnt match child ", $entry->{'budget_period_id'}, "\n" if( $entry->{'budget_period_id'} != $budget_period_id );
- my $orphan = 0; # set to 1 if we need to make an entry in parent_children
- my $old_id = delete $entry->{'budget_id'};
- my $parent_id = delete $entry->{'budget_parent_id'};
- $entry->{'budget_period_id'} = $new_budget_period_id;
-
- if( !defined $parent_id ){
- } elsif( defined $parent_id && $parent_id eq '' ){
- } elsif( defined $old_new{$parent_id} ){
- # set parent id now
- $entry->{'budget_parent_id'} = $old_new{$parent_id};
- } else {
- # make an entry in parent_children
- $parent_children{$parent_id} = [] unless defined $parent_children{$parent_id};
- $orphan = 1;
+ my $budget_period_startdate = dt_from_string scalar $input->param('budget_period_startdate');
+ my $budget_period_enddate = dt_from_string scalar $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');
+
+ my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
+ {
+ budget_period_id => $budget_period_id,
+ 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,