From 0363a97768a5ff3c54a5824f018cb827a2192869 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 30 Mar 2017 04:15:54 +0000 Subject: [PATCH] Bug 18351: Able to delete budget with funds MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To test: 1) Create a budget, add a fund 2) Delete budget. Notice this is successful and triggers no warning message etc. 3) Go to Funds. Notice the funds appear as if they are not there 4) Go into mysql and view the aqbudgetperiods table - notice the funds are still there and are now inaccessible. 5) Apply patch 6) Create a budget, add a fund 7) Attempt to delete budget. Notice you can't click Delete button. Confirm number of funds in hover message is correct. 8) Delete fund 9) Confirm you can now delete budget. Sponsored-by: Catalyst IT Signed-off-by: Felix Hemme Signed-off-by: Owen Leonard Bug 18351: [FOLLOW-UP] Some code fixes See Comment 5. Ready to test. Signed-off-by: Lee Jamison Signed-off-by: Owen Leonard Bug 18351: [FOLLOW-UP] Code fix See comment 10. Ready for testing. Signed-off-by: Owen Leonard Bug 18351: [FOLLOW-UP] Prevent deletion from forcing URL This patch adds a check in the script for existing funds so that the budget cannot be deleted when forcing the URL and has other small fixes. Signed-off-by: Owen Leonard Bug 18351: [FOLLOW-UP] Prevent deletion if funds are added after clicking 'Delete' and before confirming delete Followed test plan and patch works as described. Signed-off-by: Dilan Johnpullé Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart (cherry picked from commit 0ed469525fe16e36663c1f5266568beb5e27672d) Signed-off-by: Fridolin Somers (cherry picked from commit 2a9dc2e595d916e4fb94948871f665df06b7088b) Signed-off-by: Katrin Fischer --- admin/aqbudgetperiods.pl | 30 ++++++++++---- .../prog/en/modules/admin/aqbudgetperiods.tt | 40 +++++++++++++------ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index ca2171f145..fbe193843b 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -127,21 +127,31 @@ elsif ( $op eq 'add_validate' ) { #-------------------------------------------------- elsif ( $op eq 'delete_confirm' ) { ## delete a budget period (preparation) - my $dbh = C4::Context->dbh; - ## $total = number of records linked to the record that must be deleted + my $funds = GetBudgets({ budget_period_id => $budget_period_id }); + my $fund_count = scalar @$funds; + if ( $fund_count > 0 ) { + $template->param( funds_exist => 1 ); + } + + #$total = number of records linked to the record that must be deleted my $total = 0; my $data = GetBudgetPeriod( $budget_period_id); - $template->param( - %$data + %$data ); } elsif ( $op eq 'delete_confirmed' ) { -## delete the budget period record - - my $data = GetBudgetPeriod( $budget_period_id); - DelBudgetPeriod($budget_period_id); + ## confirm no funds have been added to budget + my $funds = GetBudgets({ budget_period_id => $budget_period_id }); + my $fund_count = scalar @$funds; + if ( $fund_count > 0 ) { + $template->param( failed_delete_funds_exist => 1 ); + } else { + ## delete the budget period record + my $data = GetBudgetPeriod( $budget_period_id); + DelBudgetPeriod($budget_period_id); + } $op='else'; } @@ -263,6 +273,8 @@ my @period_active_loop; foreach my $result ( @{$results} ) { my $budgetperiod = $result; $budgetperiod->{budget_active} = 1; + my $funds = GetBudgets({ budget_period_id => $budgetperiod->{budget_period_id} }); + $budgetperiod->{count} = scalar @$funds; push( @period_active_loop, $budgetperiod ); } @@ -276,6 +288,8 @@ my @period_inactive_loop; foreach my $result ( @{$results} ) { my $budgetperiod = $result; $budgetperiod->{budget_active} = 1; + my $funds = GetBudgets({ budget_period_id => $budgetperiod->{budget_period_id} }); + $budgetperiod->{count} = scalar @$funds; push( @period_inactive_loop, $budgetperiod ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt index ecedbea395..91f6a7a38b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt @@ -3,24 +3,30 @@ [%- BLOCK action_menu %] @@ -225,7 +231,7 @@ [% END %] [% IF ( delete_confirm ) %] Budgets › - [% IF ( total ) %] + [% IF ( total || funds_exist ) %] Cannot delete budget '[% budget_period_description %]' [% ELSE %] Delete budget '[% budget_period_description %]'? @@ -401,10 +407,13 @@

Cannot delete budget

This record is used [% total %] times . Deletion is not possible.

+ [% ELSIF ( funds_exist ) %] +
+

Cannot delete budget

+

This budget has funds attached. You must delete all attached funds before you can delete this budget.

[% ELSE %]

Delete budget '[% budget_period_description %]'?

- [% END %] @@ -418,6 +427,7 @@
+ [% END %]
[% END %] @@ -532,6 +542,10 @@ [% IF ( else ) %]

Budgets administration

+ [% IF ( failed_delete_funds_exist ) %] +
Failed to delete budget because funds exist.
+ [% END %] + [% INCLUDE 'budgets-active-currency.inc' %]
@@ -566,7 +580,7 @@ [% period_active.budget_period_total | $Price %] - [% PROCESS action_menu block_budget_id=period_active.budget_period_id %] + [% PROCESS action_menu block_budget=period_active %] [% END %] @@ -598,7 +612,7 @@ [% IF ( period_loo.budget_period_locked ) %]Locked [% ELSE %][% END %] [% period_loo.budget_period_total | $Price %] - [% PROCESS action_menu block_budget_id=period_loo.budget_period_id %] + [% PROCESS action_menu block_budget=period_loo %] [% END %] -- 2.39.5