From edea573bf5a1f07cace029bcb7edee7f2ca99fed Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 11 Oct 2012 14:14:20 +0200 Subject: [PATCH] [PASSED QA] Bug 7308: rework aqbudgets.pl table admin/aqbudgets.pl should have the following columns: Base-level allocated (or just Allocated) Base-level ordered Total sub-levels ordered Base-level spent Total sub-levels spent Base-level available Total sub-levels available Base-level is always calculated for one level, without children. Total sub-levels should include child funds. Available is calculated as "allocated - (ordered + spent)". Signed-off-by: Cedric Vita Signed-off-by: Katrin Fischer Seems to work alright for me. Passes QA script and tests, after I fixed 2 tabs in admin/aqbudgets.pl. Signed-off-by: Katrin Fischer --- C4/Budgets.pm | 11 ++--- admin/aqbudgets.pl | 52 +++++++++----------- .../prog/en/modules/admin/aqbudgets.tt | 46 ++++++++++------- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 999ba70..80164c0 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -612,16 +612,13 @@ sub GetBudgetHierarchy { $r->{'budget_spent'} = GetBudgetSpent( $r->{'budget_id'} ); $r->{budget_ordered} = GetBudgetOrdered( $r->{budget_id} ); - $r->{'budget_amount_total'} = $r->{'budget_amount'}; - + $r->{budget_spent_sublevels} = 0; + $r->{budget_ordered_sublevels} = 0; # foreach sub-levels - my $unalloc_count ; - foreach my $sub (@subs_arr) { my $sub_budget = GetBudget($sub); - - $r->{budget_spent_sublevel} += GetBudgetSpent( $sub_budget->{'budget_id'} ); - $unalloc_count += $sub_budget->{'budget_amount'}; + $r->{budget_spent_sublevels} += GetBudgetSpent( $sub_budget->{'budget_id'} ); + $r->{budget_ordered_sublevels} += GetBudgetOrdered($sub); } } return \@sort; diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index bd28dc4..1a8f4bd 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -276,14 +276,14 @@ if ($op eq 'add_form') { my $toggle = 0; my @loop; my $period_total = 0; - my ( $period_alloc_total, $base_spent_total, $base_ordered_total ); + my ($period_alloc_total, $spent_total, $ordered_total, $available_total) = (0,0,0,0); #This Looks WEIRD to me : should budgets be filtered in such a way ppl who donot own it would not see the amount spent on the budget by others ? foreach my $budget (@budgets) { - #Level and sublevels total spent - $budget->{'total_levels_spent'} = GetChildBudgetsSpent($budget->{"budget_id"}); - + #Level and sublevels total spent and ordered + $budget->{total_spent} = $budget->{budget_spent_sublevels} + $budget->{budget_spent}; + $budget->{total_ordered} = $budget->{budget_ordered_sublevels} + $budget->{budget_ordered}; # PERMISSIONS unless(CanUserModifyBudget($borrowernumber, $budget, $staffflags)) { $budget->{'budget_lock'} = 1; @@ -300,22 +300,29 @@ if ($op eq 'add_form') { } ## TOTALS + $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'budget_spent'} - $budget->{budget_ordered}; + $budget->{'total_remaining'} = $budget->{'budget_amount'} - $budget->{'total_spent'} - $budget->{total_ordered}; # adds to total - only if budget is a 'top-level' budget - $period_alloc_total += $budget->{'budget_amount_total'} if $budget->{'depth'} == 0; - $base_spent_total += $budget->{'budget_spent'}; - $base_ordered_total += $budget->{budget_ordered}; - $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'total_levels_spent'}; + if ($budget->{depth} == 0) { + $period_alloc_total += $budget->{'budget_amount'}; + $spent_total += $budget->{total_spent}; + $ordered_total += $budget->{total_ordered}; + $available_total += $budget->{total_remaining}; + } # if amount == 0 dont display... delete $budget->{'budget_unalloc_sublevel'} if (!defined $budget->{'budget_unalloc_sublevel'} or $budget->{'budget_unalloc_sublevel'} == 0); - $budget->{'remaining_pos'} = 1 if $budget->{'budget_remaining'} > 0; - $budget->{'remaining_neg'} = 1 if $budget->{'budget_remaining'} < 0; - for (grep {/total_levels_spent|budget_spent|budget_ordered|budget_amount|budget_remaining|budget_unalloc/} keys %$budget){ + for (grep {/total_spent|budget_spent|total_ordered|budget_ordered|budget_amount/} keys %$budget){ $budget->{$_} = $num->format_price( $budget->{$_} ) if defined($budget->{$_}) } + for (qw/budget_remaining total_remaining/) { + if (defined $budget->{$_}) { + $budget->{$_.'_display'} = $num->format_price($budget->{$_}); + } + } # Value of budget_spent equals 0 instead of undefined value $budget->{"budget_spent"} = $num->format_price(0) unless defined($budget->{"budget_spent"}); @@ -344,22 +351,10 @@ if ($op eq 'add_form') { ); } - my $budget_period_total; - if ( $period->{budget_period_total} ) { - $budget_period_total = - $num->format_price( $period->{budget_period_total} ); - } - - if ($period_alloc_total) { - $period_alloc_total = $num->format_price($period_alloc_total); - } - - if ($base_spent_total) { - $base_spent_total = $num->format_price($base_spent_total); - } + my $budget_period_total = $period->{budget_period_total}; - if ($base_ordered_total) { - $base_ordered_total = $num->format_price($base_ordered_total); + foreach ($budget_period_total, $period_alloc_total, $spent_total, $ordered_total, $available_total) { + $_ = $num->format_price($_); } $template->param( @@ -367,8 +362,9 @@ if ($op eq 'add_form') { budget => \@loop, budget_period_total => $budget_period_total, period_alloc_total => $period_alloc_total, - base_spent_total => $base_spent_total, - base_ordered_total => $base_ordered_total, + spent_total => $spent_total, + ordered_total => $ordered_total, + available_total => $available_total, branchloop => \@branchloop2, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index e30d0bc..1abd720 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -245,12 +245,13 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Fund code Fund name - Total
allocated Base-level
allocated Base-level
ordered + Total ordered Base-level
spent - Total sublevels
spent - Base-level
remaining + Total spent + Base-level
available + Total available   Actions @@ -259,12 +260,13 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %] [% period_alloc_total %] - [% base_alloc_total %] - [% base_ordered_total %] - [% base_spent_total %] - [% base_spent_total %] - [% base_remaining_total %] + + [% ordered_total %] + + [% spent_total %] + + [% available_total %] @@ -278,19 +280,29 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") [% budge.budget_code_indent %] [% budge.budget_name %] - [% budge.budget_amount_total %] [% budge.budget_amount %] [% budge.budget_ordered %] + [% budge.total_ordered %] [% budge.budget_spent %] - [% budge.total_levels_spent %] - [% IF ( budge.remaining_pos ) %] - - [% ELSIF ( budge.remaining_neg ) %] - - [% ELSE %] - + [% budge.total_spent %] + + [% BLOCK colorcellvalue %] + [% IF (value > 0) %] + + [% ELSIF (value < 0) %] + + [% ELSE %] + + [% END %] + [% text %] + [% END %] - [% budge.budget_remaining %] + + [% INCLUDE colorcellvalue value=budge.budget_remaining text=budge.budget_remaining_display %] + + + [% INCLUDE colorcellvalue value=budge.total_remaining text=budge.total_remaining_display %] + [% IF ( budge.budget_owner_id ) %]Owner: [% budge.budget_owner_name %][% END %] [% IF ( budge.budget_branchcode ) %]
Library: [% budge.budget_branchcode %][% END %] -- 1.7.9.5