From 1e64160a779e96d84c5db648622dee4f88f34215 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Fri, 17 Jul 2015 03:50:54 -0500 Subject: [PATCH] RT#37165: Print document when account is created --- FS/FS/Conf.pm | 10 ++++++++-- FS/FS/svc_acct.pm | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 1d4a85a57..90b5d2985 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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, }, diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 0181b1e0e..a76d93dab 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -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 -- 2.11.0