summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-07-17 23:40:53 -0500
committerJonathan Prykop <jonathan@freeside.biz>2015-07-22 17:50:38 -0500
commitf477acee6da9e2ccf24fe34ade2c39051fe20477 (patch)
tree5c8b4e26173d3a0edb498975914426ffe8c1d237 /FS/FS
parenta55fafd36b1dfa8a90e7177298a0dca8534115e2 (diff)
RT#37165: Print document when account is created [implemented as export]
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/Conf.pm10
-rw-r--r--FS/FS/cust_main.pm11
-rw-r--r--FS/FS/part_export/print_template.pm198
-rw-r--r--FS/FS/svc_acct.pm41
4 files changed, 211 insertions, 49 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index bab8953..4e1736b 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2522,17 +2522,11 @@ 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 or letter is to be sent.',
+ 'description' => 'A list of svc_acct services for which no welcome email is to be sent.',
'type' => 'select-part_svc',
'multiple' => 1,
},
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index f55c349..f0c4f5c 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -4681,6 +4681,8 @@ I<extra_fields> - a hashref of name/value pairs which will be substituted
into the template. These values may override values mentioned below
and those from the customer record.
+I<template_text> - if present, ignores TEMPLATE_NAME and uses the provided text
+
The following variables are available in the template instead of or in addition
to the fields of the customer record.
@@ -4696,11 +4698,16 @@ I<$returnaddress> - the return address defaults to invoice_latexreturnaddress or
sub generate_letter {
my ($self, $template, %options) = @_;
- return unless $conf->exists($template);
+ warn "Template $template does not exist" && return
+ unless $conf->exists($template) || $options{'template_text'};
+
+ my $template_source = $options{'template_text'}
+ ? [ $options{'template_text'} ]
+ : [ map "$_\n", $conf->config($template) ];
my $letter_template = new Text::Template
( TYPE => 'ARRAY',
- SOURCE => [ map "$_\n", $conf->config($template)],
+ SOURCE => $template_source,
DELIMITERS => [ '[@--', '--@]' ],
)
or die "can't create new Text::Template object: Text::Template::ERROR";
diff --git a/FS/FS/part_export/print_template.pm b/FS/FS/part_export/print_template.pm
new file mode 100644
index 0000000..21f0a15
--- /dev/null
+++ b/FS/FS/part_export/print_template.pm
@@ -0,0 +1,198 @@
+package FS::part_export::print_template;
+
+use strict;
+
+use base qw( FS::part_export );
+
+use FS::Record qw(qsearchs);
+use FS::Misc;
+use FS::queue;
+
+=pod
+
+=head1 NAME
+
+FS::part_export::print_template
+
+=head1 SYNOPSIS
+
+Print a document of a template.
+
+=head1 DESCRIPTION
+
+See the L<Text::Template> documentation and the billing documentation for details on the template substitution language.
+
+Currently does not support printing during replace.
+
+=cut
+
+use vars qw( %info );
+
+tie my %options, 'Tie::IxHash',
+ 'phase' => { label => 'Print during',
+ type => 'select',
+ options => [qw(insert delete suspend unsuspend)] },
+ 'template_text' => { label => 'Template text',
+ type => 'textarea' },
+;
+
+%info = (
+ #unfortunately, FS::part_svc->svc_tables fails at this point, not sure why
+ 'svc' => [ map { 'svc_'.$_ } qw(
+ acct domain cert forward mailinglist www broadband cable dsl
+ conferencing video dish hardware phone pbx circuit port alarm external)
+ ],
+ 'desc' => 'Print document during service change, for all services',
+ 'options' => \%options,
+ 'no_machine' => 1,
+ 'notes' => <<'EOF',
+Will use the print command configured by the lpr setting.
+See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation and the billing documentation for details on the template substitution language.
+Fields from the customer and service records are available for substitution, as well as the following fields:
+
+<ul>
+<li>$payby - a friendler represenation of the field</li>
+<li>$payinfo - the masked payment information</li>
+<li>$expdate - the time at which the payment method expires (a UNIX timestamp)</li>
+<li>$returnaddress - the invoice return address for this customer's agent</li>
+<li>$logo_file - the image stored in the logo.eps setting
+</ul>
+EOF
+);
+
+=head1 Hook Methods
+
+Each of these simply invoke this module's L<print_template> method,
+passing the appropriate phase.
+
+=cut
+
+=head2 _export_insert
+
+Hook that is called when service is initially provisioned.
+To avoid confusion, don't use for anything else.
+
+=cut
+
+sub _export_insert {
+ my $self = shift;
+ return $self->print_template('insert',@_);
+}
+
+=head2 _export_delete
+
+Hook that is called when service is unprovisioned.
+To avoid confusion, don't use for anything else.
+
+=cut
+
+sub _export_delete {
+ my $self = shift;
+ return $self->print_template('delete',@_);
+}
+
+=head2 _export_replace
+
+Hook that is called when provisioned service is edited.
+To avoid confusion, don't use for anything else.
+
+Currently not supported for this export.
+
+=cut
+
+sub _export_replace {
+ return '';
+}
+
+=head2 _export_suspend
+
+Hook that is called when service is suspended.
+To avoid confusion, don't use for anything else.
+
+=cut
+
+sub _export_suspend {
+ my $self = shift;
+ return $self->print_template('suspend',@_);
+}
+
+=head2 _export_unsuspend
+
+Hook that is called when service is unsuspended.
+To avoid confusion, don't use for anything else.
+
+=cut
+
+sub _export_unsuspend {
+ my $self = shift;
+ return $self->print_template('unsuspend',@_);
+}
+
+=head1 Core Methods
+
+=head2 print_template
+
+Accepts $phase and $svc_x.
+If phase matches the configured option, starts a L</process_print_template>
+job in the queue.
+
+=cut
+
+sub print_template {
+ my ($self, $phase, $svc_x) = @_;
+ if ($self->option('phase') eq $phase) {
+ my $queue = new FS::queue {
+ 'job' => 'FS::part_export::print_template::process_print_template',
+ };
+ my $error = $queue->insert(
+ 'svcnum' => $svc_x->svcnum,
+ 'table' => $svc_x->table,
+ 'template_text' => $self->option('template_text'),
+ );
+ return "can't start print job: $error" if $error;
+ }
+ return '';
+}
+
+=head2 process_print_template
+
+For use as an FS::queue job. Requires opts svcnum, table and template_text.
+Constructs page from template and sends to printer.
+
+=cut
+
+sub process_print_template {
+ my %opt = @_;
+
+ my $svc_x = qsearchs($opt{'table'}, { 'svcnum' => $opt{'svcnum'} } )
+ or die "invalid " . $opt{'table'} . " svcnum " . $opt{'svcnum'};
+ my $cust_main = $svc_x->cust_svc->cust_pkg->cust_main
+ or die "could not find customer for service";
+
+ my $ps = $cust_main->print_ps(undef,
+ 'template_text' => $opt{'template_text'},
+ 'extra_fields' => {
+ map { $_ => $svc_x->$_ } $svc_x->fields,
+ },
+ );
+ my $error = FS::Misc::do_print(
+ [ $ps ],
+ 'agentnum' => $cust_main->agentnum,
+ );
+ die $error if $error;
+}
+
+=head1 SEE ALSO
+
+L<FS::part_export>
+
+=head1 AUTHOR
+
+Jonathan Prykop
+jonathan@freeside.biz
+
+=cut
+
+1;
+
+
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index a76d93d..0181b1e 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -57,7 +57,6 @@ use FS::svc_forward;
use FS::svc_www;
use FS::cdr;
use FS::tower_sector;
-use FS::Misc;
$DEBUG = 0;
$me = '[FS::svc_acct]';
@@ -729,11 +728,9 @@ sub insert {
$cust_main->invoicing_list(\@invoicing_list);
}
- #welcome email/letter
+ #welcome email
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 ) {
@@ -817,21 +814,7 @@ 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;
@@ -3036,26 +3019,6 @@ 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