X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=0ead2265860513b0b26883a3722b226d7a17a333;hb=f0547b5c6821995268ae3a68dbc80eef08885b77;hp=85bd4dbdfd6d1b62df4e9d6ba3fde1c2a9c11080;hpb=a7ea8cde763b396d0f4ce48168c689d038263786;p=freeside.git diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 85bd4dbdf..0ead22658 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"; } @@ -398,6 +403,7 @@ sub check { || $self->ut_money('paid') || $self->ut_numbern('_date') || $self->ut_textn('paybatch') + || $self->ut_textn('payunique') || $self->ut_enum('closed', [ '', 'Y' ]) || $self->payinfo_check() ; @@ -411,6 +417,13 @@ sub check { $self->_date(time) unless $self->_date; + # UNIQUE index should catch this too, without race conditions, but this + # should give a better error message the other 99.9% of the time... + if ( length($self->payunique) + && qsearchs('cust_pay', { 'payunique' => $self->payunique } ) ) { + return "duplicate transaction"; #well, it *could* be a better error message + } + $self->SUPER::check; }