RT#37165: Print document when account is created
authorJonathan Prykop <jonathan@freeside.biz>
Fri, 17 Jul 2015 08:50:54 +0000 (03:50 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Fri, 17 Jul 2015 08:50:54 +0000 (03:50 -0500)
FS/FS/Conf.pm
FS/FS/svc_acct.pm

index 1d4a85a..90b5d29 100644 (file)
@@ -2564,11 +2564,17 @@ 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_letter',
+    'section'     => 'notification',
+    'description' => 'Optional LaTex template for a printed welcome letter when a svc_acct record is created.  Fields from the customer and svc_acct records are available for substitution.',
+    'type'        => 'textarea',
+  },
+
   {
     'key'         => 'svc_acct_welcome_exclude',
     'section'     => 'notification',
-    'description' => 'A list of svc_acct services for which no welcome email is to be sent.',
+    'description' => 'A list of svc_acct services for which no welcome email or letter is to be sent.',
     'type'        => 'select-part_svc',
     'multiple'    => 1,
   },
index 0181b1e..a76d93d 100644 (file)
@@ -57,6 +57,7 @@ use FS::svc_forward;
 use FS::svc_www;
 use FS::cdr;
 use FS::tower_sector;
+use FS::Misc;
 
 $DEBUG = 0;
 $me = '[FS::svc_acct]';
@@ -728,9 +729,11 @@ sub insert {
       $cust_main->invoicing_list(\@invoicing_list);
     }
 
-    #welcome email
+    #welcome email/letter
     my @welcome_exclude_svcparts = $conf->config('svc_acct_welcome_exclude');
     unless ( grep { $_ eq $self->svcpart } @welcome_exclude_svcparts ) {
+      #indent skips a level for some reason
+        #welcome email
         my $error = '';
         my $msgnum = $conf->config('welcome_msgnum', $agentnum);
         if ( $msgnum ) {
@@ -814,7 +817,21 @@ sub insert {
 
           } # if $welcome_template
         } # if !$msgnum
-    }
+        # print welcome letter
+        if ($conf->exists('svc_acct_welcome_letter')) {
+          my $queue = new FS::queue {
+            'job'     => 'FS::svc_acct::process_print_welcome_letter',
+          };
+          $error = $queue->insert(
+            'svcnum'  => $self->svcnum,
+            'template' => 'svc_acct_welcome_letter',
+          );
+          if ($error) {
+            warn "can't send welcome letter: $error";
+          }
+        }
+      #indent skipped a level for some reason
+    } # unless in @welcome_exclude_svcparts
   } # if $cust_pkg
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -3019,6 +3036,26 @@ sub reached_threshold {
   }
 }
 
+sub process_print_welcome_letter {
+  my %opt = @_;
+
+  my $self = qsearchs('svc_acct', { 'svcnum' => $opt{'svcnum'} } )
+    or die "invalid svc_acct: " . $opt{'svcnum'};
+  my $cust_main = $self->cust_svc->cust_pkg->cust_main;
+
+  my $ps = $cust_main->print_ps('svc_acct_welcome_letter',
+    'extra_fields' => {
+      map { $_ => $self->$_ } $self->fields, # or maybe just username & password?
+    },
+  );
+  my $error = FS::Misc::do_print(
+    [ $ps ],
+    'agentnum' => $cust_main->agentnum,
+  );
+  die $error if $error;
+
+}
+
 =back
 
 =head1 BUGS