X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pay_pkg.pm;h=eb2e80c78a832b9413e67dc76effdf879d62a1d8;hp=af331cd6f34c8cec25392ebe9eafbcb9bf59b602;hb=aed8ec35ccb9cdeb7ea0cb6ff2946f9d83d582f6;hpb=4845aaefedfcbaa25716694b6d80f3dd6d56530a diff --git a/FS/FS/cust_bill_pay_pkg.pm b/FS/FS/cust_bill_pay_pkg.pm index af331cd6f..eb2e80c78 100644 --- a/FS/FS/cust_bill_pay_pkg.pm +++ b/FS/FS/cust_bill_pay_pkg.pm @@ -2,7 +2,10 @@ package FS::cust_bill_pay_pkg; use strict; use vars qw( @ISA ); +use FS::Conf; use FS::Record qw( qsearch qsearchs ); +use FS::cust_bill_pay; +use FS::cust_bill_pkg; @ISA = qw(FS::Record); @@ -44,8 +47,15 @@ following fields are currently supported: =item setuprecur - 'setup' or 'recur', designates whether the payment was applied to the setup or recurring portion of the line item. +=item sdate - starting date of recurring fee + +=item edate - ending date of recurring fee + =back +sdate and edate are specified as UNIX timestamps; see L. Also +see L and L for conversion functions. + =head1 METHODS =over 4 @@ -70,7 +80,39 @@ otherwise returns false. =cut -# the insert method can be inherited from FS::Record +sub insert { + my($self, %options) = @_; + + #local $SIG{HUP} = 'IGNORE'; + #local $SIG{INT} = 'IGNORE'; + #local $SIG{QUIT} = 'IGNORE'; + #local $SIG{TERM} = 'IGNORE'; + #local $SIG{TSTP} = 'IGNORE'; + #local $SIG{PIPE} = 'IGNORE'; + # + #my $oldAutoCommit = $FS::UID::AutoCommit; + #local $FS::UID::AutoCommit = 0; + #my $dbh = dbh; + + my $error = $self->SUPER::insert; + if ( $error ) { + #$dbh->rollback if $oldAutoCommit; + return "error inserting $self: $error"; + } + + #payment receipt + my $conf = new FS::Conf; + my $trigger = $conf->config('payment_receipt-trigger') || 'cust_pay'; + if ( $trigger eq 'cust_bill_pay_pkg' ) { + my $error = $self->send_receipt( + 'manual' => $options{'manual'}, + ); + warn "can't send payment receipt/statement: $error" if $error; + } + + ''; + +} =item delete @@ -107,14 +149,64 @@ sub check { $self->ut_numbern('billpaypkgnum') || $self->ut_foreign_key('billpaynum', 'cust_bill_pay', 'billpaynum' ) || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum' ) + || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum') + || $self->ut_foreign_keyn('billpkgtaxlocationnum', + 'cust_bill_pkg_tax_location', + 'billpkgtaxlocationnum') + || $self->ut_foreign_keyn('billpkgtaxratelocationnum', + 'cust_bill_pkg_tax_rate_location', + 'billpkgtaxratelocationnum') || $self->ut_money('amount') || $self->ut_enum('setuprecur', [ 'setup', 'recur' ] ) + || $self->ut_numbern('sdate') + || $self->ut_numbern('edate') ; return $error if $error; $self->SUPER::check; } +=item cust_bill_pay + +Returns the FS::cust_bill_pay object (payment application to the overall +invoice). + +=cut + +sub cust_bill_pay { + my $self = shift; + qsearchs('cust_bill_pay', { 'billpaynum' => $self->billpaynum } ); +} + +=item cust_bill_pkg + +Returns the FS::cust_bill_pkg object (line item to which payment is applied). + +=cut + +sub cust_bill_pkg { + my $self = shift; + qsearchs('cust_bill_pkg', { 'billpkgnum' => $self->billpkgnum } ); +} + +=item send_receipt + +Sends a payment receipt for the associated payment, against this specific +invoice and packages. If there is an error, returns the error, otherwise +returns false. + +=cut + +sub send_receipt { + my $self = shift; + my $opt = ref($_[0]) ? shift : { @_ }; + $self->cust_bill_pay->send_receipt( + 'cust_pkg' => scalar($self->cust_bill_pkg->cust_pkg), + %$opt, + ); +} + + =back =head1 BUGS