+#returns a reason why not to rate this CDR, or false if the CDR is chargeable
+sub check_chargable {
+ my( $self, $cdr, %flags ) = @_;
+
+ #should have some better way of checking these options from a hash
+ #or something
+
+ my @opt = qw(
+ use_amaflags
+ use_disposition
+ use_disposition_taqua
+ use_carrierid
+ use_cdrtypenum
+ skip_dcontext
+ skip_dstchannel_prefix
+ skip_dst_length_less
+ skip_lastapp
+ );
+ foreach my $opt (grep !exists($flags{option_cache}->{$_}), @opt ) {
+ $flags{option_cache}->{$opt} = $self->option($opt, 1);
+ }
+ my %opt = %{ $flags{option_cache} };
+
+ return 'amaflags != 2'
+ if $opt{'use_amaflags'} && $cdr->amaflags != 2;
+
+ return 'disposition != ANSWERED'
+ if $opt{'use_disposition'} && $cdr->disposition ne 'ANSWERED';
+
+ return "disposition != 100"
+ if $opt{'use_disposition_taqua'} && $cdr->disposition != 100;
+
+ return "carrierid != $opt{'use_carrierid'}"
+ if length($opt{'use_carrierid'})
+ && $cdr->carrierid ne $opt{'use_carrierid'} #ne otherwise 0 matches ''
+ && ! $flags{'da_rewrote'};
+
+ return "cdrtypenum != $opt{'use_cdrtypenum'}"
+ if length($opt{'use_cdrtypenum'})
+ && $cdr->cdrtypenum ne $opt{'use_cdrtypenum'}; #ne otherwise 0 matches ''
+
+ return "dcontext IN ( $opt{'skip_dcontext'} )"
+ if $opt{'skip_dcontext'} =~ /\S/
+ && grep { $cdr->dcontext eq $_ } split(/\s*,\s*/, $opt{'skip_dcontext'});
+
+ my $len_prefix = length($opt{'skip_dstchannel_prefix'});
+ return "dstchannel starts with $opt{'skip_dstchannel_prefix'}"
+ if $len_prefix
+ && substr($cdr->dstchannel,0,$len_prefix) eq $opt{'skip_dstchannel_prefix'};
+
+ my $dst_length = $opt{'skip_dst_length_less'};
+ return "destination less than $dst_length digits"
+ if $dst_length && length($cdr->dst) < $dst_length;
+
+ return "lastapp is $opt{'skip_lastapp'}"
+ if length($opt{'skip_lastapp'}) && $cdr->lastapp eq $opt{'skip_lastapp'};
+
+ #all right then, rate it
+ '';