Bug 2969 - Report Name should be mandatory for saved reports
[srvgit] / reports / borrowers_out.pl
index 0a135e1..9687234 100755 (executable)
@@ -32,17 +32,17 @@ use C4::Dates qw/format_date_in_iso/;
 
 =head1 NAME
 
-plugin that shows a stats on borrowers
+reports/borrowers_out.pl
 
 =head1 DESCRIPTION
 
-=over 2
+Plugin that shows a stats on borrowers
 
 =cut
 
 my $input = new CGI;
 my $do_it=$input->param('do_it');
-my $fullreportname = "reports/borrowers_out.tmpl";
+my $fullreportname = "reports/borrowers_out.tt";
 my $limit = $input->param("Limit");
 my $column = $input->param("Criteria");
 my @filters = $input->param("Filter");
@@ -60,7 +60,6 @@ my ($template, $borrowernumber, $cookie)
                 debug => 1,
                 });
 $template->param(do_it => $do_it,
-        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
         );
 if ($do_it) {
 # Displaying results
@@ -69,7 +68,7 @@ if ($do_it) {
 # Printing results to screen
         $template->param(mainloop => $results);
         output_html_with_http_headers $input, $cookie, $template->output;
-        exit(1);
+        exit;
     } else {
 # Printing to a csv file
         print $input->header(-type => 'application/vnd.sun.xml.calc',
@@ -103,7 +102,7 @@ if ($do_it) {
             print $sep.$col->{totalcol};
         }
         print $sep.@$results[0]->{total};
-        exit(1);
+        exit;
     }
 # Displaying choices
 } else {
@@ -113,13 +112,7 @@ if ($do_it) {
     my %select;
     my $req;
     
-    my $CGIextChoice=CGI::scrolling_list(
-                -name     => 'MIME',
-                -id       => 'MIME',
-                -values   => ['CSV'], # FIXME translation
-                -size     => 1,
-                -multiple => 0 );
-    
+    my $CGIextChoice = ( 'CSV' ); # FIXME translation
        my $CGIsepChoice = GetDelimiterChoices;
     
     my ($codes,$labels) = GetborCatFromCatType(undef,undef);
@@ -230,18 +223,12 @@ sub calculate {
     @$filters[0]=~ s/\*/%/g if (@$filters[0]);
     $strcalc .= " AND borrowers.categorycode like '" . @$filters[0] ."'" if ( @$filters[0] );
 
-    my $strqueryfilter = "SELECT DISTINCT borrowernumber FROM  ";
-    $strqueryfilter .= "(SELECT borrowernumber from old_issues WHERE borrowernumber IS NOT NULL ";
-    if ($filters->[1]){
-        $strqueryfilter .= "AND old_issues.timestamp> '$filters->[1]' ";
-    }
-    $strqueryfilter .= "UNION SELECT borrowernumber FROM issues WHERE 1 ";
-    if ($filters->[1]){
-        $strqueryfilter .= "AND issues.timestamp> '$filters->[1]' ";
-    }
-    $strqueryfilter .= ") active_borrowers";
-
-    $strcalc .= " AND borrowers.borrowernumber not in ($strqueryfilter)";
+    $strcalc .= " AND NOT EXISTS (SELECT * FROM issues WHERE issues.borrowernumber=borrowers.borrowernumber ";
+    $strcalc .= " AND issues.timestamp> '" . @$filters[1] . "'" if (@$filters[1]);
+    $strcalc .= ") ";
+    $strcalc .= " AND NOT EXISTS (SELECT * FROM old_issues WHERE old_issues.borrowernumber=borrowers.borrowernumber ";
+    $strcalc .= " AND old_issues.timestamp> '" . @$filters[1] . "'" if (@$filters[1]);
+    $strcalc .= ") ";
     $strcalc .= " group by borrowers.borrowernumber";
     $strcalc .= ", $colfield" if ($column);
     $strcalc .= " order by $colfield " if ($colfield);