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

(-)a/C4/Budgets.pm (-23 / +21 lines)
Lines 573-607 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;
577
    $recursiveAdd = sub {
578
        my ($budget, $parent) = @_;
579
576
580
        foreach my $child (@{$budget->{children}}){
577
    foreach my $budget (@sort) {
581
            $recursiveAdd->($child, $budget);
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 );
582
        }
580
        }
581
    }
582
    return \@sort;
583
}
583
584
584
        $budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent};
585
sub _recursiveAdd {
585
        $budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost};
586
    my ($budget, $parent, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment ) = @_;
586
        $budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered};
587
        $budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost};
588
587
589
        $budget->{total_spent} += $budget->{budget_spent};
588
    foreach my $child (@{$budget->{children}}){
590
        $budget->{total_ordered} += $budget->{budget_ordered};
589
        _recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment );
590
    }
591
591
592
        if ($parent) {
592
    $budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent};
593
            $parent->{total_spent} += $budget->{total_spent};
593
    $budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost};
594
            $parent->{total_ordered} += $budget->{total_ordered};
594
    $budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered};
595
        }
595
    $budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost};
596
    };
597
596
598
    foreach my $budget (@sort) {
597
    $budget->{total_spent} += $budget->{budget_spent};
599
        if ($budget->{budget_parent_id} == undef) {
598
    $budget->{total_ordered} += $budget->{budget_ordered};
600
            $recursiveAdd->($budget);
601
        }
602
    }
603
599
604
    return \@sort;
600
    if ($parent) {
601
        $parent->{total_spent} += $budget->{total_spent};
602
        $parent->{total_ordered} += $budget->{total_ordered};
603
    }
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