event action to send a notice to a fixed address, RT#8209
authormark <mark>
Wed, 22 Sep 2010 23:04:32 +0000 (23:04 +0000)
committermark <mark>
Wed, 22 Sep 2010 23:04:32 +0000 (23:04 +0000)
FS/FS/msg_template.pm
FS/FS/part_event/Action/notice.pm
FS/FS/part_event/Action/notice_to.pm [new file with mode: 0644]
httemplate/edit/msg_template.html

index 50298d2..7321351 100644 (file)
@@ -168,6 +168,11 @@ Customer object (required).
 Additional context object (currently, can be a cust_main, cust_pkg, 
 cust_bill, svc_acct, cust_pay, or cust_pay_pending object).
 
+=item to
+
+Destination address.  The default is to use the customer's 
+invoicing_list addresses.
+
 =back
 
 =cut
@@ -247,7 +252,7 @@ sub prepare {
   # and email
   ###
 
-  my @to = $cust_main->invoicing_list_emailonly;
+  my @to = ($opt{'to'}) || $cust_main->invoicing_list_emailonly;
   warn "prepared msg_template with no email destination (custnum ".
     $cust_main->custnum.")\n"
     if !@to;
@@ -311,6 +316,7 @@ sub substitutions {
       num_cancelled_pkgs num_ncancelled_pkgs num_pkgs
       classname categoryname
       balance
+      credit_limit
       invoicing_list_emailonly
       cust_status ucfirst_cust_status cust_statuscolor
 
index 1269653..8e22c68 100644 (file)
@@ -5,7 +5,7 @@ use base qw( FS::part_event::Action );
 use FS::Record qw( qsearchs );
 use FS::msg_template;
 
-sub description { 'Send a notice from a message template'; }
+sub description { 'Email a notice to the customer\'s billing address'; }
 
 #sub eventtable_hashref {
 #    { 'cust_main' => 1,
diff --git a/FS/FS/part_event/Action/notice_to.pm b/FS/FS/part_event/Action/notice_to.pm
new file mode 100644 (file)
index 0000000..194aeb8
--- /dev/null
@@ -0,0 +1,55 @@
+package FS::part_event::Action::notice_to;
+
+use strict;
+use base qw( FS::part_event::Action );
+use FS::Record qw( qsearchs );
+use FS::msg_template;
+
+sub description { 'Email a notice to a specific address'; }
+
+#sub eventtable_hashref {
+#    { 'cust_main' => 1,
+#      'cust_bill' => 1,
+#      'cust_pkg'  => 1,
+#    };
+#}
+
+sub option_fields {
+  (
+    'to'     => { 'label'    => 'Destination',
+                  'type'     => 'text',
+                  'size'     => 30,
+                },
+    'msgnum' => { 'label'    => 'Template',
+                  'type'     => 'select-table',
+                  'table'    => 'msg_template',
+                  'name_col' => 'msgname',
+                  'disable_empty' => 1,
+                },
+  );
+}
+
+sub default_weight { 56; } #?
+
+sub do_action {
+  my( $self, $object ) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my $msgnum = $self->option('msgnum');
+
+  my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
+      or die "Template $msgnum not found";
+
+  my $to = $self->option('to') 
+      or die "Can't send notice without a destination address";
+  
+  $msg_template->send(
+    'to'        => $to,
+    'cust_main' => $cust_main,
+    'object'    => $object,
+  );
+
+}
+
+1;
index a60f2d0..4546db9 100644 (file)
@@ -48,6 +48,7 @@ my %substitutions = (
     '$classname'      => 'Customer class',
     '$categoryname'   => 'Customer category',
     '$balance'        => 'Current balance',
+    '$credit_limit'   => 'Credit limit',
     '$invoicing_list_emailonly' => 'Billing email address',
     '$cust_status'    => 'Status',
     '$ucfirst_cust_status'  => 'Status, capitalized',