X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-cdrrated;h=2966b2e4e64b4894053559f5f9a59a054258c882;hp=99ea675947e8bbfae2fcfa628c76f4fb7138e94f;hb=a36e0f8a0f69349dafaa16d1d2d57dfb6e5dbc85;hpb=f3e0ac2b009c4edd5692cb587ff709dac2223ebe diff --git a/FS/bin/freeside-cdrrated b/FS/bin/freeside-cdrrated index 99ea67594..2966b2e4e 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 = (); # phonenum => 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,7 +77,7 @@ 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 ) { @@ -84,9 +85,13 @@ while (1) { 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? @@ -96,6 +101,10 @@ while (1) { $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,7 +118,7 @@ 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 @@ -127,20 +136,36 @@ while (1) { } - #unless ( $part_pkg{$pkgpart{$number}} ) { - #} - - #XXX if $part_pkg->option('min_included') then we can't prerate this CDR + if ( $part_pkg{ $pkgpart{$number} }->option('min_included') ) { + #then we can't prerate this CDR + #some sort of warning? + # (sucks if you're depending on credit limit fraud warnings) + 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 + # trigger in a separate process with less frequency? + + my $cust_main = $cust_pkg{ $pkgnum{$number} }->cust_main; + + my $error = $cust_main->check_credit_limit; + if ( $error ) { + #"should never happen" normally, but as a daemon, better to survive + # e.g. database going away and coming back and resume doing our thing + warn $error; + sleep 30; + } + } last if sigterm() || sigint();