[freeside-commits] branch master updated. 0b9712428c18bd68f39c66a18e489c0e0ebc79af

Jonathan Prykop jonathan at 420.am
Fri Jul 17 21:43:09 PDT 2015


The branch, master has been updated
       via  0b9712428c18bd68f39c66a18e489c0e0ebc79af (commit)
       via  bc68d45408c963fbf7c024c15198373dc6b1de8f (commit)
      from  de4008c1c673fbb50e8b2806126fe9e7bb8ec0ee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0b9712428c18bd68f39c66a18e489c0e0ebc79af
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Fri Jul 17 23:41:51 2015 -0500

    RT#37165: Print document when account is created [fix for welcome_letter, no backport to 3]

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index f0c4f5c..c636408 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -4822,7 +4822,9 @@ sub queueable_print {
   my $self = qsearchs('cust_main', { 'custnum' => $opt{custnum} } )
     or die "invalid customer number: " . $opt{custnum};
 
-  my $error = $self->print( { 'template' => $opt{template} } );
+#do not backport this change to 3.x
+#  my $error = $self->print( { 'template' => $opt{template} } );
+  my $error = $self->print( $opt{'template'} );
   die $error if $error;
 }
 

commit bc68d45408c963fbf7c024c15198373dc6b1de8f
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Fri Jul 17 23:40:53 2015 -0500

    RT#37165: Print document when account is created [implemented as export]

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 90b5d29..1d4a85a 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2564,17 +2564,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', at _);
+}
+
+=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', at _);
+}
+
+=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', at _);
+}
+
+=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', at _);
+}
+
+=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 at 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

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                       |   10 +-
 FS/FS/cust_main.pm                  |   15 ++-
 FS/FS/part_export/print_template.pm |  198 +++++++++++++++++++++++++++++++++++
 FS/FS/svc_acct.pm                   |   41 +-------
 4 files changed, 214 insertions(+), 50 deletions(-)
 create mode 100644 FS/FS/part_export/print_template.pm




More information about the freeside-commits mailing list