fixed typo in 018 DB change
[koha_fer] / reports / acquisitions_stats.pl
index 2ef1b6f..8955126 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::Date;
 
 =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,17 +60,17 @@ 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 => get_date_format_string_for_DHTMLcalendar(),
+               );
 if ($do_it) {
 
     #warn
@@ -85,6 +86,7 @@ if ($do_it) {
     else {
         print $input->header(
             -type       => 'application/vnd.sun.xml.calc',
+            -encoding    => 'utf-8',
             -attachment => "$basename.csv",
             -name       => "$basename.csv"
         );
@@ -136,7 +138,7 @@ else {
     }
     my $CGIBookSellers = CGI::scrolling_list(
         -name   => 'Filter',
-        -id     => 'Filter',
+        -id     => 'supplier',
         -values => \@select,
 
         #                               -labels   => \%select,
@@ -159,7 +161,7 @@ else {
     }
     my $CGIItemTypes = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'itemtypes',
         -values   => \@select,
         -labels   => \%select,
         -size     => 1,
@@ -182,7 +184,7 @@ else {
     }
     my $CGIBudget = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'budget',
         -values   => \@select,
         -labels   => \%select,
         -size     => 1,
@@ -203,7 +205,7 @@ else {
     }
     my $CGISort1 = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'sort1',
         -values   => \@select,
         -size     => 1,
         -multiple => 0
@@ -226,7 +228,7 @@ else {
     }
     my $CGISort2 = CGI::scrolling_list(
         -name     => 'Filter',
-        -id       => 'Filter',
+        -id       => 'sort2',
         -values   => \@select,
         -size     => 1,
         -multiple => 0
@@ -294,7 +296,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 +614,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)