removed reports/inventory.pl
[koha-ffzg.git] / reports / bor_issues_top.pl
index 0f7dc0e..ce98071 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -28,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 format_date_in_iso);
 
 =head1 NAME
 
@@ -41,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,
@@ -64,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
@@ -122,28 +120,25 @@ if ($do_it) {
 #      foreach my $mime (@mime){
 #              warn "".$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 );
-    #branch
-    my $branches = GetBranches;
-    my @branchloop;
-    foreach my $thisbranch (keys %$branches) {
-#                      my $selected = 1 if $thisbranch eq $branch;
+        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 );
+        #branch
+        my $branches = GetBranches;
+       my @branchloop;
+       foreach my $thisbranch (sort keys %$branches) {
             my %row =(value => $thisbranch,
-#                                                                      selected => $selected,
                                     branchname => $branches->{$thisbranch}->{'branchname'},
                             );
             push @branchloop, \%row;
@@ -204,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] ) {
@@ -216,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;
         }
     }
@@ -384,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} ;
         }
@@ -403,7 +398,6 @@ sub calculate {
         $hilighted = -$hilighted;
     }
 #      
-            
 
     # the header of the table
     $globalline{loopfilter}=\@loopfilter;