X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=reports%2Fissues_stats.pl;h=2f8a7e359f011c9355f75a48147e2d1fa73e7c97;hb=ae48ebbcaae50a0af7ceca00d04f2aedb8d5cc2c;hp=61b9ce76fef1988b34be9c3d07855cdb0af1a3c2;hpb=e37381f44434e6a5504ab880e8c5dd0b00babb30;p=koha.git diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl index 61b9ce76fe..2f8a7e359f 100755 --- a/reports/issues_stats.pl +++ b/reports/issues_stats.pl @@ -14,24 +14,30 @@ # 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., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# 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 strict; -use C4::Auth; +#use warnings; FIXME - Bug 2505 + use CGI; +use Date::Manip; + +use C4::Auth; +use C4::Debug; use C4::Context; use C4::Branch; # GetBranches use C4::Koha; use C4::Output; use C4::Circulation; +use C4::Reports; use C4::Dates qw/format_date format_date_in_iso/; -use Date::Manip; +use C4::Members; =head1 NAME -plugin that shows a stats on borrowers +plugin that shows circulation stats =head1 DESCRIPTION @@ -39,533 +45,483 @@ plugin that shows a stats on borrowers =cut +# my $debug = 1; # override for now. my $input = new CGI; -my $do_it=$input->param('do_it'); my $fullreportname = "reports/issues_stats.tmpl"; -my $line = $input->param("Line"); -my $column = $input->param("Column"); -my @filters = $input->param("Filter"); +my $do_it = $input->param('do_it'); +my $line = $input->param("Line"); +my $column = $input->param("Column"); +my @filters = $input->param("Filter"); $filters[0]=format_date_in_iso($filters[0]); $filters[1]=format_date_in_iso($filters[1]); -my $podsp = $input->param("DisplayBy"); -my $type = $input->param("PeriodTypeSel"); -my $daysel = $input->param("PeriodDaySel"); +my $podsp = $input->param("DisplayBy"); +my $type = $input->param("PeriodTypeSel"); +my $daysel = $input->param("PeriodDaySel"); my $monthsel = $input->param("PeriodMonthSel"); -my $calc = $input->param("Cellvalue"); -my $output = $input->param("output"); +my $calc = $input->param("Cellvalue"); +my $output = $input->param("output"); my $basename = $input->param("basename"); -my $mime = $input->param("MIME"); -my $del = $input->param("sep"); -#warn "calcul : ".$calc; -my ($template, $borrowernumber, $cookie) - = get_template_and_user({template_name => $fullreportname, - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {reports => 1}, - debug => 1, - }); +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"); +$sep = "\t" if ($sep eq 'tabulation'); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), - ); + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), +); + +my $itemtypes = GetItemTypes(); +my $categoryloop = GetBorrowercategoryList; + +my $ccodes = GetKohaAuthorisedValues("items.ccode"); +my $locations = GetKohaAuthorisedValues("items.location"); + +my $Bsort1 = GetAuthorisedValues("Bsort1"); +my $Bsort2 = GetAuthorisedValues("Bsort2"); +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"){ + 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; - exit(1); - } else { + $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}; - my $sep; - $sep =C4::Context->preference("delimiter"); + my $cols = @$results[0]->{loopcol}; + my $lines = @$results[0]->{looprow}; # header top-right - print @$results[0]->{line} ."/". @$results[0]->{column} .$sep; + print @$results[0]->{line} ."/". @$results[0]->{column} .$sep; # Other header - foreach my $col ( @$cols ) { - print $col->{coltitle}.$sep; - } - print "Total\n"; + foreach my $col ( @$cols ) { + print $col->{coltitle}.$sep; + } + print "Total\n"; # Table - foreach my $line ( @$lines ) { - my $x = $line->{loopcell}; - print $line->{rowtitle}.$sep; - foreach my $cell (@$x) { - print $cell->{value}.$sep; - } - print $line->{totalrow}; - print "\n"; - } + 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}; - foreach my $col ( @$cols ) { - print $sep.$col->{totalcol}; - } + print map {$sep.$_->{totalcol}} @$cols; print $sep.@$results[0]->{total}; - exit(1); - } -# Displaying choices -} else { - my $dbh = C4::Context->dbh; - my @values; - my %labels; - my %select; - my $req; - $req = $dbh->prepare("select distinctrow categorycode,description from categories order by description"); - $req->execute; - my @select; - push @select,""; - $select{""}=""; - while (my ($value, $desc) =$req->fetchrow) { - push @select, $value; - $select{$value}=$desc; - } - my $CGIBorCat=CGI::scrolling_list( -name => 'Filter', - -id => 'borcat', - -values => \@select, - -labels => \%select, - -size => 1, - -multiple => 0 ); - - $req = $dbh->prepare( "select distinctrow itemtype,description from itemtypes order by description"); - $req->execute; - undef @select; - undef %select; - push @select,""; - $select{""}=""; - while (my ($value,$desc) =$req->fetchrow) { - push @select, $value; - $select{$value}=$desc; - } - my $CGIItemTypes=CGI::scrolling_list( -name => 'Filter', - -id => 'itemtype', - -values => \@select, - -labels => \%select, - -size => 1, - -multiple => 0 ); - - $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1"); - $req->execute; - undef @select; - push @select,""; - my $hassort1; - while (my ($value) =$req->fetchrow) { - $hassort1 =1 if ($value); - push @select, $value; - } - my $branches=GetBranches(); - my @select_branch; - my %select_branches; - push @select_branch,""; - $select_branches{""} = ""; - foreach my $branch (keys %$branches) { - push @select_branch, $branch; - $select_branches{$branch} = $branches->{$branch}->{'branchname'}; - } - my $CGIBranch=CGI::scrolling_list( -name => 'Filter', - -id => 'branch', - -values => \@select_branch, - -labels => \%select_branches, - -size => 1, - -multiple => 0 ); - - my $CGISort1=CGI::scrolling_list( -name => 'Filter', - -id => 'sort1', - -values => \@select, - -size => 1, - -multiple => 0 ); - - $req = $dbh->prepare("select distinctrow sort2 from borrowers where sort2 is not null order by sort2"); - $req->execute; - undef @select; - push @select,""; - my $hassort2; - my $hglghtsort2; - while (my ($value) =$req->fetchrow) { - $hassort2 =1 if ($value); - $hglghtsort2= !($hassort1); - push @select, $value; - } - my $CGISort2=CGI::scrolling_list( -name => 'Filter', - -id => 'sort2', - -values => \@select, - -size => 1, - -multiple => 0 ); - # location list - $req = $dbh->prepare("select distinctrow location from items order by location"); - $req->execute; - undef @select; - push @select,""; - while (my ($value) =$req->fetchrow) { - push @select, $value; - } - my $CGIlocation=CGI::scrolling_list( -name => 'Filter', - -id => 'location', - -values => \@select, - -size => 1, - -multiple => 0 ); - # various - my @mime = ( C4::Context->preference("MIME") ); - - my $CGIextChoice=CGI::scrolling_list( - -name => 'MIME', - -id => 'MIME', - -values => \@mime, - -size => 1, - -multiple => 0 ); - - my @dels = ( C4::Context->preference("delimiter") ); - my $CGIsepChoice=CGI::scrolling_list( - -name => 'sep', - -id => 'sep', - -values => \@dels, - -size => 1, - -multiple => 0 ); - - $template->param( - CGIBorCat => $CGIBorCat, - CGIItemType => $CGIItemTypes, - CGIBranch => $CGIBranch, - hassort1=> $hassort1, - hassort2=> $hassort2, - HlghtSort2 => $hglghtsort2, - CGISort1 => $CGISort1, - CGISort2 => $CGISort2, - CGIextChoice => $CGIextChoice, - CGIsepChoice => $CGIsepChoice, - CGILocation => $CGIlocation, - ); - output_html_with_http_headers $input, $cookie, $template->output; + } + exit(1); # exit either way after $do_it } +my $dbh = C4::Context->dbh; +my @values; +my %labels; +my %select; +# create itemtype arrayref for