From a3d0640f28f4aceacddcf4d428e4bbe988ae44e0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 18 Sep 2014 12:13:08 +0200 Subject: [PATCH] Bug 12958: Set a fund owner to a fund hierarchy This patch adds the ability to set an owner to a fund hierarchy On editing a fund, if it has children, a new checkbox appears "Set this owner to all children funds". If checked, all the fund hierarchy will herit to this owner. This will facilitate the fund owner modifications. Test plan: - Verify that the new checkbox only appears if the fund has at least a child. - Create a consistent fund hierarchy, something like: fund1 fund11 fund111 fund12 fund2 fund21 - Try to modify a fund owner without checking the checkbox. Verify the children have not been modified. - Try to modify a fund owner with checking the checkbox. Verify all fund hierarchy has been modified. --- C4/Budgets.pm | 21 +++++++ admin/aqbudgets.pl | 9 +++ .../prog/en/modules/admin/aqbudgets.tt | 9 +++ t/db_dependent/Budgets.t | 65 +++++++++++++++++++++- 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 1a7f7e4..0cd7c93 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 d312ae8..2217633 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -211,6 +211,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, @@ -241,12 +242,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); @@ -254,6 +257,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 b0c4344..d6d23bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -473,6 +473,15 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") onclick="ownerRemove(); return false;" /> + [% IF budget_has_children %] +
  • + + + + +
  • + [% END %] +
  • Users: