Cleanup for member entry: XHTML-compliance (close inputs, ids must match labels)...
[koha.git] / C4 / Stats.pm
index d6a0e9c..0afd810 100644 (file)
@@ -1,6 +1,5 @@
 package C4::Stats;
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -24,10 +23,16 @@ require Exporter;
 use C4::Context;
 use vars qw($VERSION @ISA @EXPORT);
 
-# set the version for version checking
-$VERSION = $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
-    shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
-};
+BEGIN {
+       # set the version for version checking
+       $VERSION = 3.01;
+       @ISA    = qw(Exporter);
+       @EXPORT = qw(
+               &UpdateStats
+               &TotalPaid
+       );
+}
+
 
 =head1 NAME
 
@@ -46,14 +51,6 @@ the Koha database, which acts as an activity log.
 
 =over 2
 
-=cut
-
-@ISA    = qw(Exporter);
-@EXPORT = qw(
-    &UpdateStats
-    &TotalPaid
-);
-
 =item UpdateStats
 
   &UpdateStats($branch, $type, $value, $other, $itemnumber,
@@ -75,18 +72,18 @@ sub UpdateStats {
     my (
         $branch,         $type,
         $amount,   $other,          $itemnum,
-        $itemtype, $borrowernumber
+        $itemtype, $borrowernumber, $accountno
       )
       = @_;
     my $dbh = C4::Context->dbh;
-    # FIXME - Use $dbh->do() instead
     my $sth = $dbh->prepare(
-        "Insert into statistics (datetime,branch,type,value,
-                                        other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?)"
+        "INSERT INTO statistics (datetime,branch,type,value,
+                                        other,itemnumber,itemtype,borrowernumber,proccode) VALUES (now(),?,?,?,?,?,?,?,?)"
     );
     $sth->execute(
         $branch,    $type,    $amount,
         $other,     $itemnum, $itemtype, $borrowernumber,
+               $accountno
     );
     $sth->finish;
 }
@@ -96,9 +93,9 @@ sub TotalPaid {
     my ( $time, $time2, $spreadsheet ) = @_;
     $time2 = $time unless $time2;
     my $dbh   = C4::Context->dbh;
-    my $query = "SELECT * FROM statistics,borrowers
-  WHERE statistics.borrowernumber= borrowers.borrowernumber
-  AND (statistics.type='payment' OR statistics.type='writeoff') ";
+    my $query = "SELECT * FROM statistics 
+  LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber
+  WHERE (statistics.type='payment' OR statistics.type='writeoff') ";
     if ( $time eq 'today' ) {
         $query = $query . " AND datetime = now()";
     }
@@ -112,6 +109,7 @@ sub TotalPaid {
         $query .= " ORDER BY branch, type";
     }
     my $sth = $dbh->prepare($query);
+warn $query;
     $sth->execute();
     my @results;
     while ( my $data = $sth->fetchrow_hashref ) {