diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 1a7f7e4689..0cd7c93357 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -187,6 +187,27 @@ sub BudgetHasChildren { return $sum->{'sum'}; } +sub GetBudgetChildren { + my ( $budget_id ) = @_; + my $dbh = C4::Context->dbh; + return $dbh->selectall_arrayref(q| + SELECT * FROM aqbudgets + WHERE budget_parent_id = ? + |, { Slice => {} }, $budget_id ); +} + +sub SetOwnerToFundHierarchy { + my ( $budget_id, $borrowernumber ) = @_; + + my $budget = GetBudget( $budget_id ); + $budget->{budget_owner_id} = $borrowernumber; + ModBudget( $budget ); + my $children = GetBudgetChildren( $budget_id ); + for my $child ( @$children ) { + SetOwnerToFundHierarchy( $child->{budget_id}, $borrowernumber ); + } +} + # ------------------------------------------------------------------- sub GetBudgetsPlanCell { my ( $cell, $period, $budget ) = @_; diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 287cf139c7..60463870f7 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -210,6 +210,7 @@ if ($op eq 'add_form') { # if no buget_id is passed then its an add $template->param( + budget_has_children => BudgetHasChildren( $budget->{budget_id} ), budget_parent_id => $budget_parent->{'budget_id'}, budget_parent_name => $budget_parent->{'budget_name'}, branchloop_select => \@branchloop_select, @@ -240,12 +241,14 @@ if ($op eq 'add_form') { @budgetusersid = split(':', $budget_users_ids); } + my $budget_modified = 0; if (defined $budget_id) { if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id}, $staffflags) ) { ModBudget( $budget_hash ); ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid); + $budget_modified = 1; } else { $template->param(error_not_authorised_to_modify => 1); @@ -253,6 +256,12 @@ if ($op eq 'add_form') { } else { $budget_hash->{budget_id} = AddBudget( $budget_hash ); ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid); + $budget_modified = 1; + } + + my $set_owner_to_children = $input->param('set_owner_to_children'); + if ( $set_owner_to_children and $budget_modified ) { + C4::Budgets::SetOwnerToFundHierarchy( $budget_hash->{budget_id}, $budget_hash->{budget_owner_id} ); } $op = 'list'; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index bec6272ffd..0f1d4b27f0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -474,6 +474,15 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") onclick="ownerRemove(); return false;" /> + [% IF budget_has_children %] +
  • + + + + +
  • + [% END %] +
  • Users: