From 63dd9232e85fa6009242b33ffd11e4c9e1e20798 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Tue, 4 Dec 2007 17:40:47 -0600 Subject: [PATCH] reports subdir - Dates.pm integration and warnings fixes. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- reports/acquisitions_stats.pl | 17 +++------- reports/bor_issues_top.pl | 62 +++++++++++++++++------------------ reports/borrowers_out.pl | 16 +++------ reports/borrowers_stats.pl | 4 +-- reports/cat_issues_top.pl | 4 +-- reports/catalogue_out.pl | 13 +++----- reports/catalogue_stats.pl | 8 ++--- reports/inventory.pl | 11 +++---- reports/issues_avg_stats.pl | 7 ++-- reports/issues_stats.pl | 4 +-- reports/manager.pl | 2 +- reports/reservereport.pl | 2 +- reports/stats.screen.pl | 8 ++--- 13 files changed, 68 insertions(+), 90 deletions(-) diff --git a/reports/acquisitions_stats.pl b/reports/acquisitions_stats.pl index 8955126626..e135ec0e9a 100755 --- a/reports/acquisitions_stats.pl +++ b/reports/acquisitions_stats.pl @@ -28,7 +28,7 @@ use C4::Context; use C4::Output; use C4::Koha; use C4::Circulation; -use C4::Date; +use C4::Dates; =head1 NAME @@ -69,19 +69,15 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); if ($do_it) { - - #warn -"line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n"; - + # warn "line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n"; my $results = calculate( $line, $column, $podsp, $rodsp, $aodsp, $calc, \@filters ); if ( $output eq "screen" ) { $template->param( mainloop => $results ); output_html_with_http_headers $input, $cookie, $template->output; - exit(1); } else { print $input->header( @@ -114,8 +110,8 @@ if ($do_it) { print $sep. $col->{totalcol}; } print $sep. @$results[0]->{total}; - exit(1); } + exit(1); } else { my $dbh = C4::Context->dbh; @@ -123,9 +119,7 @@ else { my %labels; my %select; my $req; - $req = - $dbh->prepare( - "SELECT distinctrow id,name FROM aqbooksellers ORDER BY name"); + $req = $dbh->prepare("SELECT distinctrow id,name FROM aqbooksellers ORDER BY name"); $req->execute; my @select; push @select, ""; @@ -236,7 +230,6 @@ else { my @mime = ( C4::Context->preference("MIME") ); foreach my $mime (@mime) { - # warn "".$mime; } diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl index 06e41c7a12..da38ba4e73 100755 --- a/reports/bor_issues_top.pl +++ b/reports/bor_issues_top.pl @@ -27,7 +27,7 @@ use C4::Branch; # GetBranches use C4::Koha; use C4::Circulation; use C4::Members; -use C4::Date; +use C4::Dates qw(format_date_in_iso); =head1 NAME @@ -40,19 +40,18 @@ plugin that shows a stats on borrowers =cut my $input = new CGI; -my $do_it=$input->param('do_it'); my $fullreportname = "reports/bor_issues_top.tmpl"; -my $limit = $input->param("Limit"); -my $column = $input->param("Criteria"); +my $do_it = $input->param('do_it'); +my $limit = $input->param("Limit"); +my $column = $input->param("Criteria"); my @filters = $input->param("Filter"); -$filters[0]=format_date_in_iso($filters[0]); -$filters[1]=format_date_in_iso($filters[1]); -$filters[2]=format_date_in_iso($filters[2]); -$filters[3]=format_date_in_iso($filters[3]); -my $output = $input->param("output"); +for (0..3) { + $filters[$_]=format_date_in_iso($filters[$_]); +} +my $output = $input->param("output"); my $basename = $input->param("basename"); -my $mime = $input->param("MIME"); -my $del = $input->param("sep"); +my $mime = $input->param("MIME"); +my $del = $input->param("sep"); #warn "calcul : ".$calc; my ($template, $borrowernumber, $cookie) = get_template_and_user({template_name => $fullreportname, @@ -63,7 +62,7 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); if ($do_it) { # Displaying results @@ -200,6 +199,18 @@ sub calculate { # Checking filters # my @loopfilter; + my @cellmap = ( + "Issue From", + "Issue To", + "Return From", + "Return To", + "Branch", + "Doc Type", + "Bor Cat", + "Day", + "Month", + "Year" + ); for (my $i=0;$i<=6;$i++) { my %cell; if ( @$filters[$i] ) { @@ -212,16 +223,8 @@ sub calculate { } else { $cell{filter} .= format_date(@$filters[$i]); } - $cell{crit} .="Issue From" if ($i==0); - $cell{crit} .="Issue To" if ($i==1); - $cell{crit} .="Return From" if ($i==2); - $cell{crit} .="Return To" if ($i==3); - $cell{crit} .="Branch" if ($i==4); - $cell{crit} .="Doc Type" if ($i==5); - $cell{crit} .="Bor Cat" if ($i==6); - $cell{crit} .="Day" if ($i==7); - $cell{crit} .="Month" if ($i==8); - $cell{crit} .="Year" if ($i==9); + defined ($cellmap[$i]) and + $cell{crit} .= $cellmap[$i]; push @loopfilter, \%cell; } } @@ -380,15 +383,11 @@ sub calculate { my $value; my $count=0; my $link; - if (@loopcol){ - $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'name'}; - $count =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'count'}; - $link =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'link'}; - } else { - $value =$table[$i]->{"zzEMPTY"}->{'name'}; - $count =$table[$i]->{"zzEMPTY"}->{'count'}; - $link =$table[$i]->{"zzEMPTY"}->{'link'}; - } + my $key = ((!(@loopcol)) or ($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global")) + ? "zzEMPTY" : $col->{coltitle}; + $value =$table[$i]->{$key}->{'name'}; + $count =$table[$i]->{$key}->{'count'}; + $link =$table[$i]->{$key}->{'link'}; # warn " ".$i ." value:$value count:$count reference:$link"; push @loopcell, {value => $value, count =>$count, reference => $link} ; } @@ -399,7 +398,6 @@ sub calculate { $hilighted = -$hilighted; } # - # the header of the table $globalline{loopfilter}=\@loopfilter; diff --git a/reports/borrowers_out.pl b/reports/borrowers_out.pl index 9bb5a8d958..185017051e 100755 --- a/reports/borrowers_out.pl +++ b/reports/borrowers_out.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl - # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. @@ -26,7 +25,7 @@ use C4::Koha; use C4::Output; use C4::Circulation; use C4::Members; -use C4::Date; +use C4::Dates; =head1 NAME @@ -48,7 +47,6 @@ 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, @@ -58,7 +56,7 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); if ($do_it) { # Displaying results @@ -151,8 +149,6 @@ output_html_with_http_headers $input, $cookie, $template->output; } - - sub calculate { my ($line, $column, $filters) = @_; my @mainloop; @@ -207,8 +203,6 @@ sub calculate { my $sth2 = $dbh->prepare( $strsth2 ); $sth2->execute; - - while (my ($celvalue) = $sth2->fetchrow) { my %cell; # my %ft; @@ -278,20 +272,20 @@ sub calculate { $dbcalc->execute; # warn "filling table"; my $previous_col; - my $i=1; + $i=1; while (my @data = $dbcalc->fetchrow) { my ($row, $col )=@data; $col = "zzEMPTY" if ($col eq undef); $i=1 if (($previous_col) and not($col eq $previous_col)); $table[$i]->{$col}=$row; -# warn " ".$i." ".$col. " ".$row; +# warn " $i $col $row"; $i++; $previous_col=$col; } push @loopcol,{coltitle => "Global"} if not($column); - my $max =(($line)?$line:@table -1); + $max =(($line)?$line:@table -1); for ($i=1; $i<=$max;$i++) { my @loopcell; #@loopcol ensures the order for columns is common with column titles diff --git a/reports/borrowers_stats.pl b/reports/borrowers_stats.pl index 3c3d36beb7..069038c943 100755 --- a/reports/borrowers_stats.pl +++ b/reports/borrowers_stats.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl - # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. @@ -24,6 +23,7 @@ use C4::Auth; use C4::Context; use C4::Branch; # GetBranches use C4::Koha; +use C4::Dates; use C4::Acquisition; use C4::Output; use C4::Circulation; @@ -236,7 +236,7 @@ foreach my $thisbranch (sort keys %$branches) { CGIsepChoice => $CGIsepChoice, CGIBranch => $CGIBranch, # CGIBranch => \@branchloop - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); } diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl index 8b2b61ca75..b5c6c03aaf 100755 --- a/reports/cat_issues_top.pl +++ b/reports/cat_issues_top.pl @@ -26,7 +26,7 @@ use C4::Branch; # GetBranches use C4::Output; use C4::Koha; use C4::Circulation; -use C4::Date; +use C4::Dates; use C4::Members; =head1 NAME @@ -61,7 +61,7 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); if ($do_it) { # Displaying results diff --git a/reports/catalogue_out.pl b/reports/catalogue_out.pl index cc28dcb8e8..5df3d42407 100755 --- a/reports/catalogue_out.pl +++ b/reports/catalogue_out.pl @@ -271,20 +271,17 @@ sub calculate { $strcalc .= " AND biblioitems.itemtype like '" . @$filters[1] ."'" if ( @$filters[1] ); $strcalc .= " group by items.itemnumber"; - $strcalc .= ", $colfield" if ($column); + $strcalc .= ", $colfield" if ($column); $strcalc .= " order by $colfield " if ($colfield); - my $max; - if (@loopcol) { - $max = $line*@loopcol; - } else { $max=$line;} - $strcalc .= " LIMIT 0,$max" if ($line); + my $max = (@loopcol) ? $line*@loopcol : $line ; + $strcalc .= " LIMIT 0,$max" if ($line); warn "SQL :". $strcalc; my $dbcalc = $dbh->prepare($strcalc); $dbcalc->execute; # warn "filling table"; my $previous_col; - my $i=1; + $i=1; while (my @data = $dbcalc->fetchrow) { my ($barcode,$title,$bibnum,$author, $col )=@data; $col = "zzEMPTY" if ($col eq undef); @@ -300,7 +297,7 @@ sub calculate { push @loopcol,{coltitle => "Global"} if not($column); - my $max =(($line)?$line:@table); + $max =(($line)?$line:@table); for ($i=1; $i<$max;$i++) { my @loopcell; #@loopcol ensures the order for columns is common with column titles diff --git a/reports/catalogue_stats.pl b/reports/catalogue_stats.pl index 35e56c8a83..3ac0216950 100755 --- a/reports/catalogue_stats.pl +++ b/reports/catalogue_stats.pl @@ -332,8 +332,8 @@ sub calculate { $linefilter[0] = @$filters[7] if ($line =~ /publishercode/ ) ; $linefilter[0] = @$filters[8] if ($line =~ /publicationyear/ ) ; $linefilter[1] = @$filters[9] if ($line =~ /publicationyear/ ) ; - @linefilter[0] = @$filters[10] if ($line =~ /items.homebranch/ ) ; - @linefilter[0] = @$filters[11] if ($line =~ /items.location/ ) ; + $linefilter[0] = @$filters[10] if ($line =~ /items.homebranch/ ) ; + $linefilter[0] = @$filters[11] if ($line =~ /items.location/ ) ; # my @colfilter ; $colfilter[0] = @$filters[0] if ($column =~ /dewey/ ) ; @@ -346,8 +346,8 @@ sub calculate { $colfilter[0] = @$filters[7] if ($column =~ /publishercode/ ) ; $colfilter[0] = @$filters[8] if ($column =~ /publicationyear/ ) ; $colfilter[1] = @$filters[9] if ($column =~ /publicationyear/ ) ; - @colfilter[0] = @$filters[10] if ($column =~ /items.homebranch/ ) ; - @colfilter[0] = @$filters[11] if ($column =~ /items.location/ ) ; + $colfilter[0] = @$filters[10] if ($column =~ /items.homebranch/ ) ; + $colfilter[0] = @$filters[11] if ($column =~ /items.location/ ) ; # 1st, loop rows. my $linefield; diff --git a/reports/inventory.pl b/reports/inventory.pl index 44197a2063..cbce08c982 100755 --- a/reports/inventory.pl +++ b/reports/inventory.pl @@ -23,8 +23,7 @@ use C4::Auth; use C4::Context; use C4::Output; use C4::Biblio; -use C4::Date; - +use C4::Dates; # Fixed variables my $linecolor1='#ffffcc'; @@ -33,7 +32,6 @@ my $backgroundimage="/images/background-mem.gif"; my $script_name="/cgi-bin/koha/admin/branches.pl"; my $pagepagesize=20; - ####################################################################################### # Main loop.... my $input = new CGI; @@ -65,14 +63,13 @@ $template->param(minlocation => $minlocation, ); if ($uploadbarcodes && length($uploadbarcodes)>0){ my $dbh=C4::Context->dbh; - my $date=format_date($input->param('setdate')); - $date = format_date("today") unless $date; + my $date = format_date($input->param('setdate')) || C4::Dates->new()->output(); # warn "$date"; my $strsth="update items set (datelastseen = $date) where items.barcode =?"; my $qupdate = $dbh->prepare($strsth); - my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null"; + $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null"; my $qonloan = $dbh->prepare($strsth); - my $strsth="select * from items where items.barcode =? and issues.wthdrawn=1"; + $strsth="select * from items where items.barcode =? and issues.wthdrawn=1"; my $qwthdrawn = $dbh->prepare($strsth); my @errorloop; my $count=0; diff --git a/reports/issues_avg_stats.pl b/reports/issues_avg_stats.pl index c3f1c6bfc2..b3ef7380a0 100755 --- a/reports/issues_avg_stats.pl +++ b/reports/issues_avg_stats.pl @@ -26,7 +26,7 @@ use C4::Branch; # GetBranches use C4::Output; use C4::Koha; use C4::Circulation; -use C4::Date; +use C4::Dates; use Date::Calc qw(Delta_Days); =head1 NAME @@ -66,7 +66,7 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); if ($do_it) { # Displaying results @@ -530,10 +530,9 @@ sub calculate { $row = "zzEMPTY" if ($row eq undef); # fill returndate to avoid an error with date calc (needed for all non returned issues) $returndate= join '-',Date::Calc::Today if $returndate eq '0000-00-00'; - my $result =Delta_Days(split(/-/,$issuedate),split (/-/,$returndate)) ; # DateCalc returns => 0:0:WK:DD:HH:MM:SS the weeks, days, hours, minutes, # and seconds between the two - $loanlength = $result; + $loanlength = Delta_Days(split(/-/,$issuedate),split (/-/,$returndate)) ; # warn "512 Same row and col DateCalc returns :$loanlength with return ". $returndate ."issue ". $issuedate ."weight : ". $weight; # warn "513 row :".$row." column :".$col; $table{$row}->{$col}+=$weight*$loanlength; diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl index ed59e5a7f6..114ef3df99 100755 --- a/reports/issues_stats.pl +++ b/reports/issues_stats.pl @@ -26,7 +26,7 @@ use C4::Branch; # GetBranches use C4::Koha; use C4::Output; use C4::Circulation; -use C4::Date; +use C4::Dates; use Date::Manip; =head1 NAME @@ -66,7 +66,7 @@ my ($template, $borrowernumber, $cookie) debug => 1, }); $template->param(do_it => $do_it, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); if ($do_it) { # Displaying results diff --git a/reports/manager.pl b/reports/manager.pl index 21251fd668..5572f26ed5 100755 --- a/reports/manager.pl +++ b/reports/manager.pl @@ -42,7 +42,7 @@ $template->param(do_it => $do_it, report_name => $report_name, ); my $cgidir = C4::Context->config('intranetdir')."/cgi-bin/reports/"; -unless (opendir(DIR, "$cgidir")) { +unless (-r $cgidir and -d $cgidir) { $cgidir = C4::Context->intranetdir."/reports/"; } my $plugin = $cgidir.$report_name.".plugin"; diff --git a/reports/reservereport.pl b/reports/reservereport.pl index 66d4b1bfd4..129f9cc88f 100755 --- a/reports/reservereport.pl +++ b/reports/reservereport.pl @@ -25,7 +25,7 @@ use strict; use C4::Stats; -use C4::Date; +use C4::Dates; use CGI; use C4::Output; use C4::Branch; # GetBranches diff --git a/reports/stats.screen.pl b/reports/stats.screen.pl index a7161994d9..50e5230581 100755 --- a/reports/stats.screen.pl +++ b/reports/stats.screen.pl @@ -84,8 +84,8 @@ if ( $time ne '' && $time2 ne '' ) { $date2 = ParseDate($time2); } -my $date = UnixDate( $date, '%Y-%m-%d' ); -my $date2 = UnixDate( $date2, '%Y-%m-%d' ); +$date = UnixDate( $date, '%Y-%m-%d' ); +$date2 = UnixDate( $date2, '%Y-%m-%d' ); # warn "MASON: TIME: $time, $time2"; # warn "MASON: DATE: $date, $date2"; @@ -164,8 +164,8 @@ while ( $i < $count ) { #get credits and append to the bottom of payments my @credits = getcredits( $date, $date2 ); -my $count = @credits; -my $i = 0; +$count = @credits; +$i = 0; while ( $i < $count ) { -- 2.20.1