backport fix for too much payment receiptery, RT#9723 / RT#9856
authorivan <ivan>
Wed, 29 Sep 2010 20:47:19 +0000 (20:47 +0000)
committerivan <ivan>
Wed, 29 Sep 2010 20:47:19 +0000 (20:47 +0000)
FS/FS/Conf.pm
FS/FS/Upgrade.pm
FS/FS/cust_pay.pm
FS/bin/freeside-upgrade

index 8b49e9c..c214d6a 100644 (file)
@@ -1227,6 +1227,13 @@ and customer address. Include units.',
   },
 
   {
   },
 
   {
+    'key'         => 'payment_receipt',
+    'section'     => 'notification',
+    'description' => 'Send payment receipts.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'payment_receipt_msgnum',
     'section'     => 'notification',
     'description' => 'Template to use for payment receipts',
     'key'         => 'payment_receipt_msgnum',
     'section'     => 'notification',
     'description' => 'Template to use for payment receipts',
@@ -2206,6 +2213,32 @@ and customer address. Include units.',
   },
 
   {
   },
 
   {
+    'key'         => 'selfservice-agent_signup',
+    'section'     => 'self-service',
+    'description' => 'Allow agent signup via self-service.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'selfservice-agent_signup-agent_type',
+    'section'     => 'self-service',
+    'description' => 'Agent type when allowing agent signup via self-service.',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::agent_type;
+                          map { $_->typenum => $_->atype }
+                               FS::Record::qsearch('agent_type', {} ); # disabled=>'' } );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::agent_type;
+                          my $agent = FS::Record::qsearchs(
+                            'agent_type', { 'typenum'=>shift }
+                          );
+                           $agent_type ? $agent_type->atype : '';
+                        },
+  },
+
+  {
     'key'         => 'card_refund-days',
     'section'     => 'billing',
     'description' => 'After a payment, the number of days a refund link will be available for that payment.  Defaults to 120.',
     'key'         => 'card_refund-days',
     'section'     => 'billing',
     'description' => 'After a payment, the number of days a refund link will be available for that payment.  Defaults to 120.',
index 333c277..22ec081 100644 (file)
@@ -12,7 +12,7 @@ use FS::svc_domain;
 $FS::svc_domain::whois_hack = 1;
 
 @ISA = qw( Exporter );
 $FS::svc_domain::whois_hack = 1;
 
 @ISA = qw( Exporter );
-@EXPORT_OK = qw( upgrade_schema upgrade upgrade_sqlradius );
+@EXPORT_OK = qw( upgrade_schema upgrade_config upgrade upgrade_sqlradius );
 
 $DEBUG = 1;
 
 
 $DEBUG = 1;
 
@@ -33,6 +33,22 @@ database upgrades.
 
 =over 4
 
 
 =over 4
 
+=item upgrade_config
+
+=cut
+
+#config upgrades
+sub upgrade_config {
+  my %opt = @_;
+
+  my $conf = new FS::Conf;
+
+  $conf->touch('payment_receipt')
+    if $conf->exists('payment_receipt_email')
+    || $conf->config('payment_receipt_msgnum');
+
+}
+
 =item upgrade
 
 =cut
 =item upgrade
 
 =cut
index 2ef9a1c..6dad3d7 100644 (file)
@@ -446,17 +446,20 @@ sub send_receipt {
 
   my $conf = new FS::Conf;
 
 
   my $conf = new FS::Conf;
 
+  return '' unless $conf->exists('payment_receipt');
+
   my @invoicing_list = $cust_main->invoicing_list_emailonly;
   return '' unless @invoicing_list;
 
   $cust_bill ||= ($cust_main->cust_bill)[-1]; #rather inefficient though?
 
   my @invoicing_list = $cust_main->invoicing_list_emailonly;
   return '' unless @invoicing_list;
 
   $cust_bill ||= ($cust_main->cust_bill)[-1]; #rather inefficient though?
 
+  my $error = '';
+
   if (    ( exists($opt->{'manual'}) && $opt->{'manual'} )
   if (    ( exists($opt->{'manual'}) && $opt->{'manual'} )
-       || ! $conf->exists('invoice_html_statement') # XXX msg_template
+       || ! $conf->exists('invoice_html_statement')
        || ! $cust_bill
        || ! $cust_bill
-     ) {
-
-    my $error = '';
+     )
+  {
 
     if ( $conf->exists('payment_receipt_msgnum')
          && $conf->config('payment_receipt_msgnum')
 
     if ( $conf->exists('payment_receipt_msgnum')
          && $conf->config('payment_receipt_msgnum')
@@ -467,6 +470,7 @@ sub send_receipt {
       $error = $msg_template->send('cust_main'=> $cust_main, 'object'=> $self);
 
     } elsif ( $conf->exists('payment_receipt_email') ) {
       $error = $msg_template->send('cust_main'=> $cust_main, 'object'=> $self);
 
     } elsif ( $conf->exists('payment_receipt_email') ) {
+
       my $receipt_template = new Text::Template (
         TYPE   => 'ARRAY',
         SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
       my $receipt_template = new Text::Template (
         TYPE   => 'ARRAY',
         SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
@@ -509,21 +513,27 @@ sub send_receipt {
         'body'    => [ $receipt_template->fill_in( HASH => \%fill_in ) ],
       );
 
         'body'    => [ $receipt_template->fill_in( HASH => \%fill_in ) ],
       );
 
-    } else { # no payment_receipt_msgnum or payment_receipt_email
+    } else {
 
 
-      my $queue = new FS::queue {
-         'paynum' => $self->paynum,
-         'job'    => 'FS::cust_bill::queueable_email',
-      };
+      warn "payment_receipt is on, but no payment_receipt_msgnum or invoice_html_statement is configured\n";
 
 
-      $queue->insert(
-        'invnum'   => $cust_bill->invnum,
-        'template' => 'statement',
-      );
     }
     }
+
+  } else { #not manual
+
+    my $queue = new FS::queue {
+       'paynum' => $self->paynum,
+       'job'    => 'FS::cust_bill::queueable_email',
+    };
+
+    $error = $queue->insert(
+      'invnum'   => $cust_bill->invnum,
+      'template' => 'statement',
+    );
+
+  }
   
     warn "send_receipt: $error\n" if $error;
   
     warn "send_receipt: $error\n" if $error;
-  } #$opt{manual} || no invoice_html_statement || customer has no invoices
 }
 
 =item cust_bill_pay
 }
 
 =item cust_bill_pay
index e22afa2..d3723a1 100755 (executable)
@@ -11,7 +11,7 @@ use FS::Schema qw( dbdef dbdef_dist reload_dbdef );
 use FS::Misc::prune qw(prune_applications);
 use FS::Conf;
 use FS::Record qw(qsearch);
 use FS::Misc::prune qw(prune_applications);
 use FS::Conf;
 use FS::Record qw(qsearch);
-use FS::Upgrade qw(upgrade_schema upgrade upgrade_sqlradius);
+use FS::Upgrade qw(upgrade_schema upgrade_config upgrade upgrade_sqlradius);
 
 my $start = time;
 
 
 my $start = time;
 
@@ -199,6 +199,14 @@ $dbh = adminsuidsetup($user);
 warn "Re-initialization with updated schema completed in ". (time-$start). " seconds\n"; # if $DEBUG;
 $start = time;
 
 warn "Re-initialization with updated schema completed in ". (time-$start). " seconds\n"; # if $DEBUG;
 $start = time;
 
+upgrade_config()
+  unless $DRY_RUN || $opt_s;
+
+$dbh->commit or die $dbh->errstr;
+
+warn "Config updates completed in ". (time-$start). " seconds\n"; # if $DEBUG;
+$start = time;
+
 upgrade()
   unless $DRY_RUN || $opt_s;
 
 upgrade()
   unless $DRY_RUN || $opt_s;