From 8dca36661d7cca5a60aaacc44d2e6a774f78da7a Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 24 Sep 2020 14:21:43 +0200 Subject: [PATCH] Bug 11176: Add active switch on budgets select in suggestions When creating a new purchase suggestion, all funds display and are available for selection. The behaviour of this drop-down menu should mirror that of those drop-down menus elsewhere in acquisitions, where only funds that are linked to active budgets display to the user. This patch add the active switch based on what exists in acqui/invoice.tt and acqui/invoice.pl. Looks like actually in suggestion.pl budgets list was fetches with GetBudgets(). But this is for the filter in 'Acquisition information'. Budgets selection on suggestion creation/edition must use GetBudgetHierarchy(), like in acqui/invoice.pl, in order to have the actif status. Test plan : 1) Create a budget periods active B1 with a fund F1 2) Create a budget periods inactive B2 with a fund F2 3) Go to suggestions module 4) Create a new suggestion 5) Check you see only active fund F1 6) Click on 'Show inactive' 7) Check you see also 'F2 (inactive)' 8) Choose fund F1 and save 9) Select the suggestion and edit 10) Check fund F1 is selected 11) Come back to suggestion table 12) Check filter 'Book fund' under 'Acquisition information' contains all funds Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../prog/en/modules/suggestion/suggestion.tt | 31 +++++++++++++++++-- suggestion/suggestion.pl | 21 +++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index 4e801db741..8930674422 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -447,10 +447,21 @@
  • -
  • + + +
  • +
  • @@ -1186,6 +1197,20 @@ $('#notify').prop('checked', false).prop('disabled', true); }); + //keep a copy of all budgets before removing the inactives + var budgetId = $("form#add_edit #budgetid"); + var disabledBudgetsCopy = budgetId.html(); + $('.b_inactive').remove(); + + $('#showallfunds').click(function() { + if ($(this).is(":checked")) { + budgetId.html(disabledBudgetsCopy); //Puts back all the funds + } + else { + $('.b_inactive').remove(); + } + }); + }); [% END %] diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index bd4c1a0696..ce8a9dee90 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -407,7 +407,7 @@ $template->param( returnsuggestedby => $returnsuggestedby ); my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG"); $template->param(patron_reason_loop=>$patron_reason_loop); -#Budgets management +# Budgets for filtering my $budgets = GetBudgets; my @budgets_loop; foreach my $budget ( @{$budgets} ) { @@ -420,8 +420,25 @@ foreach my $budget ( @{$budgets} ) { push @budgets_loop, $budget; } - $template->param( budgetsloop => \@budgets_loop); + +# Budgets for suggestion add or edition +my $sugg_budget_loop = []; +my $sugg_budgets = GetBudgetHierarchy(); +foreach my $r ( @{$sugg_budgets} ) { + next unless ( CanUserUseBudget( $borrowernumber, $r, $userflags ) ); + my $selected = ( $$suggestion_ref{budgetid} && $r->{budget_id} eq $$suggestion_ref{budgetid} ) ? 1 : 0; + push @{$sugg_budget_loop}, + { + b_id => $r->{budget_id}, + b_txt => $r->{budget_name}, + b_active => $r->{budget_period_active}, + selected => $selected, + }; +} +@{$sugg_budget_loop} = sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @{$sugg_budget_loop}; +$template->param( sugg_budgets => $sugg_budget_loop); + if( $suggestion_ref->{STATUS} ) { $template->param( "statusselected_".$suggestion_ref->{STATUS} => 1, -- 2.39.5