From 20fee0bb0d5f076a62b8789bf2b996d9b98231f2 Mon Sep 17 00:00:00 2001 From: Maxime Pelletier Date: Fri, 21 Feb 2014 17:18:11 -0500 Subject: [PATCH] Add the total ordered amount to the funds list. --- C4/Budgets.pm | 29 ++++++++++++++++++++ admin/aqbudgets.pl | 5 ++- .../prog/en/modules/admin/aqbudgets.tt | 2 + t/db_dependent/Acquisition.t | 4 ++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 334e610..222dfd9 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -45,6 +45,7 @@ BEGIN { &GetBudgetName &GetPeriodsCount &GetChildBudgetsSpent + &GetChildBudgetsOrdered &GetBudgetUsers &ModBudgetUsers @@ -724,6 +725,34 @@ sub GetChildBudgetsSpent { return $total_spent; } +=head2 GetChildBudgetsOrdered + + &GetChildBudgetsOrdered($budget_id); + +gets the total ordered of the level and sublevels of $budget_id + +=cut + +# ------------------------------------------------------------------- +sub GetChildBudgetsOrdered { + my ( $budget_id ) = @_; + my $dbh = C4::Context->dbh; + my $query = " + SELECT * + FROM aqbudgets + WHERE budget_parent_id=? + "; + my $sth = $dbh->prepare($query); + $sth->execute( $budget_id ); + my $result = $sth->fetchall_arrayref({}); + my $total_spent = GetBudgetOrdered($budget_id); + if ($result){ + $total_spent += GetChildBudgetsOrdered($_->{"budget_id"}) foreach @$result; + } + return $total_spent; +} + + =head2 GetBudgets &GetBudgets($filter, $order_by); diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 42a39f7..ccad617 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -283,6 +283,7 @@ if ($op eq 'add_form') { foreach my $budget (@budgets) { #Level and sublevels total spent $budget->{'total_levels_spent'} = GetChildBudgetsSpent($budget->{"budget_id"}); + $budget->{'total_levels_ordered'} = GetChildBudgetsOrdered($budget->{"budget_id"}); # PERMISSIONS unless(CanUserModifyBudget($borrowernumber, $budget, $staffflags)) { @@ -303,7 +304,7 @@ if ($op eq 'add_form') { # adds to total - only if budget is a 'top-level' budget $period_alloc_total += $budget->{'budget_amount_total'} if $budget->{'depth'} == 0; $base_spent_total += $budget->{'budget_spent'}; - $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'total_levels_spent'}; + $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'total_levels_spent'} - $budget->{'total_levels_ordered'}; # if amount == 0 dont display... delete $budget->{'budget_unalloc_sublevel'} @@ -312,7 +313,7 @@ if ($op eq 'add_form') { $budget->{'remaining_pos'} = 1 if $budget->{'budget_remaining'} > 0; $budget->{'remaining_neg'} = 1 if $budget->{'budget_remaining'} < 0; - for (grep {/total_levels_spent|budget_spent|budget_amount|budget_remaining|budget_unalloc/} keys %$budget){ + for (grep {/total_levels_spent|budget_spent|budget_amount|budget_remaining|budget_unalloc|total_levels_ordered/} keys %$budget){ $budget->{$_} = $num->format_price( $budget->{$_} ) if defined($budget->{$_}) } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index 219a049..2b9ee4b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -247,6 +247,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Base-level
allocated Base-level
spent Total sublevels
spent + Total sublevels
ordered Base-level
remaining   Actions @@ -278,6 +279,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") [% budge.budget_amount %] [% budge.budget_spent %] [% budge.total_levels_spent %] + [% budge.total_levels_ordered %] [% IF ( budge.remaining_pos ) %] [% ELSIF ( budge.remaining_neg ) %] diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 2585802..4eed47e 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -8,7 +8,7 @@ use POSIX qw(strftime); use C4::Bookseller qw( GetBookSellerFromId ); -use Test::More tests => 62; +use Test::More tests => 63; BEGIN { use_ok('C4::Acquisition'); @@ -92,6 +92,8 @@ ok( exists( @$orders[0]->{basketgroupname} ), "SearchOrder: The basketgroupname ok( GetBudgetByOrderNumber($ordernumber1)->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" ); +ok(GetChildBudgetsOrdered($budgetid) eq '168', "GetChildBudgetsOrdered returns the cost of all ordered acquisitions for the budget and all sub-budgets."); + C4::Acquisition::CloseBasket( $basketno ); my @lateorders = GetLateOrders(0); my $order = $lateorders[0]; -- 1.7.2.5