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.
Signed-off-by: Frederic Demians <f.demians@tamil.fr>
It works as announced.
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
2a838cabce
commit
5e2cc5c958
|
|
@ -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 ) = @_;
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -474,6 +474,15 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
|
|||
onclick="ownerRemove(); return false;" />
|
||||
</li>
|
||||
|
||||
[% IF budget_has_children %]
|
||||
<li>
|
||||
<span class="label">
|
||||
<label for="set_owner_to_children">Set this owner to all children funds:</label>
|
||||
</span>
|
||||
<input type="checkbox" id="set_owner_to_children" name="set_owner_to_children" value="1" />
|
||||
</li>
|
||||
[% END %]
|
||||
|
||||
<li>
|
||||
<span class="label">Users:</span>
|
||||
<ul style="float:left;" id="budget_users">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use Modern::Perl;
|
||||
use Test::More tests => 108;
|
||||
use Test::More tests => 120;
|
||||
|
||||
BEGIN {
|
||||
use_ok('C4::Budgets')
|
||||
|
|
@ -9,6 +9,7 @@ use C4::Biblio;
|
|||
use C4::Bookseller;
|
||||
use C4::Acquisition;
|
||||
use C4::Dates;
|
||||
use C4::Members qw( AddMember );
|
||||
|
||||
use Koha::Acquisition::Order;
|
||||
|
||||
|
|
@ -97,6 +98,14 @@ is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget p
|
|||
# Budget :
|
||||
#
|
||||
|
||||
# The budget hierarchy will be:
|
||||
# budget_1
|
||||
# budget_11
|
||||
# budget_111
|
||||
# budget_12
|
||||
# budget_2
|
||||
# budget_21
|
||||
|
||||
is( AddBudget(), undef, 'AddBuget without argument returns undef' );
|
||||
my $budgets = GetBudgets();
|
||||
is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' );
|
||||
|
|
@ -516,6 +525,60 @@ for my $new_budget ( @new_budgets ) {
|
|||
is( $new_budget->{budget_amount} + 0, $new_budget_amount_should_be, "MoveOrders updated the budget amount with the previous unspent budget (for budget $new_budget->{budget_code})" );
|
||||
}
|
||||
|
||||
# Test SetOwnerToFundHierarchy
|
||||
|
||||
my $categorycode = 'S';
|
||||
my $branchcode = 'CPL';
|
||||
my $john_doe = C4::Members::AddMember(
|
||||
cardnumber => '123456',
|
||||
firstname => 'John',
|
||||
surname => 'Doe',
|
||||
categorycode => $categorycode,
|
||||
branchcode => $branchcode,
|
||||
dateofbirth => '',
|
||||
dateexpiry => '9999-12-31',
|
||||
userid => 'john.doe'
|
||||
);
|
||||
|
||||
C4::Budgets::SetOwnerToFundHierarchy( $budget_id1, $john_doe );
|
||||
is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
|
||||
$john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 1 ($budget_id1)" );
|
||||
is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
|
||||
$john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 11 ($budget_id11)" );
|
||||
is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
|
||||
$john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 111 ($budget_id111)" );
|
||||
is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
|
||||
$john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 12 ($budget_id12 )" );
|
||||
is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
|
||||
undef, "SetOwnerToFundHierarchy should not have set an owner for budget 2 ($budget_id2)" );
|
||||
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
|
||||
undef, "SetOwnerToFundHierarchy should not have set an owner for budget 21 ($budget_id21)" );
|
||||
|
||||
my $jane_doe = C4::Members::AddMember(
|
||||
cardnumber => '789012',
|
||||
firstname => 'Jane',
|
||||
surname => 'Doe',
|
||||
categorycode => $categorycode,
|
||||
branchcode => $branchcode,
|
||||
dateofbirth => '',
|
||||
dateexpiry => '9999-12-31',
|
||||
userid => 'jane.doe'
|
||||
);
|
||||
|
||||
C4::Budgets::SetOwnerToFundHierarchy( $budget_id11, $jane_doe );
|
||||
is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
|
||||
$john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 1 ($budget_id1)" );
|
||||
is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
|
||||
$jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 11 ($budget_id11)" );
|
||||
is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
|
||||
$jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 111 ($budget_id111)" );
|
||||
is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
|
||||
$john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 12 ($budget_id12 )" );
|
||||
is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
|
||||
undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 2 ($budget_id2)" );
|
||||
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
|
||||
undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
|
||||
|
||||
sub _get_dependencies {
|
||||
my ($budget_hierarchy) = @_;
|
||||
my $graph;
|
||||
|
|
|
|||
Loading…
Reference in New Issue