replacing SUPER with NO_LIBRARY_SET for login information
[koha.git] / C4 / Stats.pm
1 package C4::Stats;
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 require Exporter;
24 use C4::Context;
25 use vars qw($VERSION @ISA @EXPORT);
26
27 # set the version for version checking
28 $VERSION = $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
29     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
30 };
31
32 =head1 NAME
33
34 C4::Stats - Update Koha statistics (log)
35
36 =head1 SYNOPSIS
37
38   use C4::Stats;
39
40 =head1 DESCRIPTION
41
42 The C<&UpdateStats> function adds an entry to the statistics table in
43 the Koha database, which acts as an activity log.
44
45 =head1 FUNCTIONS
46
47 =over 2
48
49 =cut
50
51 @ISA    = qw(Exporter);
52 @EXPORT = qw(
53     &UpdateStats
54     &TotalPaid
55 );
56
57 =item UpdateStats
58
59   &UpdateStats($branch, $type, $value, $other, $itemnumber,
60                $itemtype, $borrowernumber);
61
62 Adds a line to the statistics table of the Koha database. In effect,
63 it logs an event.
64
65 C<$branch>, C<$type>, C<$value>, C<$other>, C<$itemnumber>,
66 C<$itemtype>, and C<$borrowernumber> correspond to the fields of the
67 statistics table in the Koha database.
68
69 =cut
70
71 #'
72 sub UpdateStats {
73
74     #module to insert stats data into stats table
75     my (
76         $branch,         $type,
77         $amount,   $other,          $itemnum,
78         $itemtype, $borrowernumber
79       )
80       = @_;
81     my $dbh = C4::Context->dbh;
82     # FIXME - Use $dbh->do() instead
83     my $sth = $dbh->prepare(
84         "Insert into statistics (datetime,branch,type,value,
85                                         other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?)"
86     );
87     $sth->execute(
88         $branch,    $type,    $amount,
89         $other,     $itemnum, $itemtype, $borrowernumber,
90     );
91     $sth->finish;
92 }
93
94 # Otherwise, it'd need a POD.
95 sub TotalPaid {
96     my ( $time, $time2, $spreadsheet ) = @_;
97     $time2 = $time unless $time2;
98     my $dbh   = C4::Context->dbh;
99     my $query = "SELECT * FROM statistics,borrowers
100   WHERE statistics.borrowernumber= borrowers.borrowernumber
101   AND (statistics.type='payment' OR statistics.type='writeoff') ";
102     if ( $time eq 'today' ) {
103         $query = $query . " AND datetime = now()";
104     }
105     else {
106         $query .= " AND datetime > '$time'";
107     }
108     if ( $time2 ne '' ) {
109         $query .= " AND datetime < '$time2'";
110     }
111     if ($spreadsheet) {
112         $query .= " ORDER BY branch, type";
113     }
114     my $sth = $dbh->prepare($query);
115     $sth->execute();
116     my @results;
117     while ( my $data = $sth->fetchrow_hashref ) {
118         push @results, $data;
119     }
120     $sth->finish;
121     return (@results);
122 }
123
124 1;
125 __END__
126
127 =back
128
129 =head1 AUTHOR
130
131 Koha Developement team <info@koha.org>
132
133 =cut
134