- foreach my $did ( @dids ) {
- my $svcnum = $did->svcnum;
- next unless $svcnum;
-
- my $sql = "select count(1) from cdr where src =
- (select phonenum from svc_phone where svcnum = $svcnum)
- or charged_party = (select phonenum from svc_phone where
- svcnum = $svcnum)";
- my $c = $did_order->scalar_sql($sql);
- $count++ if $c > 0;
- }
+ my $sql = "select count(1) from cdr where src in
+ (select phonenum from svc_phone where svcnum in (
+ select svcnum from phone_avail where latanum = $latanum
+ and svcnum is not null) )
+ or charged_party in (select phonenum from svc_phone where
+ svcnum in (select svcnum from phone_avail where
+ latanum = $latanum and svcnum is not null) )";
+ my $c = $phone_avail->scalar_sql($sql);
+ $count++ if $c > 0;