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);
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)=@_;
76 my $dbh = C4::Context->dbh;
78 $branch=$env->{'branchcode'};
80 my $user = $env->{'usercode'};
81 # FIXME - Use $dbh->do() instead
82 my $sth=$dbh->prepare("Insert into statistics (datetime,branch,type,usercode,value,
83 other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?,?)");
84 $sth->execute($branch,$type,$user,$amount,$other,$itemnum,$itemtype,$borrowernumber);
88 # Otherwise, it'd need a POD.
91 $time2=$time unless $time2;
92 my $dbh = C4::Context->dbh;
93 my $query="Select * from accountlines,borrowers where (accounttype = 'Pay' or accounttype ='W')
94 and accountlines.borrowernumber = borrowers.borrowernumber";
96 if ($time eq 'today'){
97 $query .= " and date = now()";
99 $query.=" and date>=? and date<=?";
100 @bind = ($time,$time2);
102 # my $query="Select * from statistics,borrowers
103 # where statistics.borrowernumber= borrowers.borrowernumber
104 # and (statistics.type='payment' or statistics.type='writeoff') ";
105 # if ($time eq 'today'){
106 # $query=$query." and datetime = now()";
108 # $query.=" and datetime > '$time'";
110 $query.=" order by timestamp";
112 my $sth=$dbh->prepare($query);
113 $sth->execute(@bind);
116 while (my $data=$sth->fetchrow_hashref){
125 # Otherwise, it needs a POD.
127 my($borrowerno,$timestamp)=@_;
128 my $dbh = C4::Context->dbh;
129 my $timestamp2=$timestamp-1;
131 my $sth=$dbh->prepare("Select * from accountlines where borrowernumber=?
132 and timestamp = ? and accounttype <> 'Pay' and
133 accounttype <> 'W'");
134 # print $query,"<br>";
135 $sth->execute($borrowerno,$timestamp);
138 while (my $data=$sth->fetchrow_hashref){
139 # if ($data->{'timestamp'} == $timestamp){
147 # Otherwise, this needs a POD.
149 my($date,$borrno)=@_;
150 my $dbh = C4::Context->dbh;
151 my $sth=$dbh->prepare("select * from statistics where type='payment' and datetime >? and borrowernumber=?");
152 $sth->execute($date,$borrno);
154 my $data=$sth->fetchrow_hashref;
156 return($data->{'branch'});
159 # FIXME - This is only used in reservereport.pl and reservereport.xls,
160 # neither of which is used.
161 # Otherwise, it needs a POD.
162 sub unfilledreserves {
163 my $dbh = C4::Context->dbh;
164 my $sth=$dbh->prepare("select *,biblio.title from reserves,reserveconstraints,biblio,borrowers,biblioitems where found <> 'F' and cancellationdate
165 is NULL and biblio.biblionumber=reserves.biblionumber and
166 reserves.constrainttype='o'
167 and (reserves.biblionumber=reserveconstraints.biblionumber
168 and reserves.borrowernumber=reserveconstraints.borrowernumber)
170 reserves.borrowernumber=borrowers.borrowernumber and
171 biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
172 biblio.title,reserves.reservedate");
176 while (my $data=$sth->fetchrow_hashref){
181 $sth=$dbh->prepare("select *,biblio.title from reserves,biblio,borrowers where found <> 'F' and cancellationdate
182 is NULL and biblio.biblionumber=reserves.biblionumber and reserves.constrainttype='a' and
183 reserves.borrowernumber=borrowers.borrowernumber
185 biblio.title,reserves.reservedate");
187 while (my $data=$sth->fetchrow_hashref){
192 return($i,\@results);
202 Koha Developement team <info@koha.org>