X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2Fcust_refund.pm;h=0f87679a043f7dd5610a8ace8eeff073a56e836a;hb=f3d5a1bc3bf8ffe4b2fe6a0da3b201ba988b21a8;hp=77bacdffb92cbda3d0d74fff97e86514adbec850;hpb=4f8a0bb6d0c789c7e156a446dc61dbe27938a372;p=freeside.git diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 77bacdffb..0f87679a0 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -93,10 +93,23 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + if ( $self->crednum ) { + my $cust_credit = qsearchs('cust_bill', { 'invnum' => $self->invnum } ) + or do { + $dbh->rollback if $oldAutoCommit; + return "Unknown cust_credit.crednum: ". $self->crednum; + }; + $self->custnum($cust_credit->custnum); + } + my $error = $self->check; return $error if $error; - die; + $error = $self->SUPER::insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } if ( $self->crednum ) { my $cust_credit_refund = new FS::cust_credit_refund { @@ -110,14 +123,9 @@ sub insert { $dbh->rollback if $oldAutoCommit; return $error; } - $self->custnum($cust_credit_refund->cust_credit->custnum); + #$self->custnum($cust_credit_refund->cust_credit->custnum); } - $error = $self->SUPER::insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } $dbh->commit or die $dbh->errstr if $oldAutoCommit; @@ -125,7 +133,7 @@ sub insert { } -sub upgrade_replace { +sub upgrade_replace { #1.3.x->1.4.x my $self = shift; local $SIG{HUP} = 'IGNORE'; @@ -162,7 +170,7 @@ sub upgrade_replace { die; } - $error = $new->SUPER::insert($self); + $error = $new->SUPER::replace($self); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -206,18 +214,20 @@ sub check { my $error = $self->ut_number('refundnum') - || $self->ut_number('custnum') + || $self->ut_numbern('custnum') || $self->ut_money('amount') || $self->ut_numbern('_date') || $self->ut_textn('paybatch') ; return $error if $error; + return "amount must be > 0 " if $self->amount == 0; + $self->_date(time) unless $self->_date; return "unknown cust_main.custnum: ". $self->custnum - unless $self->invnum - || qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); + unless $self->crednum + || qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby"; $self->payby($1); @@ -249,7 +259,7 @@ sub check { =head1 VERSION -$Id: cust_refund.pm,v 1.8 2001-09-02 05:38:13 ivan Exp $ +$Id: cust_refund.pm,v 1.11 2002-01-24 06:46:29 ivan Exp $ =head1 BUGS