Lines 276-289
if ($op eq 'add_form') {
Link Here
|
276 |
my $toggle = 0; |
276 |
my $toggle = 0; |
277 |
my @loop; |
277 |
my @loop; |
278 |
my $period_total = 0; |
278 |
my $period_total = 0; |
279 |
my ( $period_alloc_total, $base_spent_total, $base_ordered_total ); |
279 |
my ($period_alloc_total, $spent_total, $ordered_total, $available_total) = (0,0,0,0); |
280 |
|
280 |
|
281 |
#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 ? |
281 |
#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 ? |
282 |
|
282 |
|
283 |
foreach my $budget (@budgets) { |
283 |
foreach my $budget (@budgets) { |
284 |
#Level and sublevels total spent |
284 |
#Level and sublevels total spent and ordered |
285 |
$budget->{'total_levels_spent'} = GetChildBudgetsSpent($budget->{"budget_id"}); |
285 |
$budget->{total_spent} = $budget->{budget_spent_sublevels} + $budget->{budget_spent}; |
286 |
|
286 |
$budget->{total_ordered} = $budget->{budget_ordered_sublevels} + $budget->{budget_ordered}; |
287 |
# PERMISSIONS |
287 |
# PERMISSIONS |
288 |
unless(CanUserModifyBudget($borrowernumber, $budget, $staffflags)) { |
288 |
unless(CanUserModifyBudget($borrowernumber, $budget, $staffflags)) { |
289 |
$budget->{'budget_lock'} = 1; |
289 |
$budget->{'budget_lock'} = 1; |
Lines 300-321
if ($op eq 'add_form') {
Link Here
|
300 |
} |
300 |
} |
301 |
|
301 |
|
302 |
## TOTALS |
302 |
## TOTALS |
|
|
303 |
$budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'budget_spent'} - $budget->{budget_ordered}; |
304 |
$budget->{'total_remaining'} = $budget->{'budget_amount'} - $budget->{'total_spent'} - $budget->{total_ordered}; |
303 |
# adds to total - only if budget is a 'top-level' budget |
305 |
# adds to total - only if budget is a 'top-level' budget |
304 |
$period_alloc_total += $budget->{'budget_amount_total'} if $budget->{'depth'} == 0; |
306 |
if ($budget->{depth} == 0) { |
305 |
$base_spent_total += $budget->{'budget_spent'}; |
307 |
$period_alloc_total += $budget->{'budget_amount'}; |
306 |
$base_ordered_total += $budget->{budget_ordered}; |
308 |
$spent_total += $budget->{total_spent}; |
307 |
$budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'total_levels_spent'}; |
309 |
$ordered_total += $budget->{total_ordered}; |
|
|
310 |
$available_total += $budget->{total_remaining}; |
311 |
} |
308 |
|
312 |
|
309 |
# if amount == 0 dont display... |
313 |
# if amount == 0 dont display... |
310 |
delete $budget->{'budget_unalloc_sublevel'} |
314 |
delete $budget->{'budget_unalloc_sublevel'} |
311 |
if (!defined $budget->{'budget_unalloc_sublevel'} |
315 |
if (!defined $budget->{'budget_unalloc_sublevel'} |
312 |
or $budget->{'budget_unalloc_sublevel'} == 0); |
316 |
or $budget->{'budget_unalloc_sublevel'} == 0); |
313 |
|
317 |
|
314 |
$budget->{'remaining_pos'} = 1 if $budget->{'budget_remaining'} > 0; |
318 |
for (grep {/total_spent|budget_spent|total_ordered|budget_ordered|budget_amount/} keys %$budget){ |
315 |
$budget->{'remaining_neg'} = 1 if $budget->{'budget_remaining'} < 0; |
|
|
316 |
for (grep {/total_levels_spent|budget_spent|budget_ordered|budget_amount|budget_remaining|budget_unalloc/} keys %$budget){ |
317 |
$budget->{$_} = $num->format_price( $budget->{$_} ) if defined($budget->{$_}) |
319 |
$budget->{$_} = $num->format_price( $budget->{$_} ) if defined($budget->{$_}) |
318 |
} |
320 |
} |
|
|
321 |
for (qw/budget_remaining total_remaining/) { |
322 |
if (defined $budget->{$_}) { |
323 |
$budget->{$_.'_display'} = $num->format_price($budget->{$_}); |
324 |
} |
325 |
} |
319 |
|
326 |
|
320 |
# Value of budget_spent equals 0 instead of undefined value |
327 |
# Value of budget_spent equals 0 instead of undefined value |
321 |
$budget->{"budget_spent"} = $num->format_price(0) unless defined($budget->{"budget_spent"}); |
328 |
$budget->{"budget_spent"} = $num->format_price(0) unless defined($budget->{"budget_spent"}); |
Lines 344-365
if ($op eq 'add_form') {
Link Here
|
344 |
); |
351 |
); |
345 |
} |
352 |
} |
346 |
|
353 |
|
347 |
my $budget_period_total; |
354 |
my $budget_period_total = $period->{budget_period_total}; |
348 |
if ( $period->{budget_period_total} ) { |
|
|
349 |
$budget_period_total = |
350 |
$num->format_price( $period->{budget_period_total} ); |
351 |
} |
352 |
|
353 |
if ($period_alloc_total) { |
354 |
$period_alloc_total = $num->format_price($period_alloc_total); |
355 |
} |
356 |
|
357 |
if ($base_spent_total) { |
358 |
$base_spent_total = $num->format_price($base_spent_total); |
359 |
} |
360 |
|
355 |
|
361 |
if ($base_ordered_total) { |
356 |
foreach ($budget_period_total, $period_alloc_total, $spent_total, $ordered_total, $available_total) { |
362 |
$base_ordered_total = $num->format_price($base_ordered_total); |
357 |
$_ = $num->format_price($_); |
363 |
} |
358 |
} |
364 |
|
359 |
|
365 |
$template->param( |
360 |
$template->param( |
Lines 367-374
if ($op eq 'add_form') {
Link Here
|
367 |
budget => \@loop, |
362 |
budget => \@loop, |
368 |
budget_period_total => $budget_period_total, |
363 |
budget_period_total => $budget_period_total, |
369 |
period_alloc_total => $period_alloc_total, |
364 |
period_alloc_total => $period_alloc_total, |
370 |
base_spent_total => $base_spent_total, |
365 |
spent_total => $spent_total, |
371 |
base_ordered_total => $base_ordered_total, |
366 |
ordered_total => $ordered_total, |
|
|
367 |
available_total => $available_total, |
372 |
branchloop => \@branchloop2, |
368 |
branchloop => \@branchloop2, |
373 |
); |
369 |
); |
374 |
|
370 |
|