From 072e9f8a7c38d3ea0bc3fc8cacc791c2f1f57f98 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 10 Oct 2016 14:36:59 +0200 Subject: [PATCH] Bug 13392: Remove use of C4::Branch and C4::Category + fix a 'ambiguous column name' error when using borrowers table Signed-off-by: Josef Moravec --- reports/suggestions_stats.pl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/reports/suggestions_stats.pl b/reports/suggestions_stats.pl index 10a5305bb1..75e671da98 100755 --- a/reports/suggestions_stats.pl +++ b/reports/suggestions_stats.pl @@ -24,14 +24,13 @@ use C4::Auth; use C4::Context; use C4::Output; -use C4::Branch; use C4::Budgets; -use C4::Category; use Koha::DateUtils qw/output_pref dt_from_string/; use C4::Koha; use C4::Reports; -use Koha::I18N; +use Koha::Libraries; +use Koha::Patron::Categories; my $cgi = new CGI; my $template_name = 'reports/suggestions_stats.tt'; @@ -92,7 +91,7 @@ foreach my $budget (@$budgets) { $display_values->{budgetid}->{$budget_id} = $budget->{budget_name}; } -my @categories = C4::Category->all; +my @categories = Koha::Patron::Categories->search( {}, {order_by => ['description']} ); foreach my $category (@categories) { my $code = $category->categorycode; $display_values->{categorycode}->{$code} = $category->description; @@ -116,7 +115,7 @@ foreach my $av (@$suggest) { $display_values->{reason}->{$value} = $av->{lib}; } -my $branches = C4::Branch::GetBranchesLoop('', 0); +my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; foreach my $branch (@$branches) { my $branchcode = $branch->{branchcode}; $display_values->{branchcode}->{$branchcode} = $branch->{branchname}; @@ -137,6 +136,11 @@ output_html_with_http_headers $cgi, $cookie, $template->output; sub get_select_expr { my ($field, $groupby) = @_; + # To avoid 'ambiguous column name' error when using borrowers table + if ($field eq 'branchcode') { + $field = 'suggestions.branchcode'; + } + my $select_expr = $field; if ($groupby->{$field}) { if ($groupby->{$field} eq 'year') { @@ -197,7 +201,14 @@ sub calculate { foreach my $filter (qw(status categorycode sort1 sort2 branchcode reason itemtype)) { if ($filters->{$filter}) { - push @conditions, "$filter = ?"; + my $column = $filter; + + # To avoid 'ambiguous column name' error when using borrowers table + if ($column eq 'branchcode') { + $column = 'suggestions.branchcode'; + } + + push @conditions, "$column = ?"; push @bind_values, $filters->{$filter}; } } -- 2.17.1