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,$borrowernumber)=@_;
58 my $branch=$env->{'branchcode'};
59 my $user = $env->{'usercode'};
60 print $borrowernumber;
61 my $sth=$dbh->prepare("Insert into statistics
62 (datetime,branch,type,usercode,value,
63 other,itemnumber,itemtype,borrowernumber)
64 values (now(),'$branch','$type','$user','$amount',
65 '$other','$itemnum','$itemtype','$borrowernumber')");
72 #module to return a list of stats for a given day,time,branch type
73 #or to return search stats
77 # if ($type eq 'issue'){
78 @data=circrep($time,$type);
86 my $query="Select * from statistics";
87 if ($time eq 'today'){
88 $query=$query." where type='$type' and datetime
89 >=datetime('yesterday'::date)";
91 my $sth=$dbh->prepare($query);
95 while (my $data=$sth->fetchrow_hashref){
96 $results[$i]="$data->{'datetime'}\t$data->{'branch'}";
107 my ($type,$branch,$time,$time2)=@_;
109 my $query="Select count(*) from statistics where type='$type'";
110 $query.=" and datetime >= '$time' and datetime< '$time2' and branch='$branch'";
111 my $sth=$dbh->prepare($query);
113 my $data=$sth->fetchrow_hashref;
117 return($data->{'count(*)'});
122 my $query="Select count(*) from issues where date_due >= now()";
123 my $sth=$dbh->prepare($query);
125 my $count=$sth->fetchrow_hashref;
128 return($count->{'count(*)'});
134 my $query="Select sum(amountoutstanding) from accountlines";
135 if ($type eq 'fine'){
136 $query=$query." where accounttype='F' or accounttype='FN'";
138 my $sth=$dbh->prepare($query);
141 my $total=$sth->fetchrow_hashref;
144 return($total->{'sum(amountoutstanding)'});
150 my $query="Select * from statistics,borrowers
151 where statistics.borrowernumber= borrowers.borrowernumber
152 and (statistics.type='payment' or statistics.type='writeoff')";
153 if ($time eq 'today'){
154 $query=$query." and datetime = now()";
156 $query.=" and datetime > '$time'";
158 # $query.=" order by timestamp";
160 my $sth=$dbh->prepare($query);
164 while (my $data=$sth->fetchrow_hashref){
175 my($borrowerno,$timestamp)=@_;
177 my $timestamp2=$timestamp-1;
178 my $query="Select * from accountlines where borrowernumber=$borrowerno
179 and timestamp = '$timestamp' and accounttype <> 'Pay' and
181 my $sth=$dbh->prepare($query);
186 while (my $data=$sth->fetchrow_hashref){
187 # if ($data->{'timestamp'} == $timestamp){
199 my $query="select * from statistics where type='payment' and datetime='$date'";
200 my $sth=$dbh->prepare($query);
203 my $data=$sth->fetchrow_hashref;
206 return($data->{'branch'});
209 sub unfilledreserves {
211 my $query="select *,biblio.title from reserves,reserveconstraints,biblio,borrowers,biblioitems where found <> 'F' and cancellationdate
212 is NULL and biblio.biblionumber=reserves.biblionumber and
213 reserves.constrainttype='o'
214 and (reserves.biblionumber=reserveconstraints.biblionumber
215 and reserves.borrowernumber=reserveconstraints.borrowernumber)
217 reserves.borrowernumber=borrowers.borrowernumber and
218 biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
219 biblio.title,reserves.reservedate";
220 my $sth=$dbh->prepare($query);
224 while (my $data=$sth->fetchrow_hashref){
229 $query="select *,biblio.title from reserves,biblio,borrowers where found <> 'F' and cancellationdate
230 is NULL and biblio.biblionumber=reserves.biblionumber and reserves.constrainttype='a' and
231 reserves.borrowernumber=borrowers.borrowernumber
233 biblio.title,reserves.reservedate";
234 $sth=$dbh->prepare($query);
236 while (my $data=$sth->fetchrow_hashref){
242 return($i,\@results);
245 END { } # module clean-up code here (global destructor)