|
Lines 44-50
BEGIN {
Link Here
|
| 44 |
&GetBudgetOrdered |
44 |
&GetBudgetOrdered |
| 45 |
&GetBudgetName |
45 |
&GetBudgetName |
| 46 |
&GetPeriodsCount |
46 |
&GetPeriodsCount |
| 47 |
&GetChildBudgetsSpent |
47 |
GetBudgetHierarchySpent |
|
|
48 |
GetBudgetHierarchyOrdered |
| 48 |
|
49 |
|
| 49 |
&GetBudgetUsers |
50 |
&GetBudgetUsers |
| 50 |
&ModBudgetUsers |
51 |
&ModBudgetUsers |
|
Lines 594-628
sub GetBudgetHierarchy {
Link Here
|
| 594 |
last if $children == 0; |
595 |
last if $children == 0; |
| 595 |
} |
596 |
} |
| 596 |
|
597 |
|
| 597 |
# add budget-percent and allocation, and flags for html-template |
|
|
| 598 |
foreach my $r (@sort) { |
| 599 |
my $subs_href = $r->{'child'}; |
| 600 |
my @subs_arr = (); |
| 601 |
if ( defined $subs_href ) { |
| 602 |
@subs_arr = @{$subs_href}; |
| 603 |
} |
| 604 |
|
| 605 |
my $moo = $r->{'budget_code_indent'}; |
| 606 |
$moo =~ s/\ /\ \;/g; |
| 607 |
$r->{'budget_code_indent'} = $moo; |
| 608 |
|
| 609 |
$moo = $r->{'budget_name_indent'}; |
| 610 |
$moo =~ s/\ /\ \;/g; |
| 611 |
$r->{'budget_name_indent'} = $moo; |
| 612 |
|
| 613 |
$r->{'budget_spent'} = GetBudgetSpent( $r->{'budget_id'} ); |
| 614 |
$r->{budget_ordered} = GetBudgetOrdered( $r->{budget_id} ); |
| 615 |
|
598 |
|
| 616 |
$r->{budget_spent_sublevels} = 0; |
599 |
foreach my $budget (@sort) { |
| 617 |
$r->{budget_ordered_sublevels} = 0; |
600 |
$budget->{budget_spent} = GetBudgetSpent( $budget->{budget_id} ); |
| 618 |
# foreach sub-levels |
601 |
$budget->{budget_ordered} = GetBudgetOrdered( $budget->{budget_id} ); |
| 619 |
foreach my $sub (@subs_arr) { |
602 |
$budget->{total_spent} = GetBudgetHierarchySpent( $budget->{budget_id} ); |
| 620 |
my $sub_budget = GetBudget($sub); |
603 |
$budget->{total_ordered} = GetBudgetHierarchyOrdered( $budget->{budget_id} ); |
| 621 |
$r->{budget_spent_sublevels} += GetBudgetSpent( $sub_budget->{'budget_id'} ); |
604 |
} |
| 622 |
$r->{budget_ordered_sublevels} += GetBudgetOrdered($sub); |
605 |
return \@sort; |
| 623 |
} |
|
|
| 624 |
} |
| 625 |
return \@sort; |
| 626 |
} |
606 |
} |
| 627 |
|
607 |
|
| 628 |
# ------------------------------------------------------------------- |
608 |
# ------------------------------------------------------------------- |
|
Lines 695-727
sub GetBudgetByOrderNumber {
Link Here
|
| 695 |
return $result; |
675 |
return $result; |
| 696 |
} |
676 |
} |
| 697 |
|
677 |
|
| 698 |
=head2 GetChildBudgetsSpent |
678 |
=head2 GetBudgetHierarchySpent |
| 699 |
|
679 |
|
| 700 |
&GetChildBudgetsSpent($budget-id); |
680 |
my $spent = GetBudgetHierarchySpent( $budget_id ); |
| 701 |
|
681 |
|
| 702 |
gets the total spent of the level and sublevels of $budget_id |
682 |
Gets the total spent of the level and sublevels of $budget_id |
| 703 |
|
683 |
|
| 704 |
=cut |
684 |
=cut |
| 705 |
|
685 |
|
| 706 |
# ------------------------------------------------------------------- |
686 |
sub GetBudgetHierarchySpent { |
| 707 |
sub GetChildBudgetsSpent { |
|
|
| 708 |
my ( $budget_id ) = @_; |
687 |
my ( $budget_id ) = @_; |
| 709 |
my $dbh = C4::Context->dbh; |
688 |
my $dbh = C4::Context->dbh; |
| 710 |
my $query = " |
689 |
my $children_ids = $dbh->selectcol_arrayref(q| |
| 711 |
SELECT * |
690 |
SELECT budget_id |
| 712 |
FROM aqbudgets |
691 |
FROM aqbudgets |
| 713 |
WHERE budget_parent_id=? |
692 |
WHERE budget_parent_id = ? |
| 714 |
"; |
693 |
|, {}, $budget_id ); |
| 715 |
my $sth = $dbh->prepare($query); |
694 |
|
| 716 |
$sth->execute( $budget_id ); |
695 |
my $total_spent = GetBudgetSpent( $budget_id ); |
| 717 |
my $result = $sth->fetchall_arrayref({}); |
696 |
for my $child_id ( @$children_ids ) { |
| 718 |
my $total_spent = GetBudgetSpent($budget_id); |
697 |
$total_spent += GetBudgetHierarchySpent( $child_id ); |
| 719 |
if ($result){ |
|
|
| 720 |
$total_spent += GetChildBudgetsSpent($_->{"budget_id"}) foreach @$result; |
| 721 |
} |
698 |
} |
| 722 |
return $total_spent; |
699 |
return $total_spent; |
| 723 |
} |
700 |
} |
| 724 |
|
701 |
|
|
|
702 |
=head2 GetBudgetHierarchyOrdered |
| 703 |
|
| 704 |
my $ordered = GetBudgetHierarchyOrdered( $budget_id ); |
| 705 |
|
| 706 |
Gets the total ordered of the level and sublevels of $budget_id |
| 707 |
|
| 708 |
=cut |
| 709 |
|
| 710 |
sub GetBudgetHierarchyOrdered { |
| 711 |
my ( $budget_id ) = @_; |
| 712 |
my $dbh = C4::Context->dbh; |
| 713 |
my $children_ids = $dbh->selectcol_arrayref(q| |
| 714 |
SELECT budget_id |
| 715 |
FROM aqbudgets |
| 716 |
WHERE budget_parent_id = ? |
| 717 |
|, {}, $budget_id ); |
| 718 |
|
| 719 |
my $total_ordered = GetBudgetOrdered( $budget_id ); |
| 720 |
for my $child_id ( @$children_ids ) { |
| 721 |
$total_ordered += GetBudgetHierarchyOrdered( $child_id ); |
| 722 |
} |
| 723 |
return $total_ordered; |
| 724 |
} |
| 725 |
|
| 725 |
=head2 GetBudgets |
726 |
=head2 GetBudgets |
| 726 |
|
727 |
|
| 727 |
&GetBudgets($filter, $order_by); |
728 |
&GetBudgets($filter, $order_by); |