@@ -, +, @@ - adds a JS check, template side - adds a check in the perl script (should never be true) - adds an updatedatabase check, in order to alert users with inconsistent data. --- admin/aqbudgets.pl | 6 ++++++ installer/data/mysql/updatedatabase.pl | 22 ++++++++++++++++++++ .../prog/en/modules/admin/aqbudgets.tt | 11 +++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) --- a/admin/aqbudgets.pl +++ a/admin/aqbudgets.pl @@ -231,6 +231,10 @@ if ($op eq 'add_form') { # END $OP eq DELETE_CONFIRM # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ( $op eq 'delete_confirmed' ) { + if ( HasChildren( $budget_id ) ) { + # We should never be here, the interface does not provide this action. + die("Delete a fund with children is not possible"); + } my $rc = DelBudget($budget_id); $op = 'list'; } elsif( $op eq 'add_validate' ) { @@ -330,6 +334,8 @@ if ( $op eq 'list' ) { @budget_hierarchy = reverse(@budget_hierarchy); $budget->{budget_hierarchy} = \@budget_hierarchy; + + $budget->{budget_has_children} = BudgetHasChildren( $budget->{budget_id} ); } my $budget_period_total = $period->{budget_period_total}; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -9437,6 +9437,28 @@ if ( CheckVersion($DBversion) ) { print "Upgrade to $DBversion done (Bug 9043: Add system preference OpacAdvSearchOptions and OpacAdvSearchMoreOptions)\n"; SetVersion ($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + my $orphan_budgets = $dbh->selectall_arrayref(q| + SELECT budget_id, budget_name, budget_code + FROM aqbudgets + WHERE budget_parent_id IS NOT NULL + AND budget_parent_id NOT IN ( + SELECT DISTINCT budget_id FROM aqbudgets + ) + |, { Slice => {} } ); + + if ( @$orphan_budgets ) { + for my $b ( @$orphan_budgets ) { + print "Fund $b->{budget_name} (code:$b->{budget_code}, id:$b->{budget_id}) does not have a parent, it may cause problem\n"; + } + print "Upgrade to $DBversion done (Bug 12905: Check budget integrity: FAIL)\n"; + } else { + print "Upgrade to $DBversion done (Bug 12905: Check budget integrity: OK)\n"; + } + SetVersion($DBversion); +} + =head1 FUNCTIONS --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -218,6 +218,11 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") $("#filterbutton").click(function() { $("#fundfilters").slideToggle(0); }); + + $(".deletefund-disabled").on("click", function(e){ + e.preventDefault(); + alert("This fund has children. It cannot be deleted."); + }); }); //]]> @@ -391,7 +396,11 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") --