package C4::Stats;
-# $Id$
# Copyright 2000-2002 Katipo Communications
#
use strict;
require Exporter;
-use DBI;
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 );
-};
+$VERSION = 3.00;
=head1 NAME
=cut
@ISA = qw(Exporter);
-@EXPORT = qw(&UpdateStats);
+@EXPORT = qw(
+ &UpdateStats
+ &TotalPaid
+);
=item UpdateStats
# FIXME - Use $dbh->do() instead
my $sth = $dbh->prepare(
"Insert into statistics (datetime,branch,type,value,
- other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?,?)"
+ other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?)"
);
$sth->execute(
$branch, $type, $amount,
$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
+ 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()";
+ }
+ 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__