package C4::Stats;
-# $Id$
# Copyright 2000-2002 Katipo Communications
#
# Suite 330, Boston, MA 02111-1307 USA
use strict;
+use warnings;
require Exporter;
-use DBI;
use C4::Context;
+use C4::Debug;
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 );
-};
+our $debug;
+
+BEGIN {
+ # set the version for version checking
+ $VERSION = 3.01;
+ @ISA = qw(Exporter);
+ @EXPORT = qw(
+ &UpdateStats
+ &TotalPaid
+ );
+}
+
=head1 NAME
=over 2
-=cut
-
-@ISA = qw(Exporter);
-@EXPORT = qw(&UpdateStats);
-
=item UpdateStats
- &UpdateStats($env, $branch, $type, $value, $other, $itemnumber,
+ &UpdateStats($branch, $type, $value, $other, $itemnumber,
$itemtype, $borrowernumber);
Adds a line to the statistics table of the Koha database. In effect,
C<$itemtype>, and C<$borrowernumber> correspond to the fields of the
statistics table in the Koha database.
-If C<$branch> is the empty string, the branch code will be taken from
-C<$env-E<gt>{branchcode}>.
-
-C<$env-E<gt>{usercode}> specifies the value of the C<usercode> field.
-
=cut
#'
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;
+}
+
+# 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 .= " AND datetime = now()";
+ } else {
+ $query .= " AND datetime > '$time'"; # FIXME: use placeholders
+ }
+ if ( $time2 ne '' ) {
+ $query .= " AND datetime < '$time2'"; # FIXME: use placeholders
+ }
+ if ($spreadsheet) {
+ $query .= " ORDER BY branch, type";
+ }
+ $debug and warn "TotalPaid query: $query";
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ return @{$sth->fetchall_arrayref({})};
}
1;