View | Details | Raw Unified | Return to bug 13392
Collapse All | Expand All

(-)a/C4/Budgets.pm (+30 lines)
Lines 191-196 sub GetBudgetChildren { Link Here
191
    |, { Slice => {} }, $budget_id );
191
    |, { Slice => {} }, $budget_id );
192
}
192
}
193
193
194
sub GetBudgetDescendantsIds {
195
    my ($budget_id) = @_;
196
197
    return () unless $budget_id;
198
199
    my @descendants_ids;
200
201
    my $query = q|
202
        SELECT budget_id FROM aqbudgets WHERE budget_parent_id = ?
203
    |;
204
    my $dbh = C4::Context->dbh;
205
    my @children_ids = map {
206
        $_->{budget_id}
207
    } @{ $dbh->selectall_arrayref($query, {Slice => {}}, $budget_id) };
208
209
    while (@children_ids) {
210
        push @descendants_ids, @children_ids;
211
        $query = '
212
            SELECT budget_id
213
            FROM aqbudgets
214
            WHERE budget_parent_id IN (' . join(',', ('?') x @children_ids) . ')';
215
        @children_ids = map {
216
            $_->{budget_id}
217
        } @{ $dbh->selectall_arrayref($query, {Slice => {}}, @children_ids) };
218
    }
219
220
    return @descendants_ids;
221
}
222
223
194
sub SetOwnerToFundHierarchy {
224
sub SetOwnerToFundHierarchy {
195
    my ( $budget_id, $borrowernumber ) = @_;
225
    my ( $budget_id, $borrowernumber ) = @_;
196
226
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-menu.inc (+1 lines)
Lines 6-11 Link Here
6
<h5>Statistics wizards</h5>
6
<h5>Statistics wizards</h5>
7
	<ul>
7
	<ul>
8
		<li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
8
		<li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
9
    <li><a href="/cgi-bin/koha/reports/suggestions_stats.pl">Suggestions</a></li>
9
		<li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
10
		<li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
10
		<li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
11
		<li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
11
		<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
12
		<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports/fields.inc (+25 lines)
Line 0 Link Here
1
[% BLOCK field_label %]
2
  [% SWITCH name %]
3
    [% CASE 'suggesteddate' %]Suggest date
4
    [% CASE 'suggesteddate_from' %]Suggest date (from)
5
    [% CASE 'suggesteddate_to' %]Suggest date (to)
6
    [% CASE 'rejecteddate' %]Reject date
7
    [% CASE 'rejecteddate_from' %]Reject date (from)
8
    [% CASE 'rejecteddate_to' %]Reject date (to)
9
    [% CASE 'ordereddate' %]Order date
10
    [% CASE 'ordereddate_from' %]Order date (from)
11
    [% CASE 'ordereddate_to' %]Order date (to)
12
    [% CASE 'publicationyear' %]Publication year
13
    [% CASE 'publicationyear_from' %]Publication year (from)
14
    [% CASE 'publicationyear_to' %]Publication year (to)
15
    [% CASE 'status' %]Status
16
    [% CASE 'budgetid' %]Fund
17
    [% CASE 'budgetid_children' %]Include child funds
18
    [% CASE 'categorycode' %]Borrower category
19
    [% CASE 'sort1' %]Borrower sort field 1
20
    [% CASE 'sort2' %]Borrower sort field 2
21
    [% CASE 'branchcode' %]Branch
22
    [% CASE 'reason' %]Reject reason
23
    [% CASE 'itemtype' %]Item type
24
  [% END %]
25
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (+1 lines)
Lines 31-36 Link Here
31
        <h2>Statistics wizards</h2>
31
        <h2>Statistics wizards</h2>
32
        <ul>
32
        <ul>
33
            <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
33
            <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
34
            <li><a href="/cgi-bin/koha/reports/suggestions_stats.pl">Suggestions</a></li>
34
            <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
35
            <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
35
            <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
36
            <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
36
            <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
37
            <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats.tt (+186 lines)
Line 0 Link Here
1
[% PROCESS 'reports/fields.inc' %]
2
3
[% BLOCK tr %]
4
  <tr>
5
    <td>[% INCLUDE field_label name=name %]</td>
6
    <td><input type="radio" name="line" value="[% name %]" /></td>
7
    <td><input type="radio" name="column" value="[% name %]" /></td>
8
    <td>[% groupby %]</td>
9
    <td>[% filter %]</td>
10
  </tr>
11
[% END %]
12
13
[% BLOCK date_tr %]
14
  [% date_groupby = BLOCK %]
15
    <select name="groupby_[% name %]">
16
      <option value=""></option>
17
      <option value="year">Year</option>
18
      <option value="month">Month</option>
19
      <option value="week">Week</option>
20
      <option value="dow">Day of week</option>
21
    </select>
22
  [% END %]
23
24
  [% date_filter = BLOCK %]
25
    From
26
    <input type="text" size="10" id="filter_[% name %]_from"
27
      name="filter_[% name %]_from"/>
28
    <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
29
    To
30
    <input type="text" size="10" id="filter_[% name %]_to"
31
      name="filter_[% name %]_to"/>
32
    <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
33
  [% END %]
34
35
  [% INCLUDE tr groupby=date_groupby filter=date_filter %]
36
[% END %]
37
38
[% BLOCK select_tr %]
39
  [% select_filter = BLOCK %]
40
    <select name="filter_[% name %]">
41
      <option value=""></option>
42
      [% FOREACH value IN display_values.$name.keys.sort %]
43
        <option value="[% value %]">[% display_values.$name.$value %]</option>
44
      [% END %]
45
    </select>
46
  [% END %]
47
48
  [% INCLUDE tr filter=select_filter %]
49
[% END %]
50
51
[% INCLUDE 'doc-head-open.inc' %]
52
  <title>Koha &rsaquo; Reports &rsaquo; Suggestions statistics</title>
53
  [% INCLUDE 'doc-head-close.inc' %]
54
  [% INCLUDE 'calendar.inc' %]
55
  <script type="text/javascript">
56
    //<![CDATA[
57
58
    (function($) {
59
60
      var onDateSelect = function(selectedDate) {
61
        var option = this.id.match(/from$/) ? "minDate" : "maxDate",
62
            instance = $(this).data("datepicker"),
63
            dateFormat = instance.settings.dateFormat || $.datepicker._defaults.dateFormat;
64
        var sDate = $.datepicker.parseDate(dateFormat, selectedDate, instance.settings);
65
        var otherId = this.id.match(/from$/)
66
          ? this.id.replace(/from$/, 'to')
67
          : this.id.replace(/to$/, 'from');
68
        $('#' + otherId).datepicker("option", option, sDate);
69
      };
70
71
      $(document).ready(function() {
72
        var datesSelectors = [
73
          '#filter_suggesteddate_from',
74
          '#filter_suggesteddate_to',
75
          '#filter_rejecteddate_from',
76
          '#filter_rejecteddate_to',
77
          '#filter_ordereddate_from',
78
          '#filter_ordereddate_to',
79
        ]
80
        $(datesSelectors.join(','))
81
          .datepicker({
82
            changeMonth: true,
83
            numberOfMonths: 1,
84
            onSelect: onDateSelect
85
          });
86
      });
87
88
    })(jQuery);
89
90
    //]]>
91
  </script>
92
</head>
93
94
<body id="rep_suggestions_stats" class="rep">
95
  [% INCLUDE 'header.inc' %]
96
  [% INCLUDE 'cat-search.inc' %]
97
98
  <div id="breadcrumbs">
99
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
100
    &rsaquo;
101
    <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
102
    &rsaquo;
103
    Suggestions statistics
104
  </div>
105
106
  <div id="doc3" class="yui-t2">
107
    <div id="bd">
108
      <div id="yui-main">
109
        <div class="yui-b">
110
111
          <form method="post" action="/cgi-bin/koha/reports/suggestions_stats.pl">
112
            <fieldset class="rows">
113
              <legend>Acquisitions statistics</legend>
114
              <table>
115
                <thead>
116
                  <tr>
117
                    <th>Title</th>
118
                    <th>Row</th>
119
                    <th>Column</th>
120
                    <th>Group by</th>
121
                    <th>Filter</th>
122
                  </tr>
123
                </thead>
124
                <tbody>
125
                  [% INCLUDE date_tr name='suggesteddate' %]
126
                  [% INCLUDE date_tr name='rejecteddate' %]
127
                  [% INCLUDE date_tr name='ordereddate' %]
128
129
                  [% publicationyear_filter = BLOCK %]
130
                    From
131
                    <input type="text" size="4" name="filter_publicationyear_from"/>
132
                    To
133
                    <input type="text" size="4" name="filter_publicationyear_to"/>
134
                  [% END %]
135
                  [% INCLUDE tr name='publicationyear' filter=publicationyear_filter %]
136
137
                  [% INCLUDE select_tr name='status' %]
138
                  [% INCLUDE select_tr name='categorycode' %]
139
                  [% INCLUDE select_tr name='sort1' %]
140
                  [% INCLUDE select_tr name='sort2' %]
141
                  [% INCLUDE select_tr name='branchcode' %]
142
                  [% INCLUDE select_tr name='reason' %]
143
                  [% INCLUDE select_tr name='itemtype' %]
144
145
                  [%# Recursive block that display budgets in a hierarchy %]
146
                  [% BLOCK budget_option %]
147
                    [% indent = indent || 0 %]
148
                    <option value="[% budget.budget_id %]">
149
                      [% '--' |repeat(indent) %]
150
                      [% budget.budget_name %]
151
                    </option>
152
                    [% FOREACH child IN budget.children %]
153
                      [% INCLUDE budget_option budget=child indent=indent+1 %]
154
                    [% END %]
155
                  [% END %]
156
157
                  [% budgetid_filter = BLOCK %]
158
                    <select name="filter_budgetid">
159
                      <option value=""></option>
160
                      [% FOREACH budget IN budget_hierarchy %]
161
                        [% INCLUDE budget_option budget=budget %]
162
                      [% END %]
163
                    </select>
164
                    <input type="checkbox" name="filter_budgetid_children" id="filter_budgetid_children" value="1">
165
                    <label for="filter_budgetid_children">Include child funds</label>
166
                  [% END %]
167
                  [% INCLUDE tr name='budgetid' filter=budgetid_filter %]
168
                </tbody>
169
              </table>
170
            </fieldset>
171
172
            <fieldset class="action">
173
              <input type="submit" value="Submit" />
174
            </fieldset>
175
          </form>
176
177
        </div>
178
      </div>
179
180
      <div class="yui-b">
181
        [% INCLUDE 'reports-menu.inc' %]
182
      </div>
183
    </div>
184
  </div>
185
186
  [% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/suggestions_stats_results.tt (+83 lines)
Line 0 Link Here
1
[% PROCESS 'reports/fields.inc' %]
2
3
[% INCLUDE 'doc-head-open.inc' %]
4
  <title>Koha &rsaquo; Reports &rsaquo; Acquisitions statistics results</title>
5
  [% INCLUDE 'doc-head-close.inc' %]
6
  [% INCLUDE 'calendar.inc' %]
7
</head>
8
9
<body id="rep_suggestions_stats" class="rep">
10
  [% INCLUDE 'header.inc' %]
11
  [% INCLUDE 'cat-search.inc' %]
12
13
  <div id="breadcrumbs">
14
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
15
    &rsaquo;
16
    <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
17
    &rsaquo;
18
    Suggestions statistics
19
  </div>
20
21
  <div id="doc3" class="yui-t2">
22
23
    <div id="bd">
24
      <div id="yui-main">
25
        <div class="yui-b">
26
27
          <h1>Acquisitions statistics </h1>
28
          [% IF filters.keys.size %]
29
            <p><b>Filtered on:</b></p>
30
            <ul>
31
              [% FOREACH filter IN filters.keys %]
32
                <li>
33
                  [% INCLUDE field_label name=filter %] :
34
                  [% value = filters.$filter %]
35
                  [% display_values.$filter.$value || value %]
36
                </li>
37
              [% END %]
38
            </ul>
39
          [% END %]
40
41
          [% totalcols = {} %]
42
          [% total = 0 %]
43
          <table>
44
            <tr>
45
              <th>[% INCLUDE field_label name=line %] / [% INCLUDE field_label name=column %]</th>
46
              [% FOREACH col IN result.cols %]
47
                <th>[% display_values.$column.$col || col %]</th>
48
                [% totalcols.$col = 0 %]
49
              [% END %]
50
              <th>TOTAL</th>
51
            </tr>
52
            [% FOREACH row IN result.rows %]
53
              [% totalrow = 0 %]
54
              <tr>
55
                <td>[% display_values.$line.$row || row %]</td>
56
                [% FOREACH col IN result.cols %]
57
                  [% value = result.table.item(row).item(col) || 0 %]
58
                  <td>[% value %]</td>
59
60
                  [%# Update totals %]
61
                  [% totalrow = totalrow + value %]
62
                  [% totalcols.$col = totalcols.$col + value %]
63
                  [% total = total + value %]
64
                [% END %]
65
                <td>[% totalrow %]</td>
66
              </tr>
67
            [% END %]
68
            <tr>
69
              <th>TOTAL</th>
70
              [% FOREACH col IN result.cols %]
71
                <th>[% totalcols.$col %]</th>
72
              [% END %]
73
              <th>[% total %]</th>
74
            </tr>
75
          </table>
76
        </div>
77
      </div>
78
79
      <div class="yui-b">
80
        [% INCLUDE 'reports-menu.inc' %]
81
      </div>
82
83
  [% INCLUDE 'intranet-bottom.inc' %]
(-)a/reports/suggestions_stats.pl (+268 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI;
22
23
use C4::Auth;
24
use C4::Context;
25
use C4::Output;
26
27
use C4::Branch;
28
use C4::Budgets;
29
use C4::Category;
30
use C4::Dates qw/format_date format_date_in_iso/;
31
use C4::ItemType;
32
use C4::Koha;
33
use C4::Reports;
34
35
use Koha::I18N;
36
37
my $cgi = new CGI;
38
my $template_name = 'reports/suggestions_stats.tt';
39
my $line = $cgi->param("line");
40
my $column = $cgi->param("column");
41
42
if ($line and $column) {
43
    $template_name = 'reports/suggestions_stats_results.tt';
44
}
45
46
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
47
    {
48
        template_name   => $template_name,
49
        query           => $cgi,
50
        type            => 'intranet',
51
        authnotrequired => 0,
52
        flagsrequired   => { reports => '*' },
53
    }
54
);
55
56
if ($line and $column) {
57
    my ($filters, $groupby) = ({}, {});
58
    foreach my $param ($cgi->param()) {
59
        my $value = $cgi->param($param);
60
        if ( (defined $value) && ($value ne '') ) {
61
            if ($param =~ /^filter_(.*)/) {
62
                $filters->{$1} = $cgi->param($param);
63
            } elsif ($param =~ /^groupby_(.*)/) {
64
                $groupby->{$1} = $cgi->param($param);
65
            }
66
        }
67
    }
68
69
    my $result = calculate($line, $column, $groupby, $filters);
70
71
    $template->param(
72
        line => $line,
73
        column => $column,
74
        filters => $filters,
75
        result => $result,
76
    );
77
} else {
78
    my $budget_hierarchy = C4::Budgets::GetBudgetHierarchy;
79
80
    # Remove all children from the first level of this array.
81
    @$budget_hierarchy = grep {
82
        not defined $_->{budget_parent_id}
83
    } @$budget_hierarchy;
84
85
    $template->param( budget_hierarchy => $budget_hierarchy);
86
}
87
88
my $display_values = {};
89
90
$display_values->{status} = {
91
    ACCEPTED => gettext('Accepted'),
92
    ASKED => gettext('Pending'),
93
    AVAILABLE => gettext('Available'),
94
    CHECKED => gettext('Checked'),
95
    ORDERED => gettext('Ordered'),
96
    REJECTED => gettext('Rejected'),
97
};
98
99
my $budgets = C4::Budgets::GetBudgets;
100
foreach my $budget (@$budgets) {
101
    my $budget_id = $budget->{budget_id};
102
    $display_values->{budgetid}->{$budget_id} = $budget->{budget_name};
103
}
104
105
my @categories = C4::Category->all;
106
foreach my $category (@categories) {
107
    my $code = $category->categorycode;
108
    $display_values->{categorycode}->{$code} = $category->description;
109
}
110
111
my $bsort1 = C4::Koha::GetAuthorisedValues('Bsort1');
112
foreach my $av (@$bsort1) {
113
    my $value = $av->{authorised_value};
114
    $display_values->{sort1}->{$value} = $av->{lib};
115
}
116
117
my $bsort2 = C4::Koha::GetAuthorisedValues('Bsort2');
118
foreach my $av (@$bsort2) {
119
    my $value = $av->{authorised_value};
120
    $display_values->{sort2}->{$value} = $av->{lib};
121
}
122
123
my $suggest = C4::Koha::GetAuthorisedValues('SUGGEST');
124
foreach my $av (@$suggest) {
125
    my $value = $av->{authorised_value};
126
    $display_values->{reason}->{$value} = $av->{lib};
127
}
128
129
my $branches = C4::Branch::GetBranchesLoop('', 0);
130
foreach my $branch (@$branches) {
131
    my $branchcode = $branch->{branchcode};
132
    $display_values->{branchcode}->{$branchcode} = $branch->{branchname};
133
}
134
135
my @itemtypes = C4::ItemType->all;
136
foreach my $itemtype (@itemtypes) {
137
    my $itype = $itemtype->itemtype;
138
    $display_values->{itemtype}->{$itype} = $itemtype->description;
139
}
140
141
$template->param(
142
    display_values => $display_values,
143
);
144
145
output_html_with_http_headers $cgi, $cookie, $template->output;
146
147
sub get_select_expr {
148
    my ($field, $groupby) = @_;
149
150
    my $select_expr = $field;
151
    if ($groupby->{$field}) {
152
        if ($groupby->{$field} eq 'year') {
153
            $select_expr = "DATE_FORMAT($field, '%Y')";
154
        } elsif ($groupby->{$field} eq 'month') {
155
            $select_expr = "DATE_FORMAT($field, '%Y-%m')";
156
        } elsif ($groupby->{$field} eq 'week') {
157
            $select_expr = "DATE_FORMAT($field, '%x-%v')";
158
        } elsif ($groupby->{$field} eq 'dow') {
159
            $select_expr = "DATE_FORMAT($field, '%w - %W')";
160
        }
161
    }
162
163
    return $select_expr;
164
}
165
166
sub calculate {
167
    my ($line, $column, $groupby, $filters) = @_;
168
169
    my @valid_fields = (qw(
170
        suggesteddate rejecteddate ordereddate publicationyear status budgetid
171
        categorycode sort1 sort2 branchcode reason itemtype
172
    ));
173
    return unless (grep /^$line$/, @valid_fields);
174
    return unless (grep /^$column$/, @valid_fields);
175
176
    my $dbh = C4::Context->dbh;
177
178
    # preparing calculation
179
    my $linefield = get_select_expr($line, $groupby);
180
    my $colfield = get_select_expr($column, $groupby);
181
    my $query = qq|
182
        SELECT $linefield AS linefield, $colfield AS columnfield, COUNT(*)
183
        FROM suggestions
184
    |;
185
186
    if (grep /^(categorycode|sort1|sort2)$/, ($line, $column, keys %$filters)) {
187
        $query .= ' JOIN borrowers ON (suggestions.suggestedby = borrowers.borrowernumber) ';
188
    }
189
190
    my @conditions;
191
    my @bind_values;
192
193
    foreach my $filter (qw(suggesteddate rejecteddate ordereddate)) {
194
        if ($filters->{"${filter}_from"}) {
195
            push @conditions, "$filter >= ?";
196
            push @bind_values, format_date_in_iso($filters->{"${filter}_from"});
197
        }
198
        if ($filters->{"${filter}_to"}) {
199
            push @conditions, "$filter <= ?";
200
            push @bind_values, format_date_in_iso($filters->{"${filter}_to"});
201
        }
202
    }
203
204
    foreach my $filter (qw(status categorycode sort1 sort2 branchcode reason itemtype)) {
205
        if ($filters->{$filter}) {
206
            push @conditions, "$filter = ?";
207
            push @bind_values, $filters->{$filter};
208
        }
209
    }
210
211
    if ($filters->{publicationyear_from}) {
212
        push @conditions, 'publicationyear >= ?';
213
        push @bind_values, $filters->{publicationyear_from};
214
    }
215
    if ($filters->{publicationyear_to}) {
216
        push @conditions, 'publicationyear <= ?';
217
        push @bind_values, $filters->{publicationyear_to};
218
    }
219
220
    if ($filters->{budgetid}) {
221
        my @descendants;
222
        if ($filters->{budgetid_children}) {
223
            @descendants = C4::Budgets::GetBudgetDescendantsIds(
224
                $filters->{budgetid});
225
        }
226
        my $cond = 'budgetid IN ('
227
            . join (',', ('?') x (@descendants + 1))
228
            . ')';
229
        push @conditions, $cond;
230
        push @bind_values, $filters->{budgetid}, @descendants;
231
    }
232
233
    if (@conditions) {
234
        $query .= ' WHERE ' . join(' AND ', @conditions);
235
    }
236
237
    $query .= " GROUP BY linefield, columnfield ORDER BY linefield, columnfield";
238
    my $sth = $dbh->prepare($query);
239
    $sth->execute(@bind_values);
240
241
    my $table;
242
    while ( my ( $row, $col, $value ) = $sth->fetchrow ) {
243
        $col = "NULL" unless defined $col;
244
        $row = "NULL" unless defined $row;
245
246
        if (not defined($table->{$row}->{$col})) {
247
            $table->{$row}->{$col} = 0;
248
        }
249
        $table->{$row}->{$col} += $value;
250
    }
251
252
    my (@rows, @cols);
253
    foreach my $row (keys %$table) {
254
        foreach my $col (keys %{ $table->{$row} }) {
255
            push @cols, $col unless grep /^$col$/, @cols;
256
        }
257
        push @rows, $row unless grep /^$row$/, @rows;
258
    }
259
    @rows = sort @rows;
260
    @cols = sort @cols;
261
262
    my $result = {
263
        table => $table,
264
        rows => \@rows,
265
        cols => \@cols,
266
    };
267
    return $result;
268
}
(-)a/t/db_dependent/Budgets.t (-2 / +12 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
use Modern::Perl;
2
use Modern::Perl;
3
use Test::More tests => 142;
3
use Test::More tests => 146;
4
4
5
BEGIN {
5
BEGIN {
6
    use_ok('C4::Budgets')
6
    use_ok('C4::Budgets')
Lines 632-637 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id}, Link Here
632
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
632
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
633
    undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
633
    undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
634
634
635
my @descendants_ids = C4::Budgets::GetBudgetDescendantsIds($budget_id1);
636
is_deeply(\@descendants_ids, [$budget_id12, $budget_id11, $budget_id111]);
637
@descendants_ids = C4::Budgets::GetBudgetDescendantsIds($budget_id11);
638
is_deeply(\@descendants_ids, [$budget_id111]);
639
@descendants_ids = C4::Budgets::GetBudgetDescendantsIds($budget_id111);
640
is_deeply(\@descendants_ids, []);
641
@descendants_ids = C4::Budgets::GetBudgetDescendantsIds(undef);
642
is_deeply(\@descendants_ids, []);
643
635
# Test GetBudgetAuthCats
644
# Test GetBudgetAuthCats
636
645
637
my $budgetPeriodId = AddBudgetPeriod({
646
my $budgetPeriodId = AddBudgetPeriod({
Lines 699-704 is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting cat Link Here
699
708
700
# /Test GetBudgetAuthCats
709
# /Test GetBudgetAuthCats
701
710
711
$schema->storage->txn_rollback();
712
702
sub _get_dependencies {
713
sub _get_dependencies {
703
    my ($budget_hierarchy) = @_;
714
    my ($budget_hierarchy) = @_;
704
    my $graph;
715
    my $graph;
705
- 

Return to bug 13392