Bugfix: Correcting conditional for branch code check
[koha.git] / reports / borrowers_stats.pl
index 0245baa..437bd09 100755 (executable)
@@ -26,7 +26,9 @@ use C4::Koha;
 use C4::Dates;
 use C4::Acquisition;
 use C4::Output;
+use C4::Reports;
 use C4::Circulation;
+use C4::Dates qw/format_date format_date_in_iso/;
 use Date::Calc qw(
   Today
   Add_Delta_YM
@@ -48,6 +50,8 @@ my $fullreportname = "reports/borrowers_stats.tmpl";
 my $line = $input->param("Line");
 my $column = $input->param("Column");
 my @filters = $input->param("Filter");
+$filters[3]=format_date_in_iso($filters[3]);
+$filters[4]=format_date_in_iso($filters[4]);
 my $digits = $input->param("digits");
 my $period = $input->param("period");
 my $borstat = $input->param("status");
@@ -55,7 +59,8 @@ my $borstat1 = $input->param("activity");
 my $output = $input->param("output");
 my $basename = $input->param("basename");
 my $mime = $input->param("MIME");
-my $del = $input->param("sep");
+our $sep     = $input->param("sep");
+$sep = "\t" if ($sep eq 'tabulation');
 my $selected_branch; # = $input->param("?");
 
 our $branches = GetBranches;
@@ -65,7 +70,7 @@ my ($template, $borrowernumber, $cookie)
                                query => $input,
                                type => "intranet",
                                authnotrequired => 0,
-                               flagsrequired => {reports=> 1},
+                               flagsrequired => {reports => '*'},
                                debug => 1,
                                });
 $template->param(do_it => $do_it);
@@ -81,8 +86,6 @@ if ($do_it) {
                        -attachment => "$basename.csv");
                my $cols = @$results[0]->{loopcol};
                my $lines = @$results[0]->{looprow};
-               my $sep;
-               $sep =C4::Context->preference("delimiter");
                print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
                foreach my $col ( @$cols ) {
                        print $col->{coltitle}.$sep;
@@ -122,7 +125,7 @@ if ($do_it) {
        $req = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category='Bsort1' ORDER BY lib");
        $req->execute;
        $template->param( SORT1_LOOP => $req->fetchall_arrayref({}));
-       $req = $dbh->prepare("SELECT DISTINCTROW sort2 AS value FROM borrowers WHERE sort2 IS NOT NULL AND sort <> '' ORDER BY sort2 LIMIT 200");
+       $req = $dbh->prepare("SELECT DISTINCTROW sort2 AS value FROM borrowers WHERE sort2 IS NOT NULL AND sort2 <> '' ORDER BY sort2 LIMIT 200");
                # More than 200 items in a dropdown is not going to be useful anyway, and w/ 50,000 patrons we can destory DB performance.
        $req->execute;
        $template->param( SORT2_LOOP => $req->fetchall_arrayref({}));
@@ -135,13 +138,7 @@ if ($do_it) {
                                -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 );
+       my $CGIsepChoice=GetDelimiterChoices;
        $template->param(
                CGIextChoice => $CGIextChoice,
                CGIsepChoice => $CGIsepChoice,
@@ -203,7 +200,12 @@ sub calculate {
        for (my $i=0;$i<=7;$i++) {
                my %cell;
                if ( @$filters[$i] ) {
-                       $cell{filter} .= @$filters[$i];
+                   if($i == 3 or $i == 4){
+                       $cell{filter} .= format_date(@$filters[$i]);
+                   }else{
+                       $cell{filter} .= @$filters[$i];
+                   }
+                       
                        $cell{crit} .="Cat Code " if ($i==0);
                        $cell{crit} .="Zip Code" if ($i==1);
                        $cell{crit} .="Branchcode" if ($i==2);