From c6d36a83453f4c46b2766a401ab64f65bed3b0c1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 2 Dec 2014 17:31:03 +0100 Subject: [PATCH] Bug 13392: New statistics assistant for suggestions New sub C4::Budgets::GetBudgetDescendantsIds (with unit tests) Signed-off-by: Nicole Engard --- C4/Budgets.pm | 30 +++ .../prog/en/includes/reports-menu.inc | 1 + .../prog/en/includes/reports/fields.inc | 25 ++ .../prog/en/modules/reports/reports-home.tt | 1 + .../prog/en/modules/reports/suggestions_stats.tt | 186 ++++++++++++++ .../modules/reports/suggestions_stats_results.tt | 83 +++++++ reports/suggestions_stats.pl | 268 +++++++++++++++++++++ t/db_dependent/Budgets.t | 13 +- 8 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/reports/fields.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats_results.tt create mode 100755 reports/suggestions_stats.pl diff --git a/C4/Budgets.pm b/C4/Budgets.pm index d0c4400..6c9946c 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -191,6 +191,36 @@ sub GetBudgetChildren { |, { Slice => {} }, $budget_id ); } +sub GetBudgetDescendantsIds { + my ($budget_id) = @_; + + return () unless $budget_id; + + my @descendants_ids; + + my $query = q| + SELECT budget_id FROM aqbudgets WHERE budget_parent_id = ? + |; + my $dbh = C4::Context->dbh; + my @children_ids = map { + $_->{budget_id} + } @{ $dbh->selectall_arrayref($query, {Slice => {}}, $budget_id) }; + + while (@children_ids) { + push @descendants_ids, @children_ids; + $query = ' + SELECT budget_id + FROM aqbudgets + WHERE budget_parent_id IN (' . join(',', ('?') x @children_ids) . ')'; + @children_ids = map { + $_->{budget_id} + } @{ $dbh->selectall_arrayref($query, {Slice => {}}, @children_ids) }; + } + + return @descendants_ids; +} + + sub SetOwnerToFundHierarchy { my ( $budget_id, $borrowernumber ) = @_; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-menu.inc index 8c4fe9f..4d3b70e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-menu.inc @@ -6,6 +6,7 @@
Statistics wizards