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',
'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";
}
|| $self->ut_money('paid')
|| $self->ut_numbern('_date')
|| $self->ut_textn('paybatch')
+ || $self->ut_textn('payunique')
|| $self->ut_enum('closed', [ '', 'Y' ])
|| $self->payinfo_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;
}