fix for bug 1723. no auth on finishreceive.pl
[koha_gimpoz] / reports / acquisitions_stats.pl
index 2ef1b6f..ae09354 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -25,12 +24,11 @@ use strict;
 use C4::Auth;
 use CGI;
 use C4::Context;
-use HTML::Template;
-use C4::Search;
+
 use C4::Output;
 use C4::Koha;
-use C4::Interface::CGI::Output;
-use C4::Circulation::Circ2;
+use C4::Circulation;
+use C4::Dates qw/format_date format_date_in_iso/;
 
 =head1 NAME
 
@@ -38,8 +36,7 @@ plugin that shows a stats on borrowers
 
 =head1 DESCRIPTION
 
-
-=over2
+=over 2
 
 =cut
 
@@ -49,6 +46,10 @@ my $fullreportname = "reports/acquisitions_stats.tmpl";
 my $line           = $input->param("Line");
 my $column         = $input->param("Column");
 my @filters        = $input->param("Filter");
+$filters[0]=format_date_in_iso($filters[0]);
+$filters[1]=format_date_in_iso($filters[1]);
+$filters[2]=format_date_in_iso($filters[2]);
+$filters[3]=format_date_in_iso($filters[3]);
 my $podsp          = $input->param("PlacedOnDisplay");
 my $rodsp          = $input->param("ReceivedOnDisplay");
 my $aodsp          = $input->param("AcquiredOnDisplay");    ##added by mason.
@@ -59,32 +60,29 @@ my $mime           = $input->param("MIME");
 my $del            = $input->param("sep");
 
 #warn "calcul : ".$calc;
-my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
-    {
-        template_name   => $fullreportname,
-        query           => $input,
-        type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { editcatalogue => 1 },
-        debug           => 1,
-    }
-);
-$template->param( do_it => $do_it );
+my ($template, $borrowernumber, $cookie)
+       = get_template_and_user({template_name => $fullreportname,
+                               query => $input,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {reports => 1},
+                               debug => 1,
+                               });
+$template->param(do_it => $do_it,
+        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
+               );
 if ($do_it) {
-
-    #warn
-"line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n";
-
+    # warn "line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n";
     my $results =
       calculate( $line, $column, $podsp, $rodsp, $aodsp, $calc, \@filters );
     if ( $output eq "screen" ) {
         $template->param( mainloop => $results );
         output_html_with_http_headers $input, $cookie, $template->output;
-        exit(1);
     }
     else {
         print $input->header(
             -type       => 'application/vnd.sun.xml.calc',
+            -encoding    => 'utf-8',
             -attachment => "$basename.csv",
             -name       => "$basename.csv"
         );
@@ -112,8 +110,8 @@ if ($do_it) {
             print $sep. $col->{totalcol};
         }
         print $sep. @$results[0]->{total};
-        exit(1);
     }
+    exit(1);
 }
 else {
     my $dbh = C4::Context->dbh;
@@ -121,9 +119,7 @@ else {
     my %labels;
     my %select;
     my $req;
-    $req =
-      $dbh->prepare(
-        "SELECT distinctrow id,name FROM aqbooksellers ORDER BY name");
+    $req = $dbh->prepare("SELECT distinctrow id,name FROM aqbooksellers ORDER BY name");
     $req->execute;
     my @select;
     push @select, "";
@@ -136,7 +132,7 @@ else {
     }
     my $CGIBookSellers = CGI::scrolling_list(
         -name   => 'Filter',
-        -id     => 'Filter',
+        -id     => 'supplier',
         -values => \@select,
 
         #                               -labels   => \%select,
@@ -159,7 +155,7 @@ else {
     }
     my $CGIItemTypes = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'itemtypes',
         -values   => \@select,
         -labels   => \%select,
         -size     => 1,
@@ -182,7 +178,7 @@ else {
     }
     my $CGIBudget = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'budget',
         -values   => \@select,
         -labels   => \%select,
         -size     => 1,
@@ -203,7 +199,7 @@ else {
     }
     my $CGISort1 = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'sort1',
         -values   => \@select,
         -size     => 1,
         -multiple => 0
@@ -226,7 +222,7 @@ else {
     }
     my $CGISort2 = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'sort2',
         -values   => \@select,
         -size     => 1,
         -multiple => 0
@@ -234,7 +230,6 @@ else {
 
     my @mime = ( C4::Context->preference("MIME") );
     foreach my $mime (@mime) {
-
         #               warn "".$mime;
     }
 
@@ -294,7 +289,12 @@ sub calculate {
             if ( ( ( $i == 1 ) or ( $i == 3 ) ) and ( @$filters[ $i - 1 ] ) ) {
                 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
             }
-            $cell{filter} .= @$filters[$i];
+            # format the dates filters, otherwise just fill as is
+            if ($i>=4) {
+                $cell{filter} .= @$filters[$i];
+            } else {
+                $cell{filter} .= format_date(@$filters[$i]);
+            }
             $cell{crit}   .= "Placed On From" if ( $i == 0 );
             $cell{crit}   .= "Placed On To" if ( $i == 1 );
             $cell{crit}   .= "Received On From" if ( $i == 2 );
@@ -607,7 +607,7 @@ sub calculate {
     # preparing calculation
     my $strcalc;
     $strcalc .= "SELECT $linefield, $colfield, ";
-    $strcalc .= "COUNT( aqorders.ordernumber ) " if ( $process == 1 );
+    $strcalc .= "SUM( aqorders.quantity ) " if ( $process == 1 );
     $strcalc .= "SUM( aqorders.quantity * aqorders.listprice ) "
       if ( $process == 2 );
     $strcalc .= "FROM (aqorders, aqbasket,aqorderbreakdown)