Lines 488-493
sub ModBudgetPeriod {
Link Here
|
488 |
|
488 |
|
489 |
# ------------------------------------------------------------------- |
489 |
# ------------------------------------------------------------------- |
490 |
sub GetBudgetHierarchy { |
490 |
sub GetBudgetHierarchy { |
|
|
491 |
warn "Here"; |
492 |
$debug=1; |
491 |
my ( $budget_period_id, $branchcode, $owner ) = @_; |
493 |
my ( $budget_period_id, $branchcode, $owner ) = @_; |
492 |
my @bind_params; |
494 |
my @bind_params; |
493 |
my $dbh = C4::Context->dbh; |
495 |
my $dbh = C4::Context->dbh; |
Lines 532-538
sub GetBudgetHierarchy {
Link Here
|
532 |
} |
534 |
} |
533 |
|
535 |
|
534 |
# link child to parent |
536 |
# link child to parent |
|
|
537 |
warn Data::Dumper::Dumper( %links ); |
535 |
my @first_parents; |
538 |
my @first_parents; |
|
|
539 |
warn Data::Dumper::Dumper(( sort { $a->{budget_code} cmp $b->{budget_code} } values %links )); |
536 |
foreach my $budget ( sort { $a->{budget_code} cmp $b->{budget_code} } values %links ) { |
540 |
foreach my $budget ( sort { $a->{budget_code} cmp $b->{budget_code} } values %links ) { |
537 |
my $child = $links{$budget->{budget_id}}; |
541 |
my $child = $links{$budget->{budget_id}}; |
538 |
if ( $child->{'budget_parent_id'} ) { |
542 |
if ( $child->{'budget_parent_id'} ) { |
Lines 584-610
sub GetBudgetHierarchy {
Link Here
|
584 |
WHERE closedate IS NULL |
588 |
WHERE closedate IS NULL |
585 |
GROUP BY shipmentcost_budgetid |
589 |
GROUP BY shipmentcost_budgetid |
586 |
|, 'budget_id'); |
590 |
|, 'budget_id'); |
|
|
591 |
my $hr_budget_spent_adjustment = $dbh->selectall_hashref(q| |
592 |
SELECT budget_id, |
593 |
SUM(adjustment) as adjustments |
594 |
FROM aqinvoice_adjustments |
595 |
JOIN aqinvoices USING (invoiceid) |
596 |
WHERE closedate IS NOT NULL |
597 |
GROUP BY budget_id |
598 |
|, 'budget_id'); |
599 |
my $hr_budget_ordered_adjustment = $dbh->selectall_hashref(q| |
600 |
SELECT budget_id, |
601 |
SUM(adjustment) as adjustments |
602 |
FROM aqinvoice_adjustments |
603 |
JOIN aqinvoices USING (invoiceid) |
604 |
WHERE closedate IS NULL AND encumber_open = 1 |
605 |
GROUP BY budget_id |
606 |
|, 'budget_id'); |
587 |
|
607 |
|
588 |
|
608 |
|
589 |
foreach my $budget (@sort) { |
609 |
foreach my $budget (@sort) { |
590 |
if ( not defined $budget->{budget_parent_id} ) { |
610 |
if ( not defined $budget->{budget_parent_id} ) { |
591 |
_recursiveAdd( $budget, undef, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment ); |
611 |
_recursiveAdd( $budget, undef, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment, $hr_budget_spent_adjustment, $hr_budget_ordered_adjustment ); |
592 |
} |
612 |
} |
593 |
} |
613 |
} |
594 |
return \@sort; |
614 |
return \@sort; |
595 |
} |
615 |
} |
596 |
|
616 |
|
597 |
sub _recursiveAdd { |
617 |
sub _recursiveAdd { |
598 |
my ($budget, $parent, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment ) = @_; |
618 |
my ($budget, $parent, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment, $hr_budget_spent_adjustment, $hr_budget_ordered_adjustment ) = @_; |
599 |
|
619 |
|
600 |
foreach my $child (@{$budget->{children}}){ |
620 |
foreach my $child (@{$budget->{children}}){ |
601 |
_recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment ); |
621 |
_recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment, $hr_budget_spent_adjustment, $hr_budget_ordered_adjustment ); |
602 |
} |
622 |
} |
603 |
|
623 |
|
604 |
$budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent}; |
624 |
$budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent}; |
605 |
$budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost}; |
625 |
$budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost}; |
|
|
626 |
$budget->{budget_spent} += $hr_budget_spent_adjustment->{$budget->{budget_id}}->{adjustments}; |
606 |
$budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered}; |
627 |
$budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered}; |
607 |
$budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost}; |
628 |
$budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost}; |
|
|
629 |
$budget->{budget_ordered} += $hr_budget_ordered_adjustment->{$budget->{budget_id}}->{adjustments}; |
608 |
|
630 |
|
609 |
$budget->{total_spent} += $budget->{budget_spent}; |
631 |
$budget->{total_spent} += $budget->{budget_spent}; |
610 |
$budget->{total_ordered} += $budget->{budget_ordered}; |
632 |
$budget->{total_ordered} += $budget->{budget_ordered}; |