import torrus 1.0.9
[freeside.git] / FS / FS / cust_credit_refund.pm
index ff2454d..9fc03f2 100644 (file)
@@ -3,11 +3,11 @@ package FS::cust_credit_refund;
 use strict;
 use vars qw( @ISA );
 use FS::Record qw( qsearch qsearchs dbh );
-#use FS::UID qw(getotaker);
+use FS::cust_main_Mixin;
 use FS::cust_credit;
 use FS::cust_refund;
 
-@ISA = qw( FS::Record );
+@ISA = qw( FS::cust_main_Mixin FS::Record );
 
 =head1 NAME
 
@@ -70,20 +70,27 @@ otherwise returns false.
 
 sub insert {
   my $self = shift;
-  my $error = $self->SUPER::insert;
-  return $error if $error;
-
-  '';
+  return "Can't apply refund to closed credit"
+    if $self->cust_credit->closed =~ /^Y/i;
+  return "Can't apply credit to closed refund"
+    if $self->cust_refund->closed =~ /^Y/i;
+  $self->SUPER::insert(@_);
 }
 
 =item delete
 
-Currently unimplemented (accounting reasons).
+Remove this cust_credit_refund from the database.  If there is an error, 
+returns the error, otherwise returns false.
 
 =cut
 
 sub delete {
-  return "Can't (yet?) delete cust_credit_refund records!";
+  my $self = shift;
+  return "Can't remove refund from closed credit"
+    if $self->cust_credit->closed =~ /^Y/i;
+  return "Can't remove credit from closed refund"
+    if $self->cust_refund->closed =~ /^Y/i;
+  $self->SUPER::delete(@_);
 }
 
 =item replace OLD_RECORD
@@ -161,10 +168,6 @@ sub cust_credit {
 
 =back
 
-=head1 VERSION
-
-$Id: cust_credit_refund.pm,v 1.11 2004-06-29 04:02:44 ivan Exp $
-
 =head1 BUGS
 
 Delete and replace methods.