From e66b81629b4741a4f93d7606bbc0d4d59794e4bb Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 3 Aug 2017 02:05:03 +0000 Subject: [PATCH] [SIGNED-OFF] 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 --- admin/aqbudgetperiods.pl | 15 ++++++++++----- .../prog/en/modules/admin/aqbudgetperiods.tt | 8 ++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 2668b4c..cdd2788 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -128,12 +128,17 @@ 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 ); } @@ -278,8 +283,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; + 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 5150da1..fa4e050 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt @@ -231,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 %]'? @@ -407,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 %] @@ -424,6 +427,7 @@
+ [% END %]
[% END %] -- 2.1.4