X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=reports%2Fissues_stats.pl;h=3eb27fb3e27e727b901613086b4700927d262787;hb=f2253158d795fb2fe47061d6235d3ff773eeed5c;hp=648efe11fe2d1a2667b9b8e3737ff0b72db1f5a0;hpb=baf78b2a332aa5416f7cbf2020609aa753debda2;p=srvgit diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl index 648efe11fe..3eb27fb3e2 100755 --- a/reports/issues_stats.pl +++ b/reports/issues_stats.pl @@ -17,23 +17,20 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); -use Date::Manip; -use C4::Auth; -use C4::Debug; +use C4::Auth qw( get_template_and_user ); use C4::Context; -use C4::Koha; -use C4::Output; -use C4::Circulation; -use C4::Reports; -use C4::Members; +use C4::Koha qw( GetAuthorisedValues ); +use C4::Output qw( output_html_with_http_headers ); +use C4::Reports qw( GetDelimiterChoices ); use Koha::AuthorisedValues; -use Koha::DateUtils; +use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::ItemTypes; +use Koha::Patron::Attribute::Types; =head1 NAME @@ -45,7 +42,6 @@ Plugin that shows circulation stats =cut -# my $debug = 1; # override for now. my $input = CGI->new; my $fullreportname = "reports/issues_stats.tt"; my $do_it = $input->param('do_it'); @@ -63,24 +59,33 @@ my $monthsel = $input->param("PeriodMonthSel"); my $calc = $input->param("Cellvalue"); my $output = $input->param("output"); my $basename = $input->param("basename"); + +my $attribute_filters; +my $vars = $input->Vars; +foreach(keys %$vars) { + if(/^Filter_borrower_attributes\.(.*)/) { + $attribute_filters->{$1} = $vars->{$_}; + } +} + + my ($template, $borrowernumber, $cookie) = get_template_and_user({ template_name => $fullreportname, query => $input, type => "intranet", - authnotrequired => 0, flagsrequired => {reports => '*'}, - debug => 0, }); -our $sep = $input->param("sep") // ''; +our $sep = $input->param("sep") // ';'; $sep = "\t" if ($sep eq 'tabulation'); $template->param(do_it => $do_it, ); -our $itemtypes = GetItemTypes(); -our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); +our $itemtypes = Koha::ItemTypes->search_with_localization->unblessed; + +our @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); -my $locations = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; -my $ccodes = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; +our $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; +our $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; our $Bsort1 = GetAuthorisedValues("Bsort1"); our $Bsort2 = GetAuthorisedValues("Bsort2"); @@ -88,55 +93,54 @@ my ($hassort1,$hassort2); $hassort1=1 if $Bsort1; $hassort2=1 if $Bsort2; - if ($do_it) { -# Displaying results - my $results = calculate($line, $column, $podsp, $type, $daysel, $monthsel, $calc, \@filters); - if ($output eq "screen"){ -# Printing results to screen - $template->param(mainloop => $results); - output_html_with_http_headers $input, $cookie, $template->output; - } else { -# Printing to a csv file - print $input->header(-type => 'application/vnd.sun.xml.calc', - -encoding => 'utf-8', - -attachment=>"$basename.csv", - -filename=>"$basename.csv" ); - my $cols = @$results[0]->{loopcol}; - my $lines = @$results[0]->{looprow}; -# header top-right - print @$results[0]->{line} ."/". @$results[0]->{column} .$sep; -# Other header - foreach my $col ( @$cols ) { - print $col->{coltitle}.$sep; - } - print "Total\n"; -# Table - foreach my $line ( @$lines ) { - my $x = $line->{loopcell}; - print $line->{rowtitle}.$sep; - print map {$_->{value}.$sep} @$x; - print $line->{totalrow}, "\n"; - } -# footer + # Displaying results + my $results = calculate( $line, $column, $podsp, $type, $daysel, $monthsel, $calc, \@filters, $attribute_filters); + if ( $output eq "screen" ) { + + # Printing results to screen + $template->param( mainloop => $results ); + output_html_with_http_headers $input, $cookie, $template->output; + } else { + + # Printing to a csv file + print $input->header( + -type => 'application/vnd.sun.xml.calc', + -encoding => 'utf-8', + -attachment => "$basename.csv", + -filename => "$basename.csv" + ); + my $cols = @$results[0]->{loopcol}; + my $lines = @$results[0]->{looprow}; + + # header top-right + print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep; + + # Other header + foreach my $col (@$cols) { + print $col->{coltitle} . $sep; + } + print "Total\n"; + + # Table + foreach my $line (@$lines) { + my $x = $line->{loopcell}; + print $line->{rowtitle} . $sep; + print map { $_->{value} . $sep } @$x; + print $line->{totalrow}, "\n"; + } + + # footer print "TOTAL"; $cols = @$results[0]->{loopfooter}; - print map {$sep.$_->{totalcol}} @$cols; + print map {$sep.$_->{totalcol}} @$cols; print $sep.@$results[0]->{total}; - } - exit; # exit either way after $do_it + } + exit; } + my $dbh = C4::Context->dbh; -my @values; -my %labels; -my %select; - -# create itemtype arrayref for