Bugzilla – Attachment 34135 Details for
Bug 13392
New statistics wizard for suggestions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13392: New statistics assistant for suggestions
Bug-13392-New-statistics-assistant-for-suggestions.patch (text/plain), 23.70 KB, created by
Julian Maurice
on 2014-12-05 09:15:10 UTC
(
hide
)
Description:
Bug 13392: New statistics assistant for suggestions
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2014-12-05 09:15:10 UTC
Size:
23.70 KB
patch
obsolete
>From d5ca2acc8d0b0cf897a5de364c5a8fed7f6ed1c9 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >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) >--- > 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 | 12 +- > 8 files changed, 605 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 ccc3d37..3bf392e 100644 >--- a/C4/Budgets.pm >+++ b/C4/Budgets.pm >@@ -196,6 +196,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..302d707 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 @@ > <h5>Statistics wizards</h5> > <ul> > <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li> >+ <li><a href="/cgi-bin/koha/reports/suggestions_stats.pl">Suggestions</a></li> > <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li> > <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li> > <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports/fields.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports/fields.inc >new file mode 100644 >index 0000000..5500c14 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports/fields.inc >@@ -0,0 +1,25 @@ >+[% BLOCK field_label %] >+ [% SWITCH name %] >+ [% CASE 'suggesteddate' %]Suggest date >+ [% CASE 'suggesteddate_from' %]Suggest date (from) >+ [% CASE 'suggesteddate_to' %]Suggest date (to) >+ [% CASE 'rejecteddate' %]Reject date >+ [% CASE 'rejecteddate_from' %]Reject date (from) >+ [% CASE 'rejecteddate_to' %]Reject date (to) >+ [% CASE 'ordereddate' %]Order date >+ [% CASE 'ordereddate_from' %]Order date (from) >+ [% CASE 'ordereddate_to' %]Order date (to) >+ [% CASE 'publicationyear' %]Publication year >+ [% CASE 'publicationyear_from' %]Publication year (from) >+ [% CASE 'publicationyear_to' %]Publication year (to) >+ [% CASE 'status' %]Status >+ [% CASE 'budgetid' %]Fund >+ [% CASE 'budgetid_children' %]Include child funds >+ [% CASE 'categorycode' %]Borrower category >+ [% CASE 'sort1' %]Borrower sort field 1 >+ [% CASE 'sort2' %]Borrower sort field 2 >+ [% CASE 'branchcode' %]Branch >+ [% CASE 'reason' %]Reject reason >+ [% CASE 'itemtype' %]Item type >+ [% END %] >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt >index fde9ad3..22a0402 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt >@@ -30,6 +30,7 @@ > <h2>Statistics wizards</h2> > <ul> > <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li> >+ <li><a href="/cgi-bin/koha/reports/suggestions_stats.pl">Suggestions</a></li> > <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li> > <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li> > <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats.tt >new file mode 100644 >index 0000000..e1a2914 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats.tt >@@ -0,0 +1,186 @@ >+[% PROCESS 'reports/fields.inc' %] >+ >+[% BLOCK tr %] >+ <tr> >+ <td>[% INCLUDE field_label name=name %]</td> >+ <td><input type="radio" name="line" value="[% name %]" /></td> >+ <td><input type="radio" name="column" value="[% name %]" /></td> >+ <td>[% groupby %]</td> >+ <td>[% filter %]</td> >+ </tr> >+[% END %] >+ >+[% BLOCK date_tr %] >+ [% date_groupby = BLOCK %] >+ <select name="groupby_[% name %]"> >+ <option value=""></option> >+ <option value="year">Year</option> >+ <option value="month">Month</option> >+ <option value="week">Week</option> >+ <option value="dow">Day of week</option> >+ </select> >+ [% END %] >+ >+ [% date_filter = BLOCK %] >+ From >+ <input type="text" size="10" id="filter_[% name %]_from" >+ name="filter_[% name %]_from"/> >+ <span class="hint">[% INCLUDE 'date-format.inc' %]</span> >+ To >+ <input type="text" size="10" id="filter_[% name %]_to" >+ name="filter_[% name %]_to"/> >+ <span class="hint">[% INCLUDE 'date-format.inc' %]</span> >+ [% END %] >+ >+ [% INCLUDE tr groupby=date_groupby filter=date_filter %] >+[% END %] >+ >+[% BLOCK select_tr %] >+ [% select_filter = BLOCK %] >+ <select name="filter_[% name %]"> >+ <option value=""></option> >+ [% FOREACH value IN display_values.$name.keys.sort %] >+ <option value="[% value %]">[% display_values.$name.$value %]</option> >+ [% END %] >+ </select> >+ [% END %] >+ >+ [% INCLUDE tr filter=select_filter %] >+[% END %] >+ >+[% INCLUDE 'doc-head-open.inc' %] >+ <title>Koha › Reports › Suggestions statistics</title> >+ [% INCLUDE 'doc-head-close.inc' %] >+ [% INCLUDE 'calendar.inc' %] >+ <script type="text/javascript"> >+ //<![CDATA[ >+ >+ (function($) { >+ >+ var onDateSelect = function(selectedDate) { >+ var option = this.id.match(/from$/) ? "minDate" : "maxDate", >+ instance = $(this).data("datepicker"), >+ dateFormat = instance.settings.dateFormat || $.datepicker._defaults.dateFormat; >+ var sDate = $.datepicker.parseDate(dateFormat, selectedDate, instance.settings); >+ var otherId = this.id.match(/from$/) >+ ? this.id.replace(/from$/, 'to') >+ : this.id.replace(/to$/, 'from'); >+ $('#' + otherId).datepicker("option", option, sDate); >+ }; >+ >+ $(document).ready(function() { >+ var datesSelectors = [ >+ '#filter_suggesteddate_from', >+ '#filter_suggesteddate_to', >+ '#filter_rejecteddate_from', >+ '#filter_rejecteddate_to', >+ '#filter_ordereddate_from', >+ '#filter_ordereddate_to', >+ ] >+ $(datesSelectors.join(',')) >+ .datepicker({ >+ changeMonth: true, >+ numberOfMonths: 1, >+ onSelect: onDateSelect >+ }); >+ }); >+ >+ })(jQuery); >+ >+ //]]> >+ </script> >+</head> >+ >+<body id="rep_suggestions_stats" class="rep"> >+ [% INCLUDE 'header.inc' %] >+ [% INCLUDE 'cat-search.inc' %] >+ >+ <div id="breadcrumbs"> >+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> >+ › >+ <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> >+ › >+ Suggestions statistics >+ </div> >+ >+ <div id="doc3" class="yui-t2"> >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ >+ <form method="post" action="/cgi-bin/koha/reports/suggestions_stats.pl"> >+ <fieldset class="rows"> >+ <legend>Acquisitions statistics</legend> >+ <table> >+ <thead> >+ <tr> >+ <th>Title</th> >+ <th>Row</th> >+ <th>Column</th> >+ <th>Group by</th> >+ <th>Filter</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% INCLUDE date_tr name='suggesteddate' %] >+ [% INCLUDE date_tr name='rejecteddate' %] >+ [% INCLUDE date_tr name='ordereddate' %] >+ >+ [% publicationyear_filter = BLOCK %] >+ From >+ <input type="text" size="4" name="filter_publicationyear_from"/> >+ To >+ <input type="text" size="4" name="filter_publicationyear_to"/> >+ [% END %] >+ [% INCLUDE tr name='publicationyear' filter=publicationyear_filter %] >+ >+ [% INCLUDE select_tr name='status' %] >+ [% INCLUDE select_tr name='categorycode' %] >+ [% INCLUDE select_tr name='sort1' %] >+ [% INCLUDE select_tr name='sort2' %] >+ [% INCLUDE select_tr name='branchcode' %] >+ [% INCLUDE select_tr name='reason' %] >+ [% INCLUDE select_tr name='itemtype' %] >+ >+ [%# Recursive block that display budgets in a hierarchy %] >+ [% BLOCK budget_option %] >+ [% indent = indent || 0 %] >+ <option value="[% budget.budget_id %]"> >+ [% '--' |repeat(indent) %] >+ [% budget.budget_name %] >+ </option> >+ [% FOREACH child IN budget.children %] >+ [% INCLUDE budget_option budget=child indent=indent+1 %] >+ [% END %] >+ [% END %] >+ >+ [% budgetid_filter = BLOCK %] >+ <select name="filter_budgetid"> >+ <option value=""></option> >+ [% FOREACH budget IN budget_hierarchy %] >+ [% INCLUDE budget_option budget=budget %] >+ [% END %] >+ </select> >+ <input type="checkbox" name="filter_budgetid_children" id="filter_budgetid_children" value="1"> >+ <label for="filter_budgetid_children">Include child funds</label> >+ [% END %] >+ [% INCLUDE tr name='budgetid' filter=budgetid_filter %] >+ </tbody> >+ </table> >+ </fieldset> >+ >+ <fieldset class="action"> >+ <input type="submit" value="Submit" /> >+ </fieldset> >+ </form> >+ >+ </div> >+ </div> >+ >+ <div class="yui-b"> >+ [% INCLUDE 'reports-menu.inc' %] >+ </div> >+ </div> >+ </div> >+ >+ [% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats_results.tt >new file mode 100644 >index 0000000..c507eb1 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats_results.tt >@@ -0,0 +1,83 @@ >+[% PROCESS 'reports/fields.inc' %] >+ >+[% INCLUDE 'doc-head-open.inc' %] >+ <title>Koha › Reports › Acquisitions statistics results</title> >+ [% INCLUDE 'doc-head-close.inc' %] >+ [% INCLUDE 'calendar.inc' %] >+</head> >+ >+<body id="rep_suggestions_stats" class="rep"> >+ [% INCLUDE 'header.inc' %] >+ [% INCLUDE 'cat-search.inc' %] >+ >+ <div id="breadcrumbs"> >+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> >+ › >+ <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> >+ › >+ Suggestions statistics >+ </div> >+ >+ <div id="doc3" class="yui-t2"> >+ >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ >+ <h1>Acquisitions statistics </h1> >+ [% IF filters.keys.size %] >+ <p><b>Filtered on:</b></p> >+ <ul> >+ [% FOREACH filter IN filters.keys %] >+ <li> >+ [% INCLUDE field_label name=filter %] : >+ [% value = filters.$filter %] >+ [% display_values.$filter.$value || value %] >+ </li> >+ [% END %] >+ </ul> >+ [% END %] >+ >+ [% totalcols = {} %] >+ [% total = 0 %] >+ <table> >+ <tr> >+ <th>[% INCLUDE field_label name=line %] / [% INCLUDE field_label name=column %]</th> >+ [% FOREACH col IN result.cols %] >+ <th>[% display_values.$column.$col || col %]</th> >+ [% totalcols.$col = 0 %] >+ [% END %] >+ <th>TOTAL</th> >+ </tr> >+ [% FOREACH row IN result.rows %] >+ [% totalrow = 0 %] >+ <tr> >+ <td>[% display_values.$line.$row || row %]</td> >+ [% FOREACH col IN result.cols %] >+ [% value = result.table.item(row).item(col) || 0 %] >+ <td>[% value %]</td> >+ >+ [%# Update totals %] >+ [% totalrow = totalrow + value %] >+ [% totalcols.$col = totalcols.$col + value %] >+ [% total = total + value %] >+ [% END %] >+ <td>[% totalrow %]</td> >+ </tr> >+ [% END %] >+ <tr> >+ <th>TOTAL</th> >+ [% FOREACH col IN result.cols %] >+ <th>[% totalcols.$col %]</th> >+ [% END %] >+ <th>[% total %]</th> >+ </tr> >+ </table> >+ </div> >+ </div> >+ >+ <div class="yui-b"> >+ [% INCLUDE 'reports-menu.inc' %] >+ </div> >+ >+ [% INCLUDE 'intranet-bottom.inc' %] >diff --git a/reports/suggestions_stats.pl b/reports/suggestions_stats.pl >new file mode 100755 >index 0000000..e8cd7ca >--- /dev/null >+++ b/reports/suggestions_stats.pl >@@ -0,0 +1,268 @@ >+#!/usr/bin/perl >+ >+# Copyright 2014 BibLibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+use CGI; >+ >+use C4::Auth; >+use C4::Context; >+use C4::Output; >+ >+use C4::Branch; >+use C4::Budgets; >+use C4::Category; >+use C4::Dates qw/format_date format_date_in_iso/; >+use C4::ItemType; >+use C4::Koha; >+use C4::Reports; >+ >+use Koha::I18N; >+ >+my $cgi = new CGI; >+my $template_name = 'reports/suggestions_stats.tt'; >+my $line = $cgi->param("line"); >+my $column = $cgi->param("column"); >+ >+if ($line and $column) { >+ $template_name = 'reports/suggestions_stats_results.tt'; >+} >+ >+my ( $template, $borrowernumber, $cookie ) = get_template_and_user( >+ { >+ template_name => $template_name, >+ query => $cgi, >+ type => 'intranet', >+ authnotrequired => 0, >+ flagsrequired => { reports => '*' }, >+ } >+); >+ >+if ($line and $column) { >+ my ($filters, $groupby) = ({}, {}); >+ foreach my $param ($cgi->param()) { >+ my $value = $cgi->param($param); >+ if ( (defined $value) && ($value ne '') ) { >+ if ($param =~ /^filter_(.*)/) { >+ $filters->{$1} = $cgi->param($param); >+ } elsif ($param =~ /^groupby_(.*)/) { >+ $groupby->{$1} = $cgi->param($param); >+ } >+ } >+ } >+ >+ my $result = calculate($line, $column, $groupby, $filters); >+ >+ $template->param( >+ line => $line, >+ column => $column, >+ filters => $filters, >+ result => $result, >+ ); >+} else { >+ my $budget_hierarchy = C4::Budgets::GetBudgetHierarchy; >+ >+ # Remove all children from the first level of this array. >+ @$budget_hierarchy = grep { >+ not defined $_->{budget_parent_id} >+ } @$budget_hierarchy; >+ >+ $template->param( budget_hierarchy => $budget_hierarchy); >+} >+ >+my $display_values = {}; >+ >+$display_values->{status} = { >+ ACCEPTED => gettext('Accepted'), >+ ASKED => gettext('Pending'), >+ AVAILABLE => gettext('Available'), >+ CHECKED => gettext('Checked'), >+ ORDERED => gettext('Ordered'), >+ REJECTED => gettext('Rejected'), >+}; >+ >+my $budgets = C4::Budgets::GetBudgets; >+foreach my $budget (@$budgets) { >+ my $budget_id = $budget->{budget_id}; >+ $display_values->{budgetid}->{$budget_id} = $budget->{budget_name}; >+} >+ >+my @categories = C4::Category->all; >+foreach my $category (@categories) { >+ my $code = $category->categorycode; >+ $display_values->{categorycode}->{$code} = $category->description; >+} >+ >+my $bsort1 = C4::Koha::GetAuthorisedValues('Bsort1'); >+foreach my $av (@$bsort1) { >+ my $value = $av->{authorised_value}; >+ $display_values->{sort1}->{$value} = $av->{lib}; >+} >+ >+my $bsort2 = C4::Koha::GetAuthorisedValues('Bsort2'); >+foreach my $av (@$bsort2) { >+ my $value = $av->{authorised_value}; >+ $display_values->{sort2}->{$value} = $av->{lib}; >+} >+ >+my $suggest = C4::Koha::GetAuthorisedValues('SUGGEST'); >+foreach my $av (@$suggest) { >+ my $value = $av->{authorised_value}; >+ $display_values->{reason}->{$value} = $av->{lib}; >+} >+ >+my $branches = C4::Branch::GetBranchesLoop('', 0); >+foreach my $branch (@$branches) { >+ my $branchcode = $branch->{branchcode}; >+ $display_values->{branchcode}->{$branchcode} = $branch->{branchname}; >+} >+ >+my @itemtypes = C4::ItemType->all; >+foreach my $itemtype (@itemtypes) { >+ my $itype = $itemtype->itemtype; >+ $display_values->{itemtype}->{$itype} = $itemtype->description; >+} >+ >+$template->param( >+ display_values => $display_values, >+); >+ >+output_html_with_http_headers $cgi, $cookie, $template->output; >+ >+sub get_select_expr { >+ my ($field, $groupby) = @_; >+ >+ my $select_expr = $field; >+ if ($groupby->{$field}) { >+ if ($groupby->{$field} eq 'year') { >+ $select_expr = "DATE_FORMAT($field, '%Y')"; >+ } elsif ($groupby->{$field} eq 'month') { >+ $select_expr = "DATE_FORMAT($field, '%Y-%m')"; >+ } elsif ($groupby->{$field} eq 'week') { >+ $select_expr = "DATE_FORMAT($field, '%x-%v')"; >+ } elsif ($groupby->{$field} eq 'dow') { >+ $select_expr = "DATE_FORMAT($field, '%w - %W')"; >+ } >+ } >+ >+ return $select_expr; >+} >+ >+sub calculate { >+ my ($line, $column, $groupby, $filters) = @_; >+ >+ my @valid_fields = (qw( >+ suggesteddate rejecteddate ordereddate publicationyear status budgetid >+ categorycode sort1 sort2 branchcode reason itemtype >+ )); >+ return unless (grep /^$line$/, @valid_fields); >+ return unless (grep /^$column$/, @valid_fields); >+ >+ my $dbh = C4::Context->dbh; >+ >+ # preparing calculation >+ my $linefield = get_select_expr($line, $groupby); >+ my $colfield = get_select_expr($column, $groupby); >+ my $query = qq| >+ SELECT $linefield AS linefield, $colfield AS columnfield, COUNT(*) >+ FROM suggestions >+ |; >+ >+ if (grep /^(categorycode|sort1|sort2)$/, ($line, $column, keys %$filters)) { >+ $query .= ' JOIN borrowers ON (suggestions.suggestedby = borrowers.borrowernumber) '; >+ } >+ >+ my @conditions; >+ my @bind_values; >+ >+ foreach my $filter (qw(suggesteddate rejecteddate ordereddate)) { >+ if ($filters->{"${filter}_from"}) { >+ push @conditions, "$filter >= ?"; >+ push @bind_values, format_date_in_iso($filters->{"${filter}_from"}); >+ } >+ if ($filters->{"${filter}_to"}) { >+ push @conditions, "$filter <= ?"; >+ push @bind_values, format_date_in_iso($filters->{"${filter}_to"}); >+ } >+ } >+ >+ foreach my $filter (qw(status categorycode sort1 sort2 branchcode reason itemtype)) { >+ if ($filters->{$filter}) { >+ push @conditions, "$filter = ?"; >+ push @bind_values, $filters->{$filter}; >+ } >+ } >+ >+ if ($filters->{publicationyear_from}) { >+ push @conditions, 'publicationyear >= ?'; >+ push @bind_values, $filters->{publicationyear_from}; >+ } >+ if ($filters->{publicationyear_to}) { >+ push @conditions, 'publicationyear <= ?'; >+ push @bind_values, $filters->{publicationyear_to}; >+ } >+ >+ if ($filters->{budgetid}) { >+ my @descendants; >+ if ($filters->{budgetid_children}) { >+ @descendants = C4::Budgets::GetBudgetDescendantsIds( >+ $filters->{budgetid}); >+ } >+ my $cond = 'budgetid IN (' >+ . join (',', ('?') x (@descendants + 1)) >+ . ')'; >+ push @conditions, $cond; >+ push @bind_values, $filters->{budgetid}, @descendants; >+ } >+ >+ if (@conditions) { >+ $query .= ' WHERE ' . join(' AND ', @conditions); >+ } >+ >+ $query .= " GROUP BY linefield, columnfield ORDER BY linefield, columnfield"; >+ my $sth = $dbh->prepare($query); >+ $sth->execute(@bind_values); >+ >+ my $table; >+ while ( my ( $row, $col, $value ) = $sth->fetchrow ) { >+ $col = "NULL" unless defined $col; >+ $row = "NULL" unless defined $row; >+ >+ if (not defined($table->{$row}->{$col})) { >+ $table->{$row}->{$col} = 0; >+ } >+ $table->{$row}->{$col} += $value; >+ } >+ >+ my (@rows, @cols); >+ foreach my $row (keys %$table) { >+ foreach my $col (keys %{ $table->{$row} }) { >+ push @cols, $col unless grep /^$col$/, @cols; >+ } >+ push @rows, $row unless grep /^$row$/, @rows; >+ } >+ @rows = sort @rows; >+ @cols = sort @cols; >+ >+ my $result = { >+ table => $table, >+ rows => \@rows, >+ cols => \@cols, >+ }; >+ return $result; >+} >diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t >index 11838c8..00e8fad 100755 >--- a/t/db_dependent/Budgets.t >+++ b/t/db_dependent/Budgets.t >@@ -1,5 +1,5 @@ > use Modern::Perl; >-use Test::More tests => 120; >+use Test::More tests => 124; > > BEGIN { > use_ok('C4::Budgets') >@@ -579,6 +579,16 @@ is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id}, > is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id}, > undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" ); > >+ >+my @descendants_ids = C4::Budgets::GetBudgetDescendantsIds($budget_id1); >+is_deeply(\@descendants_ids, [$budget_id11, $budget_id12, $budget_id111]); >+@descendants_ids = C4::Budgets::GetBudgetDescendantsIds($budget_id11); >+is_deeply(\@descendants_ids, [$budget_id111]); >+@descendants_ids = C4::Budgets::GetBudgetDescendantsIds($budget_id111); >+is_deeply(\@descendants_ids, []); >+@descendants_ids = C4::Budgets::GetBudgetDescendantsIds(undef); >+is_deeply(\@descendants_ids, []); >+ > sub _get_dependencies { > my ($budget_hierarchy) = @_; > my $graph; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13392
:
34124
|
34125
|
34135
|
34136
|
34328
|
34329
|
35835
|
35836
|
35837
|
36188
|
36189
|
36190
|
36343
|
36344
|
36345
|
40305
|
40306
|
40307
|
40308
|
48291
|
48292
|
48293
|
48294
|
49088
|
51995
|
51996
|
51997
|
51998
|
51999
|
56110
|
56889
|
60956
|
60957
|
60958
|
60959
|
60960
|
60961
|
60962
|
64459
|
64460
|
64461
|
64462
|
64463
|
64464
|
64465
|
78622
|
78623
|
78624
|
78625
|
78626
|
78627
|
78628
|
78629