5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
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
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.
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
26 use vars qw($VERSION @ISA @EXPORT);
28 # set the version for version checking
33 C4::Stats - Update Koha statistics (log)
41 The C<&UpdateStats> function adds an entry to the statistics table in
42 the Koha database, which acts as an activity log.
51 @EXPORT = qw(&UpdateStats &statsreport &TotalOwing
52 &TotalPaid &getcharges &Getpaidbranch &unfilledreserves &getcredits);
56 &UpdateStats($env, $branch, $type, $value, $other, $itemnumber,
57 $itemtype, $borrowernumber);
59 Adds a line to the statistics table of the Koha database. In effect,
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 If C<$branch> is the empty string, the branch code will be taken from
67 C<$env-E<gt>{branchcode}>.
69 C<$env-E<gt>{usercode}> specifies the value of the C<usercode> field.
74 #module to insert stats data into stats table
75 my ($env,$branch,$type,$amount,$other,$itemnum,$itemtype,$borrowernumber,$accountno)=@_;
76 my $dbh = C4::Context->dbh;
78 $branch=$env->{'branchcode'};
80 my $user = $env->{'usercode'};
81 print $borrowernumber;
82 # FIXME - Use $dbh->do() instead
83 my $sth=$dbh->prepare("Insert into statistics (datetime,branch,type,usercode,value,
84 other,itemnumber,itemtype,borrowernumber,proccode) values (now(),?,?,?,?,?,?,?,?,?)");
85 $sth->execute($branch,$type,$user,$amount,$other,$itemnum,$itemtype,$borrowernumber,$accountno);
89 # Otherwise, it'd need a POD.
92 $time2=$time unless $time2;
93 my $dbh = C4::Context->dbh;
96 #my $query="Select * from accountlines,borrowers where (accounttype = 'Pay' or accounttype ='W')
97 # and accountlines.borrowernumber = borrowers.borrowernumber";
99 #if ($time eq 'today'){
100 # $query .= " and date = now()";
102 # $query.=" and date>=? and date<=?";
103 # @bind = ($time,$time2);
106 my $query="Select * from statistics,borrowers
107 where statistics.borrowernumber= borrowers.borrowernumber
108 and (statistics.type='payment' or statistics.type='writeoff') ";
109 if ($time eq 'today'){
110 $query=$query." and datetime = now()";
112 $query.=" and datetime > '$time'";
116 # $query.=" order by timestamp";
120 my $sth=$dbh->prepare($query);
123 # $sth->execute(@bind);
126 while (my $data=$sth->fetchrow_hashref){
135 # Otherwise, it needs a POD.
137 my($borrowerno,$timestamp,$accountno)=@_;
138 my $dbh = C4::Context->dbh;
139 my $timestamp2=$timestamp-1;
143 # getcharges is now taking accountno. as an argument
145 $sth=$dbh->prepare("Select * from accountlines where borrowernumber=?
147 $sth->execute($borrowerno,$accountno);
149 # this bit left in for old 2 arg usage of getcharges
151 $sth=$dbh->prepare("Select * from accountlines where borrowernumber=?
152 and timestamp = ? and accounttype <> 'Pay' and
153 accounttype <> 'W'");
154 $sth->execute($borrowerno,$timestamp);
157 # print $query,"<br>";
160 while (my $data=$sth->fetchrow_hashref){
161 # if ($data->{'timestamp'} == $timestamp){
169 # Otherwise, it needs a POD.
171 my ($date,$date2)=@_;
172 my $dbh = C4::Context->dbh;
174 #takes date converts to timestamps
175 my $padding="000000";
176 (my $a, my $b, my $c) = unpack("A4 x1 A2 x1 A2", $date);
177 (my $x, my $y, my $z) = unpack("A4 x1 A2 x1 A2", $date2);
178 my $timestamp = $a.$b.$c.$padding;
179 my $timestamp2 = $x.$y.$z.$padding;
181 my $sth=$dbh->prepare("Select * from accountlines,borrowers where (((accounttype = 'LR') or (accounttype <> 'Pay'))
182 and amount < 0 and accountlines.borrowernumber = borrowers.borrowernumber
183 and timestamp >=? and timestamp <?)");
184 $sth->execute($timestamp, $timestamp2);
188 while (my $data=$sth->fetchrow_hashref){
197 # Otherwise, this needs a POD.
199 my($date,$borrno)=@_;
200 my $dbh = C4::Context->dbh;
201 my $sth=$dbh->prepare("select * from statistics where type='payment' and datetime >? and borrowernumber=?");
202 $sth->execute($date,$borrno);
204 my $data=$sth->fetchrow_hashref;
206 return($data->{'branch'});
209 # FIXME - This is only used in reservereport.pl and reservereport.xls,
210 # neither of which is used.
211 # Otherwise, it needs a POD.
212 sub unfilledreserves {
213 my $dbh = C4::Context->dbh;
214 my $sth=$dbh->prepare("select *,biblio.title from reserves,reserveconstraints,biblio,borrowers,biblioitems where (found <> 'F' or
215 found is NULL) and cancellationdate
216 is NULL and biblio.biblionumber=reserves.biblionumber and
217 reserves.constrainttype='o'
218 and (reserves.biblionumber=reserveconstraints.biblionumber
219 and reserves.borrowernumber=reserveconstraints.borrowernumber)
221 reserves.borrowernumber=borrowers.borrowernumber and
222 biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
223 biblio.title,reserves.reservedate");
227 while (my $data=$sth->fetchrow_hashref){
232 $sth=$dbh->prepare("select *,biblio.title from reserves,biblio,borrowers where (found <> 'F' or found is NULL) and cancellationdate
233 is NULL and biblio.biblionumber=reserves.biblionumber and reserves.constrainttype='a' and
234 reserves.borrowernumber=borrowers.borrowernumber
236 biblio.title,reserves.reservedate");
238 while (my $data=$sth->fetchrow_hashref){
243 return($i,\@results);
253 Koha Developement team <info@koha.org>