From: ivan Date: Sat, 11 Oct 2008 00:32:17 +0000 (+0000) Subject: enable suspension notices to an administrator, RT#4083 X-Git-Tag: root_of_webpay_support~323 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=5d6b394a5c676e5b87819a205da545f17fde8616 enable suspension notices to an administrator, RT#4083 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 46e636b68..61b41685a 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2460,6 +2460,13 @@ worry that config_items is freeside-specific and icky. 'type' => 'text', }, + { + 'key' => 'suspend_email_admin', + 'section' => '', + 'description' => 'Destination admin email address to enable suspension notices', + 'type' => 'text', + }, + ); 1; diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index b3359ca64..6d2c6018b 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -758,6 +758,9 @@ sub suspend { } unless ( $date ) { + + my @labels = (); + foreach my $cust_svc ( qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } ) ) { @@ -777,12 +780,43 @@ sub suspend { $dbh->rollback if $oldAutoCommit; return $error; } + my( $label, $value ) = $cust_svc->label; + push @labels, "$label: $value"; } } + + my $conf = new FS::Conf; + if ( $conf->config('suspend_email_admin') ) { + + my $error = send_email( + 'from' => $conf->config('invoice_from'), #??? well as good as any + 'to' => $conf->config('suspend_email_admin'), + 'subject' => 'FREESIDE NOTIFICATION: Customer package suspended', + 'body' => [ + "This is an automatic message from your Freeside installation\n", + "informing you that the following customer package has been suspended:\n", + "\n", + 'Customer: #'. $self->custnum. ' '. $self->cust_main->name. "\n", + 'Package : #'. $self->pkgnum. " (". $self->part_pkg->pkg_comment. ")\n", + ( map { "Service : $_\n" } @labels ), + ], + ); + + if ( $error ) { + warn "WARNING: can't send suspension admin email (suspending anyway): ". + "$error\n"; + } + + } + } my %hash = $self->hash; - $date ? ($hash{'adjourn'} = $date) : ($hash{'susp'} = time); + if ( $date ) { + $hash{'adjourn'} = $date; + } else { + $hash{'susp'} = time; + } my $new = new FS::cust_pkg ( \%hash ); $error = $new->replace( $self, options => { $self->options } ); if ( $error ) {