1 package C4::Stats; #asummes C4/Stats
3 #requires DBI.pm to be installed
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12 # set the version for version checking
16 @EXPORT = qw(&UpdateStats &statsreport &Count &Overdues &TotalOwing
17 &TotalPaid &getcharges &Getpaidbranch &unfilledreserves);
18 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
20 # your exported package globals go here,
21 # as well as any optionally exported functions
23 @EXPORT_OK = qw($Var1 %Hashit);
26 # non-exported package globals go here
27 use vars qw(@more $stuff);
29 # initalize package globals, first exported ones
35 # then the others (which are still accessible as $Some::Module::stuff)
39 # all file-scoped lexicals must be created before
40 # the functions below that use them.
42 # file-private lexicals go here
46 # here's a file-private function as a closure,
47 # callable as &$priv_func; it cannot be prototyped.
52 # make all your functions, whether exported or not;
55 #module to insert stats data into stats table
56 my ($env,$branch,$type,$amount,$other,$itemnum,$itemtype)=@_;
58 my $branch=$env->{'branchcode'};
59 my $user = $env->{'usercode'};
60 my $sth=$dbh->prepare("Insert into statistics
61 (datetime,branch,type,usercode,value,other,itemnumber,itemtype)
62 values (now(),'$branch',
63 '$type','$user','$amount','$other','$itemnum','$itemtype')");
70 #module to return a list of stats for a given day,time,branch type
71 #or to return search stats
75 # if ($type eq 'issue'){
76 @data=circrep($time,$type);
84 my $query="Select * from statistics";
85 if ($time eq 'today'){
86 $query=$query." where type='$type' and datetime
87 >=datetime('yesterday'::date)";
89 my $sth=$dbh->prepare($query);
93 while (my $data=$sth->fetchrow_hashref){
94 $results[$i]="$data->{'datetime'}\t$data->{'branch'}";
105 my ($type,$branch,$time,$time2)=@_;
107 my $query="Select count(*) from statistics where type='$type'";
108 $query.=" and datetime >= '$time' and datetime< '$time2' and branch='$branch'";
109 my $sth=$dbh->prepare($query);
111 my $data=$sth->fetchrow_hashref;
115 return($data->{'count(*)'});
120 my $query="Select count(*) from issues where date_due >= now()";
121 my $sth=$dbh->prepare($query);
123 my $count=$sth->fetchrow_hashref;
126 return($count->{'count(*)'});
132 my $query="Select sum(amountoutstanding) from accountlines";
133 if ($type eq 'fine'){
134 $query=$query." where accounttype='F' or accounttype='FN'";
136 my $sth=$dbh->prepare($query);
139 my $total=$sth->fetchrow_hashref;
142 return($total->{'sum(amountoutstanding)'});
148 my $query="Select * from accountlines,borrowers where accounttype = 'Pay'
149 and accountlines.borrowernumber = borrowers.borrowernumber";
150 if ($time eq 'today'){
151 $query=$query." and date = now()";
153 $query.=" and date='$time'";
155 # $query.=" order by timestamp";
156 my $sth=$dbh->prepare($query);
160 while (my $data=$sth->fetchrow_hashref){
171 my($borrowerno,$timestamp)=@_;
173 my $timestamp2=$timestamp-1;
174 my $query="Select * from accountlines where borrowernumber=$borrowerno
175 and timestamp <= '$timestamp' and accounttype <> 'Pay' and
177 my $sth=$dbh->prepare($query);
178 # print $query,"<br>";
182 while (my $data=$sth->fetchrow_hashref){
183 if ($data->{'timestamp'} == $timestamp){
195 my $query="select * from statistics where type='payment' and datetime='$date'";
196 my $sth=$dbh->prepare($query);
199 my $data=$sth->fetchrow_hashref;
202 return($data->{'branch'});
205 sub unfilledreserves {
207 my $query="select *,biblio.title from reserves,reserveconstraints,biblio,borrowers,biblioitems where found <> 'F' and cancellationdate
208 is NULL and biblio.biblionumber=reserves.biblionumber and
209 reserves.constrainttype='o'
210 and (reserves.biblionumber=reserveconstraints.biblionumber
211 and reserves.borrowernumber=reserveconstraints.borrowernumber)
213 reserves.borrowernumber=borrowers.borrowernumber and
214 biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
215 biblio.title,reserves.reservedate";
216 my $sth=$dbh->prepare($query);
220 while (my $data=$sth->fetchrow_hashref){
225 $query="select *,biblio.title from reserves,biblio,borrowers where found <> 'F' and cancellationdate
226 is NULL and biblio.biblionumber=reserves.biblionumber and reserves.constrainttype='a' and
227 reserves.borrowernumber=borrowers.borrowernumber
229 biblio.title,reserves.reservedate";
230 $sth=$dbh->prepare($query);
232 while (my $data=$sth->fetchrow_hashref){
238 return($i,\@results);
241 END { } # module clean-up code here (global destructor)