From cd4b824af8190bcd2ab59366b9ed120853844105 Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Tue, 30 Jul 2024 15:58:19 +0000 Subject: [PATCH] Bug 37096: Display error message for budget creation/modification if start/end date is left blank This patch adds an error message for a failed budget creation or modifcation due to the dates being empty. To test: 1) Go to the acquisitions tab, then on the side under 'Administration' select the 'Budgets' tab. 2) Click 'New budget', enter only a description and press save. 3) Note that the budget was not created, but no messages were displayed. 4) Apply patch, restart_all 5) Once again select 'New budget' and enter only a description. 6) This time when submitting, you will see an error message that says the process failed. 7) Edit an exisitng budget and remove the start date from this budget. 8) Attempt to save and note that the error message displays properly. --- admin/aqbudgetperiods.pl | 73 ++++++++++++------- .../prog/en/modules/admin/aqbudgetperiods.tt | 4 + 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index c66969a21c..8b6d4a0c7e 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -110,38 +110,57 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'cud-add_validate' ) { +EXIT_IF: { ## add or modify a budget period (confirmation) - ## update budget period data - if ( $budget_period_id ne '' ) { - # Grab the previous values so we can log them - my $budgetperiod_old=GetBudgetPeriod($budget_period_id); - $$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked); - my $status=ModBudgetPeriod($budget_period_hashref); - # Log the budget modification - if (C4::Context->preference("AcquisitionLog")) { - my $diff = 0 - ($budgetperiod_old->{budget_period_total} - $budget_period_hashref->{budget_period_total}); - my $infos = { - budget_period_startdate => $input->param('budget_period_startdate'), - budget_period_enddate => $input->param('budget_period_enddate'), - budget_period_total => $budget_period_hashref->{budget_period_total}, - budget_period_startdate_old => $budgetperiod_old->{budget_period_startdate}, - budget_period_enddate_old => $budgetperiod_old->{budget_period_enddate}, - budget_period_total_old => $budgetperiod_old->{budget_period_total}, - budget_period_total_change => $diff - }; - logaction( - 'ACQUISITIONS', - 'MODIFY_BUDGET', - $budget_period_id, - encode_json($infos) + my $budget_period_startdate = $input->param('budget_period_startdate'); + my $budget_period_enddate = $input->param('budget_period_enddate'); + my $action = $budget_period_id ne '' ? 'modify' : 'add'; + + if ( $budget_period_startdate eq '' || $budget_period_enddate eq '' ) { + + $template->param( + failed_add_validate => 1, + action => $action ); + + $op = 'else'; + last EXIT_IF; } + + ## update budget period data + if ( $action eq 'modify' ) { + + # Grab the previous values so we can log them + my $budgetperiod_old = GetBudgetPeriod($budget_period_id); + $$budget_period_hashref{$_} ||= 0 for qw(budget_period_active budget_period_locked); + my $status = ModBudgetPeriod($budget_period_hashref); + + # Log the budget modification + if ( C4::Context->preference("AcquisitionLog") ) { + my $diff = + 0 - ( $budgetperiod_old->{budget_period_total} - $budget_period_hashref->{budget_period_total} ); + my $infos = { + budget_period_startdate => $budget_period_startdate, + budget_period_enddate => $budget_period_enddate, + budget_period_total => $budget_period_hashref->{budget_period_total}, + budget_period_startdate_old => $budgetperiod_old->{budget_period_startdate}, + budget_period_enddate_old => $budgetperiod_old->{budget_period_enddate}, + budget_period_total_old => $budgetperiod_old->{budget_period_total}, + budget_period_total_change => $diff + }; + logaction( + 'ACQUISITIONS', + 'MODIFY_BUDGET', + $budget_period_id, + encode_json($infos) + ); + } + } else { # ELSE ITS AN ADD + my $budget_period_id = AddBudgetPeriod($budget_period_hashref); + } + $op = 'else'; } - else { # ELSE ITS AN ADD - my $budget_period_id=AddBudgetPeriod($budget_period_hashref); - } - $op='else'; } #-------------------------------------------------- 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 9ed1b2a704..c7ad11c718 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt @@ -456,6 +456,10 @@ [% IF ( else ) %]

Budgets

+ [% IF failed_add_validate %] +
Failed to [% action | html %] budget because start/end date was not provided.
+ [% END %] + [% IF ( failed_delete_funds_exist ) %]
Failed to delete budget because funds exist.
[% END %] -- 2.39.2