X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_credit_refund.pm;h=9fc03f2d3d72799635be0abfaeaa4c743ce990c4;hp=d0deae2f34ee69b9efcb6c3075d229cff6b939f5;hb=74e058c8a010ef6feb539248a550d0bb169c1e94;hpb=58d44fbe5eb9ab32e6d87063a4a3b22ddba9a828 diff --git a/FS/FS/cust_credit_refund.pm b/FS/FS/cust_credit_refund.pm index d0deae2f3..9fc03f2d3 100644 --- a/FS/FS/cust_credit_refund.pm +++ b/FS/FS/cust_credit_refund.pm @@ -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,54 +70,27 @@ otherwise returns false. sub insert { my $self = shift; - - 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->check; - return $error if $error; - - $error = $self->SUPER::insert; - - my $cust_refund = - qsearchs('cust_refund', { 'refundnum' => $self->refundnum } ) - or do { - $dbh->rollback if $oldAutoCommit; - return "unknown cust_refund.refundnum: ". $self->refundnum - }; - - my $refund_total = 0; - $refund_total += $_ foreach map { $_->amount } - qsearch('cust_credit_refund', { 'refundnum' => $self->refundnum } ); - - if ( $refund_total > $cust_refund->refund ) { - $dbh->rollback if $oldAutoCommit; - return "total cust_credit_refund.amount $refund_total for refundnum ". - $self->refundnum. - " greater than cust_refund.refund ". $cust_refund->refund; - } - - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - - ''; + 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 @@ -132,8 +105,9 @@ sub replace { =item check -Checks all fields to make sure this is a valid payment. If there is an error, -returns the error, otherwise returns false. Called by the insert method. +Checks all fields to make sure this is a valid refund application. If there is +an error, returns the error, otherwise returns false. Called by the insert +method. =cut @@ -151,10 +125,21 @@ sub check { return "amount must be > 0" if $self->amount <= 0; + return "unknown cust_credit.crednum: ". $self->crednum + unless my $cust_credit = + qsearchs( 'cust_credit', { 'crednum' => $self->crednum } ); + + return "Unknown refund" + unless my $cust_refund = + qsearchs( 'cust_refund', { 'refundnum' => $self->refundnum } ); + $self->_date(time) unless $self->_date; - return "unknown cust_credit.crednum: ". $self->crednum - unless qsearchs( 'cust_credit', { 'crednum' => $self->crednum } ); + return "Cannot apply more than remaining value of credit" + unless $self->amount <= $cust_credit->credited; + + return "Cannot apply more than remaining value of refund" + unless $self->amount <= $cust_refund->unapplied; $self->SUPER::check; } @@ -183,10 +168,6 @@ sub cust_credit { =back -=head1 VERSION - -$Id: cust_credit_refund.pm,v 1.10 2003-08-05 00:20:41 khoff Exp $ - =head1 BUGS Delete and replace methods.