From 104925e9ac1757a7352d1f654e3ca91e5bc686e8 Mon Sep 17 00:00:00 2001 From: toins Date: Tue, 5 Jun 2007 10:01:17 +0000 Subject: [PATCH] re introducing TotalPaid function as circ/stat.pl use it. --- C4/Stats.pm | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/C4/Stats.pm b/C4/Stats.pm index 3f9a1785b2..d6a0e9ceac 100644 --- a/C4/Stats.pm +++ b/C4/Stats.pm @@ -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__ -- 2.39.5