@@ -, +, @@ --- C4/Budgets.pm | 11 ++--- admin/aqbudgets.pl | 52 +++++++++----------- .../prog/en/modules/admin/aqbudgets.tt | 46 ++++++++++------- 3 files changed, 57 insertions(+), 52 deletions(-) --- a/C4/Budgets.pm +++ a/C4/Budgets.pm @@ -576,16 +576,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; --- a/admin/aqbudgets.pl +++ a/admin/aqbudgets.pl @@ -277,14 +277,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; @@ -301,22 +301,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"}); @@ -345,22 +352,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( @@ -368,8 +363,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, ); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -226,12 +226,13 @@