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);
=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',
+ $self->cust_bill_pay->cust_bill->cust_main->agentnum,
+ )
+ || '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
$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->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