X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=87fad02f1a3711b2c4460e51eb6171d34368eace;hb=6d47b55c98b1a8e145a4b63579e148241c65b6ed;hp=775c353e48c0c90d5385091bd5cf8009ec2e8688;hpb=6e0f3e5ce5de21104124afa048b2787e36ac0131;p=freeside.git diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 775c353e4..87fad02f1 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -11,6 +11,7 @@ use Business::CreditCard; use Text::Template; use FS::Misc::DateTime qw( parse_datetime ); #for batch_import use FS::Record qw( dbh qsearch qsearchs ); +use FS::UID qw( driver_name ); use FS::CurrentUser; use FS::payby; use FS::cust_main_Mixin; @@ -189,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. @@ -202,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 { @@ -378,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, ); @@ -580,6 +595,12 @@ will be assumed. Customer (FS::cust_main) object (for efficiency). +=item noemail + +Don't send an email receipt. + +=cut + =back =cut @@ -686,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', @@ -892,6 +914,13 @@ sub unapplied_sql { } +sub API_getinfo { + my $self = shift; + my @fields = grep { $_ ne 'payinfo' } $self->fields; + +{ ( map { $_=>$self->$_ } @fields ), + }; +} + # _upgrade_data # # Used by FS::Upgrade to migrate to a new database. @@ -1043,9 +1072,10 @@ sub process_upgrade_paybatch { ### # migrate batchnums from the misused 'paybatch' field to 'batchnum' ### + my $text = (driver_name =~ /^mysql/i) ? 'char' : 'text'; my $search = FS::Cursor->new( { 'table' => 'cust_pay', - 'addl_from' => ' JOIN pay_batch ON cust_pay.paybatch = CAST(pay_batch.batchnum AS text) ', + 'addl_from' => " JOIN pay_batch ON cust_pay.paybatch = CAST(pay_batch.batchnum AS $text) ", } ); while (my $cust_pay = $search->fetch) { $cust_pay->set('batchnum' => $cust_pay->paybatch); @@ -1148,7 +1178,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"; @@ -1233,9 +1263,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";