Merge remote-tracking branch 'origin/new/bug_7751'
[koha.git] / reports / borrowers_stats.pl
index 1ef6823..9e00ea3 100755 (executable)
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
+#use warnings; FIXME - Bug 2505
 use CGI;
 use C4::Auth;
 use C4::Context;
@@ -26,7 +27,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,14 +51,16 @@ 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");
 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;
@@ -104,7 +107,7 @@ if ($do_it) {
                }
                print $sep.@$results[0]->{total};
        }
-       exit(1);        # exit after do_it, regardless
+       exit;   # exit after do_it, regardless
 } else {
        my $dbh = C4::Context->dbh;
        my $req;
@@ -127,21 +130,13 @@ if ($do_it) {
        $req->execute;
        $template->param( SORT2_LOOP => $req->fetchall_arrayref({}));
        
-       my @mime = ( C4::Context->preference("MIME") );
-       # warn 'MIME(s): ' . join ' ', @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,
+                               -values   => ['CSV'], # FIXME translation
                                -size     => 1,
                                -multiple => 0 );
+       my $CGIsepChoice=GetDelimiterChoices;
        $template->param(
                CGIextChoice => $CGIextChoice,
                CGIsepChoice => $CGIsepChoice,
@@ -203,7 +198,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);