X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-cdrrated;h=a8fcf5157f734e81ba18c401b304f4c7bf499cc6;hb=baca421d2fa815a6338e9525e3e404928b59235e;hp=1333240ec9938962fbbc8726b07e417e2abda804;hpb=296b198525e573770dd2a1c686493f522c69f51f;p=freeside.git diff --git a/FS/bin/freeside-cdrrated b/FS/bin/freeside-cdrrated index 1333240ec..a8fcf5157 100644 --- a/FS/bin/freeside-cdrrated +++ b/FS/bin/freeside-cdrrated @@ -33,11 +33,12 @@ if ( @cdrtypenums ) { $extra_sql .= ' AND cdrtypenum IN ('. join(',', @cdrtypenums ). ')'; } -our %svcnum = (); # phonenum => svcnum -our %pkgnum = (); # phonenum => pkgnum -our %cust_pkg = (); # pkgnum => cust_pkg (NOT phonenum => cust_pkg!) -our %pkgpart = (); # phonenum => pkgpart -our %part_pkg = (); # pkgpart => part_pkg +#our %svcnum = (); # phonenum => svcnum +our %svc_phone = (); # phonenum => svc_phone +our %pkgnum = (); # phonenum => pkgnum +our %cust_pkg = (); # pkgnum => cust_pkg (NOT phonenum => cust_pkg!) +our %pkgpart = (); # phonenum => pkgpart +our %part_pkg = (); # pkgpart => part_pkg #some false laziness w/freeside-cdrrewrited @@ -76,26 +77,36 @@ while (1) { if $prefix eq substr($number, 0, length($prefix)); } - unless ( $svcnum{$number} ) { + unless ( $svc_phone{$number} ) { #only phone number matching supported right now my $svc_phone = qsearchs('svc_phone', { 'phonenum' => $number } ); unless ( $svc_phone ) { #XXX set freesideratestatus or something so we don't keep retrying? + warn "no phone number found for CDR ". $cdr->acctid. "\n"; next; } - $svcnum{$number} = $svc_phone->svcnum; + $svc_phone{$number} = $svc_phone; - my $cust_pkg = $svc_phone->cust_svc->cust_pkg; + } + + unless ( $pkgnum{$number} ) { + + my $cust_pkg = $svc_phone{$number}->cust_svc->cust_pkg; unless ( $cust_pkg ) { #XXX unlinked svc_phone? - # warn and also set freesideratestatus or somesuch? + # also set freesideratestatus or somesuch? + warn "no package found (unlinked phone number?) for CDR ". $cdr->acctid. "\n"; next; } $pkgnum{$number} = $cust_pkg->pkgnum; $cust_pkg{$cust_pkg->pkgnum} ||= $cust_pkg; + } + + unless ( $pkgpart{$number} ) { + #get the package, search through the part_pkg and linked for a voip_cdr def w/matching cdrtypenum (or no use_cdrtypenum) my @part_pkg = grep { $_->plan eq 'voip_cdr' @@ -109,12 +120,13 @@ while (1) { ) } - $cust_pkg->part_pkg->self_and_bill_linked; + $cust_pkg{ $pkgnum{$number} }->part_pkg->self_and_bill_linked; if ( ! @part_pkg ) { #XXX no package for this CDR # warn and also set freesideratestatus or somesuch? # or at least warn + warn "no CDR rating package for CDR ". $cdr->acctid. "\n"; next; } elsif ( scalar(@part_pkg) > 1 ) { warn "multiple package could rate CDR ". $cdr->acctid. "\n"; @@ -131,18 +143,18 @@ while (1) { #then we can't prerate this CDR #some sort of warning? # (sucks if you're depending on credit limit fraud warnings) + warn "package has min_included; can't prerate CDR ". $cdr->acctid. "\n"; next; } my $error = $cdr->rate( 'part_pkg' => $part_pkg{ $pkgpart{$number} }, 'cust_pkg' => $cust_pkg{ $pkgnum{$number} }, - 'svcnum' => $svcnum{$number}, + 'svcnum' => $svc_phone{$number}->svcnum, ); if ( $error ) { - #XXX ??? - warn $error; - sleep 30; + warn "Can't prerate CDR ". $cdr->acctid. ' to '. $cdr->dst. ": $error"; + #could be an included minutes CDR, so don't sleep 30; } else { #this could get expensive on a per-call basis @@ -176,7 +188,7 @@ sub _shouldrun { } sub usage { - die "Usage:\n\n freeside-cdrrewrited user\n"; + die "Usage:\n\n freeside-cdrrated user\n"; } =head1 NAME