Boolean.pm - BEGIN block VERSION and vars related to export.
[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 # set the version for version checking
27 $VERSION = 3.00;
28
29 =head1 NAME
30
31 C4::Stats - Update Koha statistics (log)
32
33 =head1 SYNOPSIS
34
35   use C4::Stats;
36
37 =head1 DESCRIPTION
38
39 The C<&UpdateStats> function adds an entry to the statistics table in
40 the Koha database, which acts as an activity log.
41
42 =head1 FUNCTIONS
43
44 =over 2
45
46 =cut
47
48 @ISA    = qw(Exporter);
49 @EXPORT = qw(
50     &UpdateStats
51     &TotalPaid
52 );
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
76       )
77       = @_;
78     my $dbh = C4::Context->dbh;
79     # FIXME - Use $dbh->do() instead
80     my $sth = $dbh->prepare(
81         "Insert into statistics (datetime,branch,type,value,
82                                         other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?)"
83     );
84     $sth->execute(
85         $branch,    $type,    $amount,
86         $other,     $itemnum, $itemtype, $borrowernumber,
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     $sth->execute();
113     my @results;
114     while ( my $data = $sth->fetchrow_hashref ) {
115         push @results, $data;
116     }
117     $sth->finish;
118     return (@results);
119 }
120
121 1;
122 __END__
123
124 =back
125
126 =head1 AUTHOR
127
128 Koha Developement team <info@koha.org>
129
130 =cut
131