Bug 28959: Fix other cases
[koha-ffzg.git] / reports / acquisitions_stats.pl
index 58e3fd9..1d27870 100755 (executable)
 
 use Modern::Perl;
 
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use CGI qw ( -utf8 );
 use C4::Context;
-use C4::Reports;
-use C4::Output;
-use C4::Koha;
-use C4::Circulation;
-use C4::Branch;
-use C4::Biblio;
-use Koha::DateUtils;
+use C4::Reports qw( GetDelimiterChoices );
+use C4::Output qw( output_html_with_http_headers );
+use C4::Koha qw( GetAuthorisedValues );
+use C4::Biblio qw( GetMarcSubfieldStructureFromKohaField );
+use Koha::ItemTypes;
+use Koha::DateUtils qw( dt_from_string output_pref );
+use Koha::Libraries;
 
 =head1 NAME
 
@@ -40,12 +40,12 @@ Plugin that shows a stats on borrowers
 
 =cut
 
-my $input          = new CGI;
+my $input          = CGI->new;
 my $do_it          = $input->param('do_it');
 my $fullreportname = "reports/acquisitions_stats.tt";
 my $line           = $input->param("Line");
 my $column         = $input->param("Column");
-my @filters        = $input->param("Filter");
+my @filters        = $input->multi_param("Filter");
 $filters[0] = eval { output_pref( { dt => dt_from_string( $filters[0]), dateonly => 1, dateformat => 'iso' } ); }
     if ( $filters[0] );
 $filters[1] = eval { output_pref( { dt => dt_from_string( $filters[1]), dateonly => 1, dateformat => 'iso' } ); }
@@ -65,9 +65,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
         template_name   => $fullreportname,
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { reports => '*' },
-        debug           => 1,
     }
 );
 
@@ -124,8 +122,6 @@ else {
     $req->execute;
     my $booksellers = $req->fetchall_arrayref({});
 
-    my $itemtypes = GetItemTypes( style => 'array' );
-
     $req = $dbh->prepare("SELECT DISTINCTROW budget_code, budget_name FROM aqbudgets ORDER BY budget_name");
     $req->execute;
     my @bselect;
@@ -185,13 +181,9 @@ else {
 
     my $CGIsepChoice = GetDelimiterChoices;
 
-    my $branches = GetBranches;
-    my @branches;
-    foreach ( sort keys %$branches ) {
-        push @branches, $branches->{$_};
-    }
+    my @branches = Koha::Libraries->search({}, { order_by => 'branchname' });
 
-    my $ccode_subfield_structure = GetMarcSubfieldStructureFromKohaField('items.ccode', '');
+    my $ccode_subfield_structure = GetMarcSubfieldStructureFromKohaField('items.ccode');
     my $ccode_label;
     my $ccode_avlist;
     if($ccode_subfield_structure) {
@@ -199,9 +191,10 @@ else {
         $ccode_avlist = GetAuthorisedValues($ccode_subfield_structure->{authorised_value});
     }
 
+    my $itemtypes = Koha::ItemTypes->search_with_localization;
     $template->param(
         booksellers   => $booksellers,
-        itemtypes     => $itemtypes,
+        itemtypes     => $itemtypes, # FIXME Should use the TT plugin instead
         Budgets       => $Budgets,
         hassort1      => $hassort1,
         hassort2      => $hassort2,
@@ -284,7 +277,7 @@ sub calculate {
             } elsif ( $rodsp == 3 ) {
                 $field{$a} = "Year($a)";
             } else {
-                field{$a} = $a;
+                $field{$a} = $a;
             }
         }
         elsif ( $_ =~ /bookseller/ ) {
@@ -430,7 +423,6 @@ sub calculate {
     }
 
     my $i = 0;
-    my @totalcol;
     my $hilighted = -1;
 
     #Initialization of cell values.....