+ if ( $conf->exists('cdr-taqua-accountcode_rewrite')
+ && $cdr->lastapp eq 'acctcode' && $cdr->cdrtypenum == 1
+ )
+ {
+
+ #find the matching CDR
+ my $primary = qsearchs('cdr', {
+ 'sessionnum' => $cdr->sessionnum,
+ 'src' => $cdr->subscriber,
+ #'accountcode' => '',
+ });
+
+ unless ( $primary ) {
+
+ my $cantfind = "can't find primary CDR with session ". $cdr->sessionnum.
+ ", src ". $cdr->subscriber;
+ if ( $cdr->calldate_unix + $accountcode_giveup < time ) {
+ warn "ERROR: $cantfind; giving up\n";
+ push @status, 'taqua-accountcode-NOTFOUND';
+ $cdr->status('done'); #so it doesn't try to rate
+ delete $accountcode_unmatch{$cdr->acctid}; #so it doesn't suck mem
+ } else {
+ warn "WARNING: $cantfind; will keep trying\n";
+ $accountcode_unmatch{$cdr->acctid} = time;
+ next;
+ }
+
+ } else {
+
+ $primary->accountcode( $cdr->lastdata );
+ #$primary->freesiderewritestatus( 'taqua-accountcode-primary' );
+ my $error = $primary->replace;
+ if ( $error ) {
+ warn "WARNING: error rewriting primary CDR (will retry): $error\n";
+ next;
+ }
+ $skip{$primary->acctid} = 1;
+
+ push @status, 'taqua-accountcode';
+ $cdr->status('done'); #so it doesn't try to rate
+
+ }
+
+ }
+