BUGFIX: the language list was calculated on opaclanguage, whatever the interface
[koha.git] / C4 / Stats.pm
1 package C4::Stats;
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
16 #
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
20
21 use strict;
22 require Exporter;
23 use C4::Context;
24 use vars qw($VERSION @ISA @EXPORT);
25
26 BEGIN {
27         # set the version for version checking
28         $VERSION = 3.01;
29         @ISA    = qw(Exporter);
30         @EXPORT = qw(
31                 &UpdateStats
32                 &TotalPaid
33         );
34 }
35
36
37 =head1 NAME
38
39 C4::Stats - Update Koha statistics (log)
40
41 =head1 SYNOPSIS
42
43   use C4::Stats;
44
45 =head1 DESCRIPTION
46
47 The C<&UpdateStats> function adds an entry to the statistics table in
48 the Koha database, which acts as an activity log.
49
50 =head1 FUNCTIONS
51
52 =over 2
53
54 =item UpdateStats
55
56   &UpdateStats($branch, $type, $value, $other, $itemnumber,
57                $itemtype, $borrowernumber);
58
59 Adds a line to the statistics table of the Koha database. In effect,
60 it logs an event.
61
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.
65
66 =cut
67
68 #'
69 sub UpdateStats {
70
71     #module to insert stats data into stats table
72     my (
73         $branch,         $type,
74         $amount,   $other,          $itemnum,
75         $itemtype, $borrowernumber, $accountno
76       )
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(),?,?,?,?,?,?,?,?)"
82     );
83     $sth->execute(
84         $branch,    $type,    $amount,
85         $other,     $itemnum, $itemtype, $borrowernumber,
86                 $accountno
87     );
88     $sth->finish;
89 }
90
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()";
101     }
102     else {
103         $query .= " AND datetime > '$time'";
104     }
105     if ( $time2 ne '' ) {
106         $query .= " AND datetime < '$time2'";
107     }
108     if ($spreadsheet) {
109         $query .= " ORDER BY branch, type";
110     }
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;
117     }
118     $sth->finish;
119     return (@results);
120 }
121
122 1;
123 __END__
124
125 =back
126
127 =head1 AUTHOR
128
129 Koha Developement team <info@koha.org>
130
131 =cut
132