Bug 15758: Koha::Libraries - Remove GetBranchName
[srvgit] / reports / reserves_stats.pl
index bfeaf8b..04d6268 100755 (executable)
@@ -21,7 +21,7 @@
 use strict;
 use warnings;
 
-use CGI;
+use CGI qw ( -utf8 );
 
 use C4::Auth;
 use C4::Debug;
@@ -31,24 +31,25 @@ use C4::Koha;
 use C4::Output;
 use C4::Reports;
 use C4::Members;
-use C4::Dates qw/format_date format_date_in_iso/;
-use C4::Category;
+use Koha::DateUtils;
+use Koha::Libraries;
+use Koha::Patron::Categories;
 use List::MoreUtils qw/any/;
 use YAML;
 
 =head1 NAME
 
-plugin that shows circulation stats
+    reports/reserve_stats.pl
 
 =head1 DESCRIPTION
 
-=over 2
+    Plugin that shows circulation stats
 
 =cut
 
 # my $debug = 1;       # override for now.
 my $input = new CGI;
-my $fullreportname = "reports/reserves_stats.tmpl";
+my $fullreportname = "reports/reserves_stats.tt";
 my $do_it    = $input->param('do_it');
 my $line     = $input->param("Line");
 my $column   = $input->param("Column");
@@ -81,7 +82,7 @@ $template->param(do_it => $do_it,
 );
 
 my $itemtypes = GetItemTypes();
-my $categoryloop = GetBorrowercategoryList;
+my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
 
 my $ccodes    = GetKohaAuthorisedValues("items.ccode");
 my $locations = GetKohaAuthorisedValues("items.location");
@@ -139,8 +140,8 @@ my %select;
 
 # create itemtype arrayref for <select>.
 my @itemtypeloop;
-for my $itype ( sort {$itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description}} keys(%$itemtypes)) {
-       push @itemtypeloop, { code => $itype , description => $itemtypes->{$itype}->{description} } ;
+for my $itype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description}} keys(%$itemtypes)) {
+       push @itemtypeloop, { code => $itype , description => $itemtypes->{$itype}->{translated_description} } ;
 }
 
     # location list
@@ -155,19 +156,11 @@ foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
 }
 
 # various
-my @mime = (C4::Context->preference("MIME"));
-
-my $CGIextChoice=CGI::scrolling_list(
-       -name     => 'MIME',
-       -id       => 'MIME',
-       -values   => \@mime,
-       -size     => 1,
-       -multiple => 0 );
-    
+my $CGIextChoice = ( 'CSV' ); # FIXME translation
 my $CGIsepChoice=GetDelimiterChoices;
  
 $template->param(
-       categoryloop => $categoryloop,
+    categoryloop => \@patron_categories,
        itemtypeloop => \@itemtypeloop,
        locationloop => \@locations,
           ccodeloop => \@ccodes,
@@ -198,9 +191,10 @@ sub calculate {
     my @loopfilter;
     foreach my $filter ( keys %$filters_hashref ) {
         $filters_hashref->{$filter} =~ s/\*/%/;
-        $filters_hashref->{$filter} =
-          format_date_in_iso( $filters_hashref->{$filter} )
-          if ( $filter =~ /date/ );
+        if ( $filter =~ /date/ ) {
+            $filters_hashref->{$filter} =
+                eval { output_pref( { dt => dt_from_string( $filters_hashref->{$filter} ), dateonly => 1, dateformat => 'iso' }); };
+        }
     }
 
     #display
@@ -209,7 +203,7 @@ sub calculate {
             crit   => $_,
             filter => (
                 $_ =~ /date/
-                ? format_date( $filters_hashref->{$_} )
+                ? eval { output_pref( { dt => dt_from_string( $filters_hashref->{$_} ), dateonly => 1 }); }
                 : $filters_hashref->{$_}
             )
         }
@@ -345,7 +339,7 @@ sub display_value {
         ( $crit =~ /ccode/ )         ? $ccodes->{$value}
       : ( $crit =~ /location/ )      ? $locations->{$value}
       : ( $crit =~ /itemtype/ )      ? $itemtypes->{$value}->{description}
-      : ( $crit =~ /branch/ )        ? GetBranchName($value)
+      : ( $crit =~ /branch/ )        ? Koha::Libraries->find($value)->branchname
       : ( $crit =~ /reservestatus/ ) ? reservestatushuman($value)
       :                                $value;    # default fallback
     if ($crit =~ /sort1/) {
@@ -361,9 +355,9 @@ sub display_value {
         }
     }
     elsif ( $crit =~ /category/ ) {
-        foreach (@$categoryloop) {
-            ( $value eq $_->{categorycode} ) or next;
-            $display_value = $_->{description} and last;
+        foreach my $patron_category ( @patron_categories ) {
+            ( $value eq $patron_category->categorycode ) or next;
+            $display_value = $patron_category->description and last;
         }
     }
     return $display_value;