File: | C4/Stats.pm |
Coverage: | 42.9% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
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 | |||||
18 | # with Koha; if not, write to the Free Software Foundation, Inc., | |||||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |||||
20 | ||||||
21 | 15 15 15 | 593 124 469 | use strict; | |||
22 | 15 15 15 | 175 130 760 | use warnings; | |||
23 | require Exporter; | |||||
24 | 15 15 15 | 331 95 244 | use C4::Context; | |||
25 | 15 15 15 | 144 82 1997 | use C4::Debug; | |||
26 | 15 15 15 | 167 71 1765 | use vars qw($VERSION @ISA @EXPORT); | |||
27 | ||||||
28 | our $debug; | |||||
29 | ||||||
30 | BEGIN { | |||||
31 | # set the version for version checking | |||||
32 | 15 | 142 | $VERSION = 3.01; | |||
33 | 15 | 316 | @ISA = qw(Exporter); | |||
34 | 15 | 4256 | @EXPORT = qw( | |||
35 | &UpdateStats | |||||
36 | &TotalPaid | |||||
37 | ); | |||||
38 | } | |||||
39 | ||||||
40 | ||||||
41 - 70 | =head1 NAME C4::Stats - Update Koha statistics (log) =head1 SYNOPSIS use C4::Stats; =head1 DESCRIPTION The C<&UpdateStats> function adds an entry to the statistics table in the Koha database, which acts as an activity log. =head1 FUNCTIONS =over 2 =item UpdateStats &UpdateStats($branch, $type, $value, $other, $itemnumber, $itemtype, $borrowernumber); Adds a line to the statistics table of the Koha database. In effect, it logs an event. C<$branch>, C<$type>, C<$value>, C<$other>, C<$itemnumber>, C<$itemtype>, and C<$borrowernumber> correspond to the fields of the statistics table in the Koha database. =cut | |||||
71 | ||||||
72 | #' | |||||
73 | sub UpdateStats { | |||||
74 | ||||||
75 | #module to insert stats data into stats table | |||||
76 | my ( | |||||
77 | 0 | $branch, $type, | ||||
78 | $amount, $other, $itemnum, | |||||
79 | $itemtype, $borrowernumber, $accountno | |||||
80 | ) | |||||
81 | = @_; | |||||
82 | 0 | my $dbh = C4::Context->dbh; | ||||
83 | 0 | my $sth = $dbh->prepare( | ||||
84 | "INSERT INTO statistics | |||||
85 | (datetime, branch, type, value, | |||||
86 | other, itemnumber, itemtype, borrowernumber, proccode) | |||||
87 | VALUES (now(),?,?,?,?,?,?,?,?)" | |||||
88 | ); | |||||
89 | 0 | $sth->execute( | ||||
90 | $branch, $type, $amount, | |||||
91 | $other, $itemnum, $itemtype, $borrowernumber, | |||||
92 | $accountno | |||||
93 | ); | |||||
94 | } | |||||
95 | ||||||
96 | # Otherwise, it'd need a POD. | |||||
97 | sub TotalPaid { | |||||
98 | 0 | my ( $time, $time2, $spreadsheet ) = @_; | ||||
99 | 0 | $time2 = $time unless $time2; | ||||
100 | 0 | my $dbh = C4::Context->dbh; | ||||
101 | 0 | my $query = "SELECT * FROM statistics | ||||
102 | LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber | |||||
103 | WHERE (statistics.type='payment' OR statistics.type='writeoff') "; | |||||
104 | 0 | if ( $time eq 'today' ) { | ||||
105 | 0 | $query .= " AND datetime = now()"; | ||||
106 | } else { | |||||
107 | 0 | $query .= " AND datetime > '$time'"; # FIXME: use placeholders | ||||
108 | } | |||||
109 | 0 | if ( $time2 ne '' ) { | ||||
110 | 0 | $query .= " AND datetime < '$time2'"; # FIXME: use placeholders | ||||
111 | } | |||||
112 | 0 | if ($spreadsheet) { | ||||
113 | 0 | $query .= " ORDER BY branch, type"; | ||||
114 | } | |||||
115 | 0 | $debug and warn "TotalPaid query: $query"; | ||||
116 | 0 | my $sth = $dbh->prepare($query); | ||||
117 | 0 | $sth->execute(); | ||||
118 | 0 0 | return @{$sth->fetchall_arrayref({})}; | ||||
119 | } | |||||
120 | ||||||
121 | 1; |