diff options
Diffstat (limited to 'FS')
| -rw-r--r-- | FS/FS/cust_bill.pm | 21 | ||||
| -rw-r--r-- | FS/FS/cust_pay.pm | 35 | 
2 files changed, 40 insertions, 16 deletions
| diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 00de74a97..2c0b35388 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -735,9 +735,13 @@ sub queueable_send {    my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } )      or die "invalid invoice number: " . $opt{invnum}; -  my $error = $self->send($opt{template}, $opt{agentnum}, $opt{invoice_from}); +  my @args = ( $opt{template}, $opt{agentnum} ); +  push @args, $opt{invoice_from} +    if exists($opt{invoice_from}) && $opt{invoice_from}; +  my $error = $self->send( @args );    die $error if $error; +  }  sub send { @@ -778,6 +782,21 @@ INVOICE_FROM, if specified, overrides the default email invoice From: address.  =cut +sub queueable_email { +  my %opt = @_; + +  my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } ) +    or die "invalid invoice number: " . $opt{invnum}; + +  my @args = ( $opt{template} ); +  push @args, $opt{invoice_from} +    if exists($opt{invoice_from}) && $opt{invoice_from}; + +  my $error = $self->email( @args ); +  die $error if $error; + +} +  sub email {    my $self = shift;    my $template = scalar(@_) ? shift : ''; diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 85bd4dbdf..30333e0c4 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -192,8 +192,14 @@ sub insert {    if ( $conf->exists('payment_receipt_email')         && grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list    ) { + +    $cust_bill ||= ($cust_main->cust_bill)[-1]; #rather inefficient though? +      my $error; -    if ( exists($options{ 'manual' }) && $options{ 'manual' } ) { +    if (    ( exists($options{'manual'}) && $options{'manual'} ) +         || ! $conf->exists('invoice_html_statement') +         || ! $cust_bill +       ) {        my $receipt_template = new Text::Template (          TYPE   => 'ARRAY', @@ -226,21 +232,20 @@ sub insert {                         'balance' => $cust_main->balance,                       } ) ],        ); -    }else{ -      unless($cust_bill){ -        $cust_bill = ($cust_main->cust_bill)[-1]; -      } -      if ($cust_bill) { -        my $queue = new FS::queue { -           'paynum' => $self->paynum, -           'job'    => 'FS::cust_bill::queueable_send', -        }; -        $error = $queue->insert( -          'invnum' => $cust_bill->invnum, -          'template' => 'statement', -        ); -      } + +    } else { + +      my $queue = new FS::queue { +         'paynum' => $self->paynum, +         'job'    => 'FS::cust_bill::queueable_email', +      }; +      $error = $queue->insert( +        'invnum' => $cust_bill->invnum, +        'template' => 'statement', +      ); +      } +      if ( $error ) {        warn "can't send payment receipt/statement: $error";      } | 
