X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_credit_refund.pm;h=ff2454d9f569a6fb48193a55cbe839e02a29e86b;hp=200e34e556fcf0abb0d6382ac3b669dee6be4d8b;hb=4a881cc149f6892da35f85b767a1e806f237a05f;hpb=51e148d543a59a3cdec24bfb5ffb839ee7b4ac72 diff --git a/FS/FS/cust_credit_refund.pm b/FS/FS/cust_credit_refund.pm index 200e34e55..ff2454d9f 100644 --- a/FS/FS/cust_credit_refund.pm +++ b/FS/FS/cust_credit_refund.pm @@ -1,4 +1,4 @@ -package cust_credit_refund; +package FS::cust_credit_refund; use strict; use vars qw( @ISA ); @@ -57,6 +57,8 @@ L and L for conversion functions. Creates a new record. To add the record to the database, see L<"insert">. +=cut + sub table { 'cust_credit_refund'; } =item insert @@ -68,43 +70,9 @@ 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; + my $error = $self->SUPER::insert; 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; - ''; } @@ -130,8 +98,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 @@ -141,18 +110,31 @@ sub check { my $error = $self->ut_numbern('creditrefundnum') || $self->ut_number('crednum') - || $self->ut_numner('refundnum') + || $self->ut_number('refundnum') || $self->ut_money('amount') || $self->ut_numbern('_date') ; return $error if $error; - $self->_date(time) unless $self->_date; + return "amount must be > 0" if $self->amount <= 0; return "unknown cust_credit.crednum: ". $self->crednum - unless qsearchs( '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 } ); - ''; #no error + $self->_date(time) unless $self->_date; + + 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; } =item cust_refund @@ -166,11 +148,22 @@ sub cust_refund { qsearchs( 'cust_refund', { 'refundnum' => $self->refundnum } ); } +=item cust_credit + +Returns the credit (see L) + +=cut + +sub cust_credit { + my $self = shift; + qsearchs( 'cust_credit', { 'crednum' => $self->crednum } ); +} + =back =head1 VERSION -$Id: cust_credit_refund.pm,v 1.2 2001-09-02 01:27:11 ivan Exp $ +$Id: cust_credit_refund.pm,v 1.11 2004-06-29 04:02:44 ivan Exp $ =head1 BUGS