email referring customers on cancellation, RT#75756
authorIvan Kohler <ivan@freeside.biz>
Thu, 27 Apr 2017 23:46:20 +0000 (16:46 -0700)
committerIvan Kohler <ivan@freeside.biz>
Thu, 27 Apr 2017 23:46:20 +0000 (16:46 -0700)
FS/FS/Conf.pm
FS/FS/cust_pkg.pm

index de4d1b8..07042e5 100644 (file)
@@ -2606,6 +2606,21 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'cancel_msgnum-referring_cust-pkg_class',
+    'section'     => 'notification',
+    'description' => 'Enable cancellation messages to the referring customer for these package classes.',
+    'type'        => 'select-pkg_class',
+    'multiple'    => 1,
+  },
+
+  {
+    'key'         => 'cancel_msgnum-referring_cust',
+    'section'     => 'notification',
+    'description' => 'Template to use for cancellation emails sent to the referring customer.',
+    %msg_template_options,
+  },
+
+  {
     'key'         => 'require_cardname',
     'section'     => 'billing',
     'description' => 'Require an "Exact name on card" to be entered explicitly; don\'t default to using the first and last name.',
index 98390c7..ef25c24 100644 (file)
@@ -1048,18 +1048,22 @@ sub cancel {
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   return '' if $date; #no errors
 
-  my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $self->cust_main->invoicing_list;
-  if ( !$options{'quiet'} && 
-        $conf->exists('emailcancel', $self->cust_main->agentnum) && 
-        @invoicing_list ) {
-    my $msgnum = $conf->config('cancel_msgnum', $self->cust_main->agentnum);
-    my $error = '';
+  my $cust_main = $self->cust_main;
+
+  my @invoicing_list = $cust_main->invoicing_list_emailonly;
+  if (    !$options{'quiet'}
+       && $conf->config_bool('emailcancel', $cust_main->agentnum)
+       && @invoicing_list
+     )
+  {
+    my $msgnum = $conf->config('cancel_msgnum', $cust_main->agentnum);
     if ( $msgnum ) {
       my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
-      $error = $msg_template->send( 'cust_main' => $self->cust_main,
-                                    'object'    => $self );
-    }
-    else {
+      my $error = $msg_template->send(
+        'cust_main' => $cust_main,
+        'object'    => $self,
+      );
+    } else {
       $error = send_email(
         'from'    => $conf->invoice_from_full( $self->cust_main->agentnum ),
         'to'      => \@invoicing_list,
@@ -1072,6 +1076,23 @@ sub cancel {
     #should this do something on errors?
   }
 
+  my %pkg_class = map { $_=>1 }
+                    $conf->config('cancel_msgnum-referring_cust-pkg_class');
+  my $ref_msgnum = $conf->config('cancel_msgnum-referring_cust');
+  if (    !$options{'quiet'}
+       && $cust_main->referral_custnum
+       && $pkg_class{ $self->classnum } 
+       && $ref_msgnum
+     )
+  {
+    my $msg_template = qsearchs('msg_template', { msgnum => $ref_msgnum });
+    my $error = $msg_template->send( 
+      'cust_main' => $cust_main->referring_cust_main,
+      'object'    => $self,
+    );
+     #should this do something on errors?
+   }
+
   ''; #no errors
 
 }