1 package C4::Stats; #assumes C4/Stats
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 # set the version for version checking
13 @EXPORT = qw(&UpdateStats &statsreport &Count &Overdues &TotalOwing
14 &TotalPaid &getcharges &Getpaidbranch &unfilledreserves);
18 #module to insert stats data into stats table
19 my ($env,$branch,$type,$amount,$other,$itemnum,$itemtype,$borrowernumber)=@_;
22 $branch=$env->{'branchcode'};
24 my $user = $env->{'usercode'};
25 print $borrowernumber;
26 my $sth=$dbh->prepare("Insert into statistics
27 (datetime,branch,type,usercode,value,
28 other,itemnumber,itemtype,borrowernumber)
29 values (now(),'$branch','$type','$user','$amount',
30 '$other','$itemnum','$itemtype','$borrowernumber')");
37 #module to return a list of stats for a given day,time,branch type
38 #or to return search stats
42 # if ($type eq 'issue'){
43 @data=circrep($time,$type);
51 my $query="Select * from statistics";
52 if ($time eq 'today'){
53 $query=$query." where type='$type' and datetime
54 >=datetime('yesterday'::date)";
56 my $sth=$dbh->prepare($query);
60 while (my $data=$sth->fetchrow_hashref){
61 $results[$i]="$data->{'datetime'}\t$data->{'branch'}";
72 my ($type,$branch,$time,$time2)=@_;
74 my $query="Select count(*) from statistics where type='$type'";
75 $query.=" and datetime >= '$time' and datetime< '$time2' and branch='$branch'";
76 my $sth=$dbh->prepare($query);
78 my $data=$sth->fetchrow_hashref;
82 return($data->{'count(*)'});
87 my $query="Select count(*) from issues where date_due >= now()";
88 my $sth=$dbh->prepare($query);
90 my $count=$sth->fetchrow_hashref;
93 return($count->{'count(*)'});
99 my $query="Select sum(amountoutstanding) from accountlines";
100 if ($type eq 'fine'){
101 $query=$query." where accounttype='F' or accounttype='FN'";
103 my $sth=$dbh->prepare($query);
106 my $total=$sth->fetchrow_hashref;
109 return($total->{'sum(amountoutstanding)'});
115 my $query="Select * from accountlines,borrowers where (accounttype = 'Pay'
117 and accountlines.borrowernumber = borrowers.borrowernumber";
118 if ($time eq 'today'){
119 $query=$query." and date = now()";
121 $query.=" and date='$time'";
123 # my $query="Select * from statistics,borrowers
124 # where statistics.borrowernumber= borrowers.borrowernumber
125 # and (statistics.type='payment' or statistics.type='writeoff') ";
126 # if ($time eq 'today'){
127 # $query=$query." and datetime = now()";
129 # $query.=" and datetime > '$time'";
131 $query.=" order by timestamp";
133 my $sth=$dbh->prepare($query);
137 while (my $data=$sth->fetchrow_hashref){
148 my($borrowerno,$timestamp)=@_;
150 my $timestamp2=$timestamp-1;
151 my $query="Select * from accountlines where borrowernumber=$borrowerno
152 and timestamp = '$timestamp' and accounttype <> 'Pay' and
154 my $sth=$dbh->prepare($query);
155 # print $query,"<br>";
159 while (my $data=$sth->fetchrow_hashref){
160 # if ($data->{'timestamp'} == $timestamp){
170 my($date,$borrno)=@_;
172 my $query="select * from statistics where type='payment' and datetime
173 >'$date' and borrowernumber='$borrno'";
174 my $sth=$dbh->prepare($query);
177 my $data=$sth->fetchrow_hashref;
180 return($data->{'branch'});
183 sub unfilledreserves {
185 my $query="select *,biblio.title from reserves,reserveconstraints,biblio,borrowers,biblioitems where found <> 'F' and cancellationdate
186 is NULL and biblio.biblionumber=reserves.biblionumber and
187 reserves.constrainttype='o'
188 and (reserves.biblionumber=reserveconstraints.biblionumber
189 and reserves.borrowernumber=reserveconstraints.borrowernumber)
191 reserves.borrowernumber=borrowers.borrowernumber and
192 biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
193 biblio.title,reserves.reservedate";
194 my $sth=$dbh->prepare($query);
198 while (my $data=$sth->fetchrow_hashref){
203 $query="select *,biblio.title from reserves,biblio,borrowers where found <> 'F' and cancellationdate
204 is NULL and biblio.biblionumber=reserves.biblionumber and reserves.constrainttype='a' and
205 reserves.borrowernumber=borrowers.borrowernumber
207 biblio.title,reserves.reservedate";
208 $sth=$dbh->prepare($query);
210 while (my $data=$sth->fetchrow_hashref){
216 return($i,\@results);
219 END { } # module clean-up code here (global destructor)