import torrus 1.0.9
[freeside.git] / FS / FS / cust_pay_refund.pm
index af25f17..cb9dbce 100644 (file)
@@ -73,15 +73,26 @@ sub table { 'cust_pay_refund'; }
 Adds this cust_pay_refund to the database.  If there is an error, returns the
 error, otherwise returns false.
 
+=cut
+
+sub insert {
+  my $self = shift;
+  return "Can't apply refund to closed payment"
+    if $self->cust_pay->closed =~ /^Y/i;
+  return "Can't apply payment to closed refund"
+    if $self->cust_refund->closed =~ /^Y/i;
+  $self->SUPER::insert(@_);
+}
+
 =item delete
 
 =cut
 
 sub delete {
   my $self = shift;
-  return "Can't apply refund to closed payment"
+  return "Can't remove refund from closed payment"
     if $self->cust_pay->closed =~ /^Y/i;
-  return "Can't apply closed refund"
+  return "Can't remove payment from closed refund"
     if $self->cust_refund->closed =~ /^Y/i;
   $self->SUPER::delete(@_);
 }
@@ -138,26 +149,26 @@ sub check {
   $self->SUPER::check;
 }
 
-=item sub cust_credit
+=item sub cust_pay
 
-Returns the credit (see L<FS::cust_credit>)
+Returns the payment (see L<FS::cust_pay>)
 
 =cut
 
-sub cust_credit {
+sub cust_pay {
   my $self = shift;
-  qsearchs( 'cust_credit', { 'crednum' => $self->crednum } );
+  qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
 }
 
-=item cust_bill 
+=item cust_refund
 
-Returns the invoice (see L<FS::cust_bill>)
+Returns the refund (see L<FS::cust_refund>)
 
 =cut
 
-sub cust_bill {
+sub cust_refund {
   my $self = shift;
-  qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
+  qsearchs( 'cust_refund', { 'refundnum' => $self->refundnum } );
 }
 
 =back