add option to unapply payments
[freeside.git] / FS / FS / cust_svc.pm
index 50d9445..211b0ad 100644 (file)
@@ -373,6 +373,8 @@ sub seconds_since_sqlradacct {
            "; guessing how to convert to UNIX timestamps";
       $str2time = 'extract(epoch from ';
     }
+
+    my $query;
   
     #find closed sessions completely within the given range
     my $sth = $dbh->prepare("SELECT SUM(acctsessiontime)
@@ -380,23 +382,23 @@ sub seconds_since_sqlradacct {
                                WHERE UserName = ?
                                  AND $str2time AcctStartTime) >= ?
                                  AND $str2time AcctStopTime ) <  ?
-                                 AND AcctStopTime =! 0
+                                 AND $str2time AcctStopTime ) > 0
                                  AND AcctStopTime IS NOT NULL"
     ) or die $dbh->errstr;
     $sth->execute($username, $start, $end) or die $sth->errstr;
     my $regular = $sth->fetchrow_arrayref->[0];
   
     #find open sessions which start in the range, count session start->range end
-    # don't count them if they are over 1 day old (probably missing stop record)
-    $sth = $dbh->prepare("SELECT SUM( ? - $str2time AcctStartTime ) )
-                            FROM radacct
-                            WHERE UserName = ?
-                              AND $str2time AcctStartTime ) >= ?
-                              AND ( ? - $str2time AcctStartTime ) < 86400
-                              AND (    AcctStopTime = 0
-                                    OR AcctStopTime IS NULL )"
-    ) or die $dbh->errstr;
-    $sth->execute($end, $username, $start, $end) or die $sth->errstr;
+    $query = "SELECT SUM( ? - $str2time AcctStartTime ) )
+                FROM radacct
+                WHERE UserName = ?
+                  AND $str2time AcctStartTime ) >= ?
+                  AND ( ? - $str2time AcctStartTime ) ) < 86400
+                  AND (    $str2time AcctStopTime ) = 0
+                                    OR AcctStopTime IS NULL )";
+    $sth = $dbh->prepare($query) or die $dbh->errstr;
+    $sth->execute($end, $username, $start, $end)
+      or die $sth->errstr. " executing query $query";
     my $start_during = $sth->fetchrow_arrayref->[0];
   
     #find closed sessions which start before the range but stop during,
@@ -407,7 +409,7 @@ sub seconds_since_sqlradacct {
                               AND $str2time AcctStartTime ) < ?
                               AND $str2time AcctStopTime  ) >= ?
                               AND $str2time AcctStopTime  ) <  ?
-                              AND AcctStopTime != 0
+                              AND $str2time AcctStopTime ) > 0
                               AND AcctStopTime IS NOT NULL"
     ) or die $dbh->errstr;
     $sth->execute($start, $username, $start, $start, $end ) or die $sth->errstr;
@@ -438,10 +440,6 @@ sub seconds_since_sqlradacct {
 
 =back
 
-=head1 VERSION
-
-$Id: cust_svc.pm,v 1.19 2002-10-17 14:16:17 ivan Exp $
-
 =head1 BUGS
 
 Behaviour of changing the svcpart of cust_svc records is undefined and should