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 76f07014c6..3323b17ec1 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 %]