diff --git a/C4/Accounts2.pm b/C4/Accounts2.pm
index 85d255b0b0..18bad780b8 100755
--- a/C4/Accounts2.pm
+++ b/C4/Accounts2.pm
@@ -100,7 +100,7 @@ sub recordpayment{
my $usth = $dbh->prepare($updquery);
$usth->execute;
$usth->finish;
- UpdateStats($env,'branch','payment',$data);
+ UpdateStats($env,'branch','payment',$data,'','','',$bornumber);
$sth->finish;
$dbh->disconnect;
}
@@ -133,7 +133,7 @@ sub makepayment{
my $usth = $dbh->prepare($updquery);
$usth->execute;
$usth->finish;
- UpdateStats($env,$user,'payment',$amount);
+ UpdateStats($env,$user,'payment',$amount,'','','',$bornumber);
$sth->finish;
$dbh->disconnect;
}
diff --git a/C4/Stats.pm b/C4/Stats.pm
index 06fa8a3851..df504e3d66 100644
--- a/C4/Stats.pm
+++ b/C4/Stats.pm
@@ -53,14 +53,16 @@ my $priv_func = sub {
sub UpdateStats {
#module to insert stats data into stats table
- my ($env,$branch,$type,$amount,$other,$itemnum,$itemtype)=@_;
+ my ($env,$branch,$type,$amount,$other,$itemnum,$itemtype,$borrowernumber)=@_;
my $dbh=C4Connect();
my $branch=$env->{'branchcode'};
my $user = $env->{'usercode'};
+ print $borrowernumber;
my $sth=$dbh->prepare("Insert into statistics
- (datetime,branch,type,usercode,value,other,itemnumber,itemtype)
- values (now(),'$branch',
- '$type','$user','$amount','$other','$itemnum','$itemtype')");
+ (datetime,branch,type,usercode,value,
+ other,itemnumber,itemtype,borrowernumber)
+ values (now(),'$branch','$type','$user','$amount',
+ '$other','$itemnum','$itemtype','$borrowernumber')");
$sth->execute;
$sth->finish;
$dbh->disconnect;
@@ -145,14 +147,16 @@ sub TotalOwing{
sub TotalPaid {
my ($time)=@_;
my $dbh=C4Connect;
- my $query="Select * from accountlines,borrowers where accounttype = 'Pay'
- and accountlines.borrowernumber = borrowers.borrowernumber";
+ 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 date = now()";
+ $query=$query." and datetime = now()";
} else {
- $query.=" and date='$time'";
+ $query.=" and datetime > '$time'";
}
# $query.=" order by timestamp";
+ print $query;
my $sth=$dbh->prepare($query);
$sth->execute;
my @results;
@@ -172,18 +176,18 @@ sub getcharges{
my $dbh=C4Connect;
my $timestamp2=$timestamp-1;
my $query="Select * from accountlines where borrowernumber=$borrowerno
- and timestamp <= '$timestamp' and accounttype <> 'Pay' and
+ and timestamp = '$timestamp' and accounttype <> 'Pay' and
accounttype <> 'W'";
my $sth=$dbh->prepare($query);
-# print $query,"
";
+ print $query,"
";
$sth->execute;
my $i=0;
my @results;
while (my $data=$sth->fetchrow_hashref){
- if ($data->{'timestamp'} == $timestamp){
+# if ($data->{'timestamp'} == $timestamp){
$results[$i]=$data;
$i++;
- }
+# }
}
$dbh->disconnect;
return(@results);