enable CardFortress in test database, #71513
[freeside.git] / FS / FS / cust_bill_pay_pkg.pm
index cdbace9..ccfa492 100644 (file)
@@ -1,10 +1,8 @@
 package FS::cust_bill_pay_pkg;
+use base qw(  FS::cust_main_Mixin FS::Record );
 
 use strict;
-use vars qw( @ISA );
-use FS::Record qw( qsearch qsearchs );
-
-@ISA = qw(FS::Record);
+use FS::Conf;
 
 =head1 NAME
 
@@ -77,7 +75,43 @@ 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',
+                    $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
 
@@ -114,6 +148,13 @@ 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')
@@ -124,6 +165,33 @@ sub check {
   $self->SUPER::check;
 }
 
+=item cust_bill_pay
+
+Returns the FS::cust_bill_pay object (payment application to the overall
+invoice).
+
+=item cust_bill_pkg
+
+Returns the FS::cust_bill_pkg object (line item to which payment is applied).
+
+=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