1 package FS::part_event::Condition::svc_acct_threshold;
6 use base qw( FS::part_event::Condition );
8 sub description { 'Service is over its usage warning threshold' };
10 sub eventtable_hashref {
14 tie my %usage_types, 'Tie::IxHash', (
16 'upbytes' => 'Upload',
17 'downbytes' => 'Download',
18 'totalbytes'=> 'Total transfer',
24 type => 'checkbox-multiple',
25 options => [ keys %usage_types ],
26 option_labels => \%usage_types,
32 my($self, $svc_acct) = @_;
34 my $types = $self->option('usage_types') || {};
35 foreach my $column (keys %$types) {
36 # don't trigger if this type of usage isn't tracked on the service
37 next if $svc_acct->$column eq '';
39 my $method = $column.'_threshold';
40 $threshold = $svc_acct->$method;
41 # don't trigger if seconds = 0 and seconds_threshold is null
42 next if $threshold eq '';
44 return 1 if ( $svc_acct->$column <= $threshold );
52 # not an exact condition_sql--ignores the usage_types option
55 my $threshold = $_.'_threshold';
56 "( svc_acct.$_ IS NOT NULL AND svc_acct.$threshold IS NOT NULL AND ".
57 "svc_acct.$_ <= svc_acct.$threshold )"