From 63a56840208480efbd9615f81efdc8b8e9925904 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 12 Oct 2022 14:55:55 +0000 Subject: [PATCH] Bug 31459: (follow-up) Preserve budget period display This patch adds a level to the budget_loops and displays the budgets as optgroups for the funds Signed-off-by: Katrin Fischer https://bugs.koha-community.org/show_bug.cgi?id=31559 Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 2a22c13cf38b45c145fc3ece7d044fefb1dd78e5) Signed-off-by: Lucas Gass --- acqui/orderreceive.pl | 29 +++++----- .../prog/en/modules/acqui/orderreceive.tt | 54 +++++++++++-------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 72aa4d7564..ab9e4ce967 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -170,21 +170,26 @@ if ( $suggestion ) { } my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; -my $budget_loop = []; +my %budget_loops; my $budgets = GetBudgetHierarchy( undef, undef, undef, 1 ); -foreach my $r (@{$budgets}) { - next unless (CanUserUseBudget($patron, $r, $userflags)); - push @{$budget_loop}, { - b_id => $r->{budget_id}, - b_txt => $r->{budget_name}, - b_sort1_authcat => $r->{'sort1_authcat'}, - b_sort2_authcat => $r->{'sort2_authcat'}, - b_active => $r->{budget_period_active}, - b_sel => ( $r->{budget_id} == $order->budget_id ) ? 1 : 0, - b_level => $r->{budget_level}, +foreach my $budget (@{$budgets}) { + next unless (CanUserUseBudget($patron, $budget, $userflags)); + unless ( defined $budget_loops{$budget->{budget_period_id}} ){ + $budget_loops{$budget->{budget_period_id}}->{description} = $budget->{budget_period_description}; + $budget_loops{$budget->{budget_period_id}}->{active} = $budget->{budget_period_active}; + $budget_loops{$budget->{budget_period_id}}->{funds} = []; + } + push @{$budget_loops{$budget->{budget_period_id}}->{funds}}, { + b_id => $budget->{budget_id}, + b_txt => $budget->{budget_name}, + b_sort1_authcat => $budget->{'sort1_authcat'}, + b_sort2_authcat => $budget->{'sort2_authcat'}, + b_active => $budget->{budget_period_active}, + b_sel => ( $budget->{budget_id} == $order->budget_id ) ? 1 : 0, + b_level => $budget->{budget_level}, }; } -$template->{'VARS'}->{'budget_loop'} = $budget_loop; +$template->{'VARS'}->{'budget_loops'} = \%budget_loops; my $op = $input->param('op'); if ($op and $op eq 'edit'){ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index db2d082694..df2b16c8f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -284,33 +284,41 @@ [% active_count = 0 %] [% IF !ordernumber %] - [% FOREACH budget_loo IN budget_loop %] - [% active_count= active_count + budget_loo.b_active %] + [% FOREACH budget_period IN budget_loops.keys %] + [% FOREACH fund IN budget_loops.$budget_period.funds %] + [% active_count= active_count + fund.b_active %] + [% END %] [% END %] [% END %] Required @@ -548,14 +556,14 @@ //keep a copy of all budgets before removing the inactives disabledBudgetsCopy = $('#bookfund').html(); - $('#bookfund .b_inactive').remove(); + $('#bookfund .inactive_budget').remove(); $('#showallbudgets').click(function() { if ($(this).is(":checked")) { $('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds } else { - $('#bookfund .b_inactive').remove(); + $('#bookfund .inactive_budget').remove(); } }); -- 2.39.5