Modified the update stats routine to store borrowernumbers also

Passing borrowernumbers to update stats from Account routines
This commit is contained in:
rangi 2001-03-27 21:43:37 +00:00
parent c2a70e1811
commit e295b51570
2 changed files with 18 additions and 14 deletions

View file

@ -100,7 +100,7 @@ sub recordpayment{
my $usth = $dbh->prepare($updquery); my $usth = $dbh->prepare($updquery);
$usth->execute; $usth->execute;
$usth->finish; $usth->finish;
UpdateStats($env,'branch','payment',$data); UpdateStats($env,'branch','payment',$data,'','','',$bornumber);
$sth->finish; $sth->finish;
$dbh->disconnect; $dbh->disconnect;
} }
@ -133,7 +133,7 @@ sub makepayment{
my $usth = $dbh->prepare($updquery); my $usth = $dbh->prepare($updquery);
$usth->execute; $usth->execute;
$usth->finish; $usth->finish;
UpdateStats($env,$user,'payment',$amount); UpdateStats($env,$user,'payment',$amount,'','','',$bornumber);
$sth->finish; $sth->finish;
$dbh->disconnect; $dbh->disconnect;
} }

View file

@ -53,14 +53,16 @@ my $priv_func = sub {
sub UpdateStats { sub UpdateStats {
#module to insert stats data into stats table #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 $dbh=C4Connect();
my $branch=$env->{'branchcode'}; my $branch=$env->{'branchcode'};
my $user = $env->{'usercode'}; my $user = $env->{'usercode'};
print $borrowernumber;
my $sth=$dbh->prepare("Insert into statistics my $sth=$dbh->prepare("Insert into statistics
(datetime,branch,type,usercode,value,other,itemnumber,itemtype) (datetime,branch,type,usercode,value,
values (now(),'$branch', other,itemnumber,itemtype,borrowernumber)
'$type','$user','$amount','$other','$itemnum','$itemtype')"); values (now(),'$branch','$type','$user','$amount',
'$other','$itemnum','$itemtype','$borrowernumber')");
$sth->execute; $sth->execute;
$sth->finish; $sth->finish;
$dbh->disconnect; $dbh->disconnect;
@ -145,14 +147,16 @@ sub TotalOwing{
sub TotalPaid { sub TotalPaid {
my ($time)=@_; my ($time)=@_;
my $dbh=C4Connect; my $dbh=C4Connect;
my $query="Select * from accountlines,borrowers where accounttype = 'Pay' my $query="Select * from statistics,borrowers
and accountlines.borrowernumber = borrowers.borrowernumber"; where statistics.borrowernumber= borrowers.borrowernumber
and (statistics.type='payment' or statistics.type='writeoff')";
if ($time eq 'today'){ if ($time eq 'today'){
$query=$query." and date = now()"; $query=$query." and datetime = now()";
} else { } else {
$query.=" and date='$time'"; $query.=" and datetime > '$time'";
} }
# $query.=" order by timestamp"; # $query.=" order by timestamp";
print $query;
my $sth=$dbh->prepare($query); my $sth=$dbh->prepare($query);
$sth->execute; $sth->execute;
my @results; my @results;
@ -172,18 +176,18 @@ sub getcharges{
my $dbh=C4Connect; my $dbh=C4Connect;
my $timestamp2=$timestamp-1; my $timestamp2=$timestamp-1;
my $query="Select * from accountlines where borrowernumber=$borrowerno my $query="Select * from accountlines where borrowernumber=$borrowerno
and timestamp <= '$timestamp' and accounttype <> 'Pay' and and timestamp = '$timestamp' and accounttype <> 'Pay' and
accounttype <> 'W'"; accounttype <> 'W'";
my $sth=$dbh->prepare($query); my $sth=$dbh->prepare($query);
# print $query,"<br>"; print $query,"<br>";
$sth->execute; $sth->execute;
my $i=0; my $i=0;
my @results; my @results;
while (my $data=$sth->fetchrow_hashref){ while (my $data=$sth->fetchrow_hashref){
if ($data->{'timestamp'} == $timestamp){ # if ($data->{'timestamp'} == $timestamp){
$results[$i]=$data; $results[$i]=$data;
$i++; $i++;
} # }
} }
$dbh->disconnect; $dbh->disconnect;
return(@results); return(@results);