summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeff <jeff>2007-01-31 04:30:49 +0000
committerjeff <jeff>2007-01-31 04:30:49 +0000
commita7ea8cde763b396d0f4ce48168c689d038263786 (patch)
tree224b5db7d94ae50ba7b9d0aaa544b2f185c52257
parent89cb729e71c400307f47eef8e9e0b295db2dfca0 (diff)
small change in payment receipt handling (ticket 1422)
-rw-r--r--FS/FS/cust_bill.pm16
-rw-r--r--FS/FS/cust_main.pm6
-rw-r--r--FS/FS/cust_pay.pm74
-rwxr-xr-xhttemplate/edit/process/cust_pay.cgi2
-rw-r--r--httemplate/misc/process/payment.cgi1
5 files changed, 68 insertions, 31 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index dc45dc32b..1016b80ec 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -571,8 +571,9 @@ sub generate_email {
'Disposition' => 'inline',
);
- $args{'from'} =~ /\@([\w\.\-]+)/ or $1 = 'example.com';
- my $content_id = join('.', rand()*(2**32), $$, time). "\@$1";
+ $args{'from'} =~ /\@([\w\.\-]+)/;
+ my $from = $1 || 'example.com';
+ my $content_id = join('.', rand()*(2**32), $$, time). "\@$from";
my $path = "$FS::UID::conf_dir/conf.$FS::UID::datasrc";
my $file;
@@ -728,6 +729,17 @@ INVOICE_FROM, if specified, overrides the default email invoice From: address.
=cut
+sub queueable_send {
+ my %opt = @_;
+
+ 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});
+
+ die $error if $error;
+}
+
sub send {
my $self = shift;
my $template = scalar(@_) ? shift : '';
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index e1fe4c6da..66d7553c2 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2739,10 +2739,12 @@ sub realtime_bop {
'payinfo' => $payinfo,
'paybatch' => $paybatch,
} );
- my $error = $cust_pay->insert;
+ my $error = $cust_pay->insert($options{'manual'} ? ( 'manual' => 1 ) : () );
if ( $error ) {
$cust_pay->invnum(''); #try again with no specific invnum
- my $error2 = $cust_pay->insert;
+ my $error2 = $cust_pay->insert( $options{'manual'} ?
+ ( 'manual' => 1 ) : ()
+ );
if ( $error2 ) {
# gah, even with transactions.
my $e = 'WARNING: Card/ACH debited but database not updated - '.
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index b8bf9f3ff..85bd4dbdf 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -99,12 +99,15 @@ Adds this payment to the database.
For backwards-compatibility and convenience, if the additional field invnum
is defined, an FS::cust_bill_pay record for the full amount of the payment
-will be created. In this case, custnum is optional.
+will be created. In this case, custnum is optional. An hash of optional
+arguments may be passed. Currently "manual" is supported. If true, a
+payment receipt is sent instead of a statement when 'payment_receipt_email'
+configuration option is set.
=cut
sub insert {
- my $self = shift;
+ my ($self, %options) = @_;
local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
@@ -117,8 +120,9 @@ sub insert {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ my $cust_bill;
if ( $self->invnum ) {
- my $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } )
+ $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } )
or do {
$dbh->rollback if $oldAutoCommit;
return "Unknown cust_bill.invnum: ". $self->invnum;
@@ -188,28 +192,31 @@ sub insert {
if ( $conf->exists('payment_receipt_email')
&& grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list
) {
+ my $error;
+ if ( exists($options{ 'manual' }) && $options{ 'manual' } ) {
+
+ my $receipt_template = new Text::Template (
+ TYPE => 'ARRAY',
+ SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
+ ) or do {
+ warn "can't create payment receipt template: $Text::Template::ERROR";
+ return '';
+ };
- my $receipt_template = new Text::Template (
- TYPE => 'ARRAY',
- SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
- ) or do {
- warn "can't create payment receipt template: $Text::Template::ERROR";
- return '';
- };
-
- my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list;
+ my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ }
+ $cust_main->invoicing_list;
- my $payby = $self->payby;
- my $payinfo = $self->payinfo;
- $payby =~ s/^BILL$/Check/ if $payinfo;
- $payinfo = $self->paymask if $payby eq 'CARD' || $payby eq 'CHEK';
- $payby =~ s/^CHEK$/Electronic check/;
+ my $payby = $self->payby;
+ my $payinfo = $self->payinfo;
+ $payby =~ s/^BILL$/Check/ if $payinfo;
+ $payinfo = $self->paymask if $payby eq 'CARD' || $payby eq 'CHEK';
+ $payby =~ s/^CHEK$/Electronic check/;
- my $error = send_email(
- 'from' => $conf->config('invoice_from'), #??? well as good as any
- 'to' => \@invoicing_list,
- 'subject' => 'Payment receipt',
- 'body' => [ $receipt_template->fill_in( HASH => {
+ $error = send_email(
+ 'from' => $conf->config('invoice_from'), #??? well as good as any
+ 'to' => \@invoicing_list,
+ 'subject' => 'Payment receipt',
+ 'body' => [ $receipt_template->fill_in( HASH => {
'date' => time2str("%a %B %o, %Y", $self->_date),
'name' => $cust_main->name,
'paynum' => $self->paynum,
@@ -217,10 +224,25 @@ sub insert {
'payby' => ucfirst(lc($payby)),
'payinfo' => $payinfo,
'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',
+ );
+ }
+ }
if ( $error ) {
- warn "can't send payment receipt: $error";
+ warn "can't send payment receipt/statement: $error";
}
}
@@ -428,7 +450,7 @@ sub batch_insert {
my $errors = 0;
my @errors = map {
- my $error = $_->insert;
+ my $error = $_->insert( 'manual' => 1 );
if ( $error ) {
$errors++;
} else {
diff --git a/httemplate/edit/process/cust_pay.cgi b/httemplate/edit/process/cust_pay.cgi
index 68342ee04..a34c88aba 100755
--- a/httemplate/edit/process/cust_pay.cgi
+++ b/httemplate/edit/process/cust_pay.cgi
@@ -20,7 +20,7 @@
% #} fields('cust_pay')
%} );
%
-%my $error = $new->insert;
+%my $error = $new->insert( 'manual' => 1 );
%
%if ($error) {
% $cgi->param('error', $error);
diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi
index 6089d27c0..a5f4d4208 100644
--- a/httemplate/misc/process/payment.cgi
+++ b/httemplate/misc/process/payment.cgi
@@ -91,6 +91,7 @@
%
%my $error = $cust_main->realtime_bop( $FS::payby::payby2bop{$payby}, $amount,
% 'quiet' => 1,
+% 'manual' => 1,
% 'payinfo' => $payinfo,
% 'paydate' => "$year-$month-01",
% 'payname' => $payname,