- my ($time)=@_;
- my $dbh = C4::Context->dbh;
- my $query="Select * from accountlines,borrowers where (accounttype = 'Pay'
-or accounttype ='W')
- and accountlines.borrowernumber = borrowers.borrowernumber";
- if ($time eq 'today'){
- $query=$query." and date = now()"; # FIXME - .=
- } else {
- $query.=" and date='$time'";
- }
-# my $query="Select * from statistics,borrowers
-# where statistics.borrowernumber= borrowers.borrowernumber
-# and (statistics.type='payment' or statistics.type='writeoff') ";
-# if ($time eq 'today'){
-# $query=$query." and datetime = now()";
-# } else {
-# $query.=" and datetime > '$time'";
-# }
- $query.=" order by timestamp";
-# print $query;
- my $sth=$dbh->prepare($query);
- $sth->execute;
- my @results;
- my $i=0;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
- $i++;
- }
- $sth->finish;
-# print $query;
- return(@results);
-}
-
-# FIXME - Only used in stats.pl, which in turn is never used.
-# Otherwise, it needs a POD.
-sub getcharges{
- my($borrowerno,$timestamp)=@_;
- my $dbh = C4::Context->dbh;
- my $timestamp2=$timestamp-1;
- my $query="Select * from accountlines where borrowernumber=$borrowerno
- and timestamp = '$timestamp' and accounttype <> 'Pay' and
- accounttype <> 'W'";
- my $sth=$dbh->prepare($query);
-# print $query,"<br>";
- $sth->execute;
- my $i=0;
- my @results;
- while (my $data=$sth->fetchrow_hashref){
-# if ($data->{'timestamp'} == $timestamp){
- $results[$i]=$data;
- $i++;
-# }
- }
- return(@results);
-}
-
-# This is only used in stats.pl and stats2.pl, neither of which is
-# used.
-# Otherwise, this needs a POD.
-sub Getpaidbranch{
- my($date,$borrno)=@_;
- my $dbh = C4::Context->dbh;
- my $query="select * from statistics where type='payment' and datetime
- >'$date' and borrowernumber='$borrno'";
- my $sth=$dbh->prepare($query);
- $sth->execute;
-# print $query;
- my $data=$sth->fetchrow_hashref;
- $sth->finish;
- return($data->{'branch'});
-}
-
-# FIXME - This is only used in reservereport.pl and reservereport.xls,
-# neither of which is used.
-# Otherwise, it needs a POD.
-sub unfilledreserves {
- my $dbh = C4::Context->dbh;
- my $query="select *,biblio.title from reserves,reserveconstraints,biblio,borrowers,biblioitems where found <> 'F' and cancellationdate
-is NULL and biblio.biblionumber=reserves.biblionumber and
-reserves.constrainttype='o'
-and (reserves.biblionumber=reserveconstraints.biblionumber
-and reserves.borrowernumber=reserveconstraints.borrowernumber)
-and
-reserves.borrowernumber=borrowers.borrowernumber and
-biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
-biblio.title,reserves.reservedate";
- my $sth=$dbh->prepare($query);
- $sth->execute;
- my $i=0;
- my @results;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
- $i++;
- }
- $sth->finish;
- $query="select *,biblio.title from reserves,biblio,borrowers where found <> 'F' and cancellationdate
-is NULL and biblio.biblionumber=reserves.biblionumber and reserves.constrainttype='a' and
-reserves.borrowernumber=borrowers.borrowernumber
-order by
-biblio.title,reserves.reservedate";
- $sth=$dbh->prepare($query);
- $sth->execute;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
- $i++;
- }
- $sth->finish;
- return($i,\@results);
+ my ( $time, $time2, $spreadsheet ) = @_;
+ $time2 = $time unless $time2;
+ my $dbh = C4::Context->dbh;
+ my $query = "SELECT * FROM statistics
+ LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber
+ WHERE (statistics.type='payment' OR statistics.type='writeoff') ";
+ if ( $time eq 'today' ) {
+ $query .= " AND datetime = now()";
+ } else {
+ $query .= " AND datetime > '$time'"; # FIXME: use placeholders
+ }
+ if ( $time2 ne '' ) {
+ $query .= " AND datetime < '$time2'"; # FIXME: use placeholders
+ }
+ if ($spreadsheet) {
+ $query .= " ORDER BY branch, type";
+ }
+ $debug and warn "TotalPaid query: $query";
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ return @{$sth->fetchall_arrayref({})};