add option to exclude configurable svc_acct svcparts from welcome emails, RT11021
authorlevinse <levinse>
Fri, 8 Apr 2011 04:58:58 +0000 (04:58 +0000)
committerlevinse <levinse>
Fri, 8 Apr 2011 04:58:58 +0000 (04:58 +0000)
FS/FS/Conf.pm
FS/FS/svc_acct.pm

index 7c7c6ed..6ea5a51 100644 (file)
@@ -2055,6 +2055,14 @@ and customer address. Include units.',
     'description' => 'Template to use for welcome messages when a svc_acct record is created.',
     %msg_template_options,
   },
+  
+  {
+    'key'         => 'svc_acct_welcome_exclude',
+    'section'     => 'notification',
+    'description' => 'A list of svc_acct services for which no welcome email is to be sent.',
+    'type'        => 'select-part_svc',
+    'multiple'    => 1,
+  },
 
   {
     'key'         => 'welcome_email',
index 0525b97..c3e7209 100644 (file)
@@ -746,89 +746,92 @@ sub insert {
     }
 
     #welcome email
-    my $error = '';
-    my $msgnum = $conf->config('welcome_msgnum', $agentnum);
-    if ( $msgnum ) {
-      my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
-      $error = $msg_template->send('cust_main' => $cust_main,
-                                   'object'    => $self);
-    }
-    else { #!$msgnum
-      my ($to,$welcome_template,$welcome_from,$welcome_subject,$welcome_subject_template,$welcome_mimetype)
-        = ('','','','','','');
-
-      if ( $conf->exists('welcome_email', $agentnum) ) {
-        $welcome_template = new Text::Template (
-          TYPE   => 'ARRAY',
-          SOURCE => [ map "$_\n", $conf->config('welcome_email', $agentnum) ]
-        ) or warn "can't create welcome email template: $Text::Template::ERROR";
-        $welcome_from = $conf->config('welcome_email-from', $agentnum);
-          # || 'your-isp-is-dum'
-        $welcome_subject = $conf->config('welcome_email-subject', $agentnum)
-          || 'Welcome';
-        $welcome_subject_template = new Text::Template (
-          TYPE   => 'STRING',
-          SOURCE => $welcome_subject,
-        ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
-        $welcome_mimetype = $conf->config('welcome_email-mimetype', $agentnum)
-          || 'text/plain';
-      }
-      if ( $welcome_template ) {
-        my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
-        if ( $to ) {
-
-          my %hash = (
-                       'custnum'  => $self->custnum,
-                       'username' => $self->username,
-                       'password' => $self->_password,
-                       'first'    => $cust_main->first,
-                       'last'     => $cust_main->getfield('last'),
-                       'pkg'      => $cust_pkg->part_pkg->pkg,
-                     );
-          my $wqueue = new FS::queue {
-            'svcnum' => $self->svcnum,
-            'job'    => 'FS::svc_acct::send_email'
-          };
-          my $error = $wqueue->insert(
-            'to'       => $to,
-            'from'     => $welcome_from,
-            'subject'  => $welcome_subject_template->fill_in( HASH => \%hash, ),
-            'mimetype' => $welcome_mimetype,
-            'body'     => $welcome_template->fill_in( HASH => \%hash, ),
-          );
-          if ( $error ) {
-            $dbh->rollback if $oldAutoCommit;
-            return "error queuing welcome email: $error";
-          }
-
-          if ( $options{'depend_jobnum'} ) {
-            warn "$me depend_jobnum found; adding to welcome email dependancies"
-              if $DEBUG;
-            if ( ref($options{'depend_jobnum'}) ) {
-              warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ).
-                   "to welcome email dependancies"
-                if $DEBUG;
-              push @jobnums, @{ $options{'depend_jobnum'} };
-            } else {
-              warn "$me adding job $options{'depend_jobnum'} ".
-                   "to welcome email dependancies"
-                if $DEBUG;
-              push @jobnums, $options{'depend_jobnum'};
-            }
+    my @welcome_exclude_svcparts = $conf->config('svc_acct_welcome_exclude');
+    unless ( grep { $_ eq $self->svcpart } @welcome_exclude_svcparts ) {
+        my $error = '';
+        my $msgnum = $conf->config('welcome_msgnum', $agentnum);
+        if ( $msgnum ) {
+          my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
+          $error = $msg_template->send('cust_main' => $cust_main,
+                                       'object'    => $self);
+        }
+        else { #!$msgnum
+          my ($to,$welcome_template,$welcome_from,$welcome_subject,$welcome_subject_template,$welcome_mimetype)
+            = ('','','','','','');
+
+          if ( $conf->exists('welcome_email', $agentnum) ) {
+            $welcome_template = new Text::Template (
+              TYPE   => 'ARRAY',
+              SOURCE => [ map "$_\n", $conf->config('welcome_email', $agentnum) ]
+            ) or warn "can't create welcome email template: $Text::Template::ERROR";
+            $welcome_from = $conf->config('welcome_email-from', $agentnum);
+              # || 'your-isp-is-dum'
+            $welcome_subject = $conf->config('welcome_email-subject', $agentnum)
+              || 'Welcome';
+            $welcome_subject_template = new Text::Template (
+              TYPE   => 'STRING',
+              SOURCE => $welcome_subject,
+            ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
+            $welcome_mimetype = $conf->config('welcome_email-mimetype', $agentnum)
+              || 'text/plain';
           }
+          if ( $welcome_template ) {
+            my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
+            if ( $to ) {
+
+              my %hash = (
+                           'custnum'  => $self->custnum,
+                           'username' => $self->username,
+                           'password' => $self->_password,
+                           'first'    => $cust_main->first,
+                           'last'     => $cust_main->getfield('last'),
+                           'pkg'      => $cust_pkg->part_pkg->pkg,
+                         );
+              my $wqueue = new FS::queue {
+                'svcnum' => $self->svcnum,
+                'job'    => 'FS::svc_acct::send_email'
+              };
+              my $error = $wqueue->insert(
+                'to'       => $to,
+                'from'     => $welcome_from,
+                'subject'  => $welcome_subject_template->fill_in( HASH => \%hash, ),
+                'mimetype' => $welcome_mimetype,
+                'body'     => $welcome_template->fill_in( HASH => \%hash, ),
+              );
+              if ( $error ) {
+                $dbh->rollback if $oldAutoCommit;
+                return "error queuing welcome email: $error";
+              }
+
+              if ( $options{'depend_jobnum'} ) {
+                warn "$me depend_jobnum found; adding to welcome email dependancies"
+                  if $DEBUG;
+                if ( ref($options{'depend_jobnum'}) ) {
+                  warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ).
+                       "to welcome email dependancies"
+                    if $DEBUG;
+                  push @jobnums, @{ $options{'depend_jobnum'} };
+                } else {
+                  warn "$me adding job $options{'depend_jobnum'} ".
+                       "to welcome email dependancies"
+                    if $DEBUG;
+                  push @jobnums, $options{'depend_jobnum'};
+                }
+              }
+
+              foreach my $jobnum ( @jobnums ) {
+                my $error = $wqueue->depend_insert($jobnum);
+                if ( $error ) {
+                  $dbh->rollback if $oldAutoCommit;
+                  return "error queuing welcome email job dependancy: $error";
+                }
+              }
 
-          foreach my $jobnum ( @jobnums ) {
-            my $error = $wqueue->depend_insert($jobnum);
-            if ( $error ) {
-              $dbh->rollback if $oldAutoCommit;
-              return "error queuing welcome email job dependancy: $error";
             }
-          }
 
-        }
-
-      } # if $welcome_template
-    } # if !$msgnum
+          } # if $welcome_template
+        } # if !$msgnum
+    }
   } # if $cust_pkg
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;