re introducing TotalPaid function as circ/stat.pl use it.
authortoins <toins>
Tue, 5 Jun 2007 10:01:17 +0000 (10:01 +0000)
committertoins <toins>
Tue, 5 Jun 2007 10:01:17 +0000 (10:01 +0000)
C4/Stats.pm

index 3f9a178..d6a0e9c 100644 (file)
@@ -21,7 +21,6 @@ package C4::Stats;
 
 use strict;
 require Exporter;
-use DBI;
 use C4::Context;
 use vars qw($VERSION @ISA @EXPORT);
 
@@ -50,7 +49,10 @@ the Koha database, which acts as an activity log.
 =cut
 
 @ISA    = qw(Exporter);
-@EXPORT = qw(&UpdateStats);
+@EXPORT = qw(
+    &UpdateStats
+    &TotalPaid
+);
 
 =item UpdateStats
 
@@ -89,6 +91,36 @@ sub UpdateStats {
     $sth->finish;
 }
 
+# Otherwise, it'd need a POD.
+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') ";
+    if ( $time eq 'today' ) {
+        $query = $query . " AND datetime = now()";
+    }
+    else {
+        $query .= " AND datetime > '$time'";
+    }
+    if ( $time2 ne '' ) {
+        $query .= " AND datetime < '$time2'";
+    }
+    if ($spreadsheet) {
+        $query .= " ORDER BY branch, type";
+    }
+    my $sth = $dbh->prepare($query);
+    $sth->execute();
+    my @results;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        push @results, $data;
+    }
+    $sth->finish;
+    return (@results);
+}
+
 1;
 __END__