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