bug-2149, added new block to C4::Letters::SendAlerts() to email 'account creation...
[koha.git] / C4 / Stats.pm
blob0afd810d4f5ca86af6c5b9dab54977b54a93bcde
1 package C4::Stats;
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
21 use strict;
22 require Exporter;
23 use C4::Context;
24 use vars qw($VERSION @ISA @EXPORT);
26 BEGIN {
27 # set the version for version checking
28 $VERSION = 3.01;
29 @ISA = qw(Exporter);
30 @EXPORT = qw(
31 &UpdateStats
32 &TotalPaid
37 =head1 NAME
39 C4::Stats - Update Koha statistics (log)
41 =head1 SYNOPSIS
43 use C4::Stats;
45 =head1 DESCRIPTION
47 The C<&UpdateStats> function adds an entry to the statistics table in
48 the Koha database, which acts as an activity log.
50 =head1 FUNCTIONS
52 =over 2
54 =item UpdateStats
56 &UpdateStats($branch, $type, $value, $other, $itemnumber,
57 $itemtype, $borrowernumber);
59 Adds a line to the statistics table of the Koha database. In effect,
60 it logs an event.
62 C<$branch>, C<$type>, C<$value>, C<$other>, C<$itemnumber>,
63 C<$itemtype>, and C<$borrowernumber> correspond to the fields of the
64 statistics table in the Koha database.
66 =cut
69 sub UpdateStats {
71 #module to insert stats data into stats table
72 my (
73 $branch, $type,
74 $amount, $other, $itemnum,
75 $itemtype, $borrowernumber, $accountno
77 = @_;
78 my $dbh = C4::Context->dbh;
79 my $sth = $dbh->prepare(
80 "INSERT INTO statistics (datetime,branch,type,value,
81 other,itemnumber,itemtype,borrowernumber,proccode) VALUES (now(),?,?,?,?,?,?,?,?)"
83 $sth->execute(
84 $branch, $type, $amount,
85 $other, $itemnum, $itemtype, $borrowernumber,
86 $accountno
88 $sth->finish;
91 # Otherwise, it'd need a POD.
92 sub TotalPaid {
93 my ( $time, $time2, $spreadsheet ) = @_;
94 $time2 = $time unless $time2;
95 my $dbh = C4::Context->dbh;
96 my $query = "SELECT * FROM statistics
97 LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber
98 WHERE (statistics.type='payment' OR statistics.type='writeoff') ";
99 if ( $time eq 'today' ) {
100 $query = $query . " AND datetime = now()";
102 else {
103 $query .= " AND datetime > '$time'";
105 if ( $time2 ne '' ) {
106 $query .= " AND datetime < '$time2'";
108 if ($spreadsheet) {
109 $query .= " ORDER BY branch, type";
111 my $sth = $dbh->prepare($query);
112 warn $query;
113 $sth->execute();
114 my @results;
115 while ( my $data = $sth->fetchrow_hashref ) {
116 push @results, $data;
118 $sth->finish;
119 return (@results);
123 __END__
125 =back
127 =head1 AUTHOR
129 Koha Developement team <info@koha.org>
131 =cut