X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-cdrrated;h=1333240ec9938962fbbc8726b07e417e2abda804;hb=e9e0cf0989259b94d9758eceff448666a2e5a5cc;hp=131b56a7e1996602e1518339a8076510dcdf9199;hpb=fb4ab1073f0d15d660c6cdc4e07afebf68ef3924;p=freeside.git diff --git a/FS/bin/freeside-cdrrated b/FS/bin/freeside-cdrrated index 131b56a7e..1333240ec 100644 --- a/FS/bin/freeside-cdrrated +++ b/FS/bin/freeside-cdrrated @@ -33,9 +33,11 @@ if ( @cdrtypenums ) { $extra_sql .= ' AND cdrtypenum IN ('. join(',', @cdrtypenums ). ')'; } -our %svcnum = (); -our %pkgpart = (); -our %part_pkg = (); +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 #some false laziness w/freeside-cdrrewrited @@ -91,6 +93,9 @@ while (1) { next; } + $pkgnum{$number} = $cust_pkg->pkgnum; + $cust_pkg{$cust_pkg->pkgnum} ||= $cust_pkg; + #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' @@ -122,19 +127,37 @@ 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} }, - 'svcnum' => $svcnum{ $number }, + 'cust_pkg' => $cust_pkg{ $pkgnum{$number} }, + 'svcnum' => $svcnum{$number}, ); if ( $error ) { #XXX ??? warn $error; 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();