View | Details | Raw Unified | Return to bug 19792
Collapse All | Expand All

(-)a/C4/Budgets.pm (-14 / +12 lines)
Lines 573-584 sub GetBudgetHierarchy { Link Here
573
        GROUP BY shipmentcost_budgetid
573
        GROUP BY shipmentcost_budgetid
574
        |, 'budget_id');
574
        |, 'budget_id');
575
575
576
    my $recursiveAdd;
576
577
    $recursiveAdd = sub {
577
    foreach my $budget (@sort) {
578
        my ($budget, $parent) = @_;
578
        if ($budget->{budget_parent_id} == undef) {
579
            _recursiveAdd( $budget, undef, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment );
580
        }
581
    }
582
    return \@sort;
583
}
584
585
sub _recursiveAdd {
586
        my ($budget, $parent, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment ) = @_;
579
587
580
        foreach my $child (@{$budget->{children}}){
588
        foreach my $child (@{$budget->{children}}){
581
            $recursiveAdd->($child, $budget);
589
            _recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment );
582
        }
590
        }
583
591
584
        $budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent};
592
        $budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent};
Lines 593-607 sub GetBudgetHierarchy { Link Here
593
            $parent->{total_spent} += $budget->{total_spent};
601
            $parent->{total_spent} += $budget->{total_spent};
594
            $parent->{total_ordered} += $budget->{total_ordered};
602
            $parent->{total_ordered} += $budget->{total_ordered};
595
        }
603
        }
596
    };
597
598
    foreach my $budget (@sort) {
599
        if ($budget->{budget_parent_id} == undef) {
600
            $recursiveAdd->($budget);
601
        }
602
    }
603
604
    return \@sort;
605
}
604
}
606
605
607
# Recursive method to add a budget and its chidren to an array
606
# Recursive method to add a budget and its chidren to an array
608
- 

Return to bug 19792