From 53ea5a72067a9b0ebcd3417692c3884d6f91f74a Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 1 Sep 2011 05:13:09 +0000 Subject: svc_acct events for usage limits, #13202 --- FS/FS/msg_template.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'FS/FS/msg_template.pm') diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index c183477fb..d980ab9e2 100644 --- a/FS/FS/msg_template.pm +++ b/FS/FS/msg_template.pm @@ -430,6 +430,20 @@ sub send { # helper sub for package dates my $ymd = sub { $_[0] ? time2str('%Y-%m-%d', $_[0]) : '' }; +# helper sub for usage-related messages +my $usage_warning = sub { + my $svc = shift; + foreach my $col (qw(seconds upbytes downbytes totalbytes)) { + my $amount = $svc->$col; next if $amount eq ''; + my $method = $col.'_threshold'; + my $threshold = $svc->$method; next if $threshold eq ''; + return [$col, $amount, $threshold] if $amount <= $threshold; + # this only returns the first one that's below threshold, if there are + # several. + } + return ['', '', '']; +}; + #my $conf = new FS::Conf; #return contexts and fill-in values @@ -514,6 +528,9 @@ sub substitutions { domain ), [ password => sub { shift->getfield('_password') } ], + [ column => sub { &$usage_warning(shift)->[0] } ], + [ amount => sub { &$usage_warning(shift)->[1] } ], + [ threshold => sub { &$usage_warning(shift)->[2] } ], ], 'svc_domain' => [qw( svcnum -- cgit v1.2.1