reports subdir - Dates.pm integration and warnings fixes.
authorJoe Atzberger <joe.atzberger@liblime.com>
Tue, 4 Dec 2007 23:40:47 +0000 (17:40 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 5 Dec 2007 00:21:02 +0000 (18:21 -0600)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
13 files changed:
reports/acquisitions_stats.pl
reports/bor_issues_top.pl
reports/borrowers_out.pl
reports/borrowers_stats.pl
reports/cat_issues_top.pl
reports/catalogue_out.pl
reports/catalogue_stats.pl
reports/inventory.pl
reports/issues_avg_stats.pl
reports/issues_stats.pl
reports/manager.pl
reports/reservereport.pl
reports/stats.screen.pl

index 8955126..e135ec0 100755 (executable)
@@ -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;
     }
 
index 06e41c7..da38ba4 100755 (executable)
@@ -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;
index 9bb5a8d..1850170 100755 (executable)
@@ -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
index 3c3d36b..069038c 100755 (executable)
@@ -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(),
                     );
 
 }
index 8b2b61c..b5c6c03 100755 (executable)
@@ -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
index cc28dcb..5df3d42 100755 (executable)
@@ -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
index 35e56c8..3ac0216 100755 (executable)
@@ -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;
index 44197a2..cbce08c 100755 (executable)
@@ -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;
index c3f1c6b..b3ef738 100755 (executable)
@@ -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;
index ed59e5a..114ef3d 100755 (executable)
@@ -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
index 21251fd..5572f26 100755 (executable)
@@ -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";
index 66d4b1b..129f9cc 100755 (executable)
@@ -25,7 +25,7 @@
 
 use strict;
 use C4::Stats;
-use C4::Date;
+use C4::Dates;
 use CGI;
 use C4::Output;
 use C4::Branch; # GetBranches
index a716199..50e5230 100755 (executable)
@@ -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 ) {