X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=e8f9aee8e4f850a04cddafd1a42449a224c08dbf;hb=0870a4c1fb02be43ea5524f58650d99c81477681;hp=54b8e90021697b5117621e7f429f62bc4d2812fb;hpb=25b36e09790470f7c7b552f8b43ce5be972fb976;p=freeside.git diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 54b8e9002..e8f9aee8e 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -190,7 +190,13 @@ If the additional field discount_term is defined then a prepayment discount is taken for that length of time. It is an error for the customer to owe after this payment is made. -A hash of optional arguments may be passed. Currently "manual" is supported. +A hash of optional arguments may be passed. The following arguments are +supported: + +=over 4 + +=item manual + If true, a payment receipt is sent instead of a statement when 'payment_receipt_email' configuration option is set. @@ -203,6 +209,13 @@ payment is created directly from the web interface, from a user-initiated realtime payment, or from a third-party payment via self-service. It should be I when creating a payment from a billing event or from a batch. +=item noemail + +Don't send an email receipt. (Note: does not currently work when +payment_receipt-trigger is set to something other than default / cust_bill) + +=back + =cut sub insert { @@ -379,6 +392,7 @@ sub insert { if ( $trigger eq 'cust_pay' ) { my $error = $self->send_receipt( 'manual' => $options{'manual'}, + 'noemail' => $options{'noemail'}, 'cust_bill' => $cust_bill, 'cust_main' => $cust_main, ); @@ -581,6 +595,12 @@ will be assumed. Customer (FS::cust_main) object (for efficiency). +=item noemail + +Don't send an email receipt. + +=cut + =back =cut @@ -674,7 +694,7 @@ sub send_receipt { 'msgtype' => 'receipt', }; $error = $queue->insert( - 'from' => $conf->config('invoice_from', $cust_main->agentnum), + 'from' => $conf->invoice_from_full( $cust_main->agentnum ), #invoice_from??? well as good as any 'to' => \@invoicing_list, 'subject' => 'Payment receipt', @@ -687,7 +707,8 @@ sub send_receipt { } - } elsif ( ! $cust_main->invoice_noemail ) { #not manual + #not manual and no noemail flag (here or on the customer) + } elsif ( ! $opt->{'noemail'} && ! $cust_main->invoice_noemail ) { my $queue = new FS::queue { 'job' => 'FS::cust_bill::queueable_email', @@ -921,10 +942,11 @@ sub _upgrade_data { #class method #not the most efficient, but hey, it only has to run once - my $where = "WHERE ( otaker IS NULL OR otaker = '' OR otaker = 'ivan' ) ". - " AND usernum IS NULL ". - " AND 0 < ( SELECT COUNT(*) FROM cust_main ". - " WHERE cust_main.custnum = cust_pay.custnum ) "; + my $where = " WHERE ( otaker IS NULL OR otaker = '' OR otaker = 'ivan' ) + AND usernum IS NULL + AND EXISTS ( SELECT 1 FROM cust_main + WHERE cust_main.custnum = cust_pay.custnum ) + "; my $count_sql = "SELECT COUNT(*) FROM cust_pay $where"; @@ -956,7 +978,6 @@ sub _upgrade_data { #class method $cust_pay->set('otaker', 'legacy'); } - delete $FS::payby::hash{'COMP'}->{cust_pay}; #quelle kludge my $error = $cust_pay->replace; if ( $error ) { @@ -965,8 +986,6 @@ sub _upgrade_data { #class method next; } - $FS::payby::hash{'COMP'}->{cust_pay} = ''; #restore it - $count++; if ( $DEBUG > 1 && $lastprog + 30 < time ) { warn "$me $count/$total (".sprintf('%.2f',100*$count/$total). '%)'."\n"; @@ -1020,9 +1039,7 @@ sub _upgrade_data { #class method # otaker->usernum upgrade ### - delete $FS::payby::hash{'COMP'}->{cust_pay}; #quelle kludge $class->_upgrade_otaker(%opt); - $FS::payby::hash{'COMP'}->{cust_pay} = ''; #restore it # if we do this anywhere else, it should become an FS::Upgrade method my $num_to_upgrade = $class->count('paybatch is not null'); @@ -1157,7 +1174,7 @@ sub batch_import { my @fields; my $payby; if ( $format eq 'simple' ) { - @fields = qw( custnum agent_custid paid payinfo ); + @fields = qw( custnum agent_custid paid payinfo invnum ); $payby = 'BILL'; } elsif ( $format eq 'extended' ) { die "unimplemented\n"; @@ -1242,9 +1259,20 @@ sub batch_import { $cust_pay{custnum} = $2; } + my $custnum = $cust_pay{custnum}; + my $cust_pay = new FS::cust_pay( \%cust_pay ); my $error = $cust_pay->insert; + if ( ! $error && $cust_pay->custnum != $custnum ) { + #invnum was defined, and ->insert set custnum to the customer for that + #invoice, but it wasn't the one the import specified. + $dbh->rollback if $oldAutoCommit; + $error = "specified invoice #". $cust_pay{invnum}. + " is for custnum ". $cust_pay->custnum. + ", not specified custnum $custnum"; + } + if ( $error ) { $dbh->rollback if $oldAutoCommit; return "can't insert payment for $line: $error";