X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_refund.pm;h=44d4d97d6fef338953fe13c70afd52e8e0bc11b9;hb=31400e6a48702b09cd30112d2f865f2f0d115bee;hp=15335a421214f576c07d8b857da7514b9284aa7e;hpb=b3db3e68f602f3ca395a6bc272a4de6fef2d0895;p=freeside.git diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 15335a421..44d4d97d6 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -83,6 +83,10 @@ Payment Type (See L for valid payby values) Payment Information (See L for data format) +=item paycardtype + +Detected credit card type, if appropriate; autodetected. + =item paymask Masked payinfo (See L for how this works) @@ -145,19 +149,21 @@ sub insert { my $dbh = dbh; unless ($self->reasonnum) { - my $result = $self->reason( $self->getfield('reason'), - exists($options{ 'reason_type' }) - ? ('reason_type' => $options{ 'reason_type' }) - : (), - ); - unless($result) { - $dbh->rollback if $oldAutoCommit; - return "failed to set reason for $me"; #: ". $dbh->errstr; + local $@; + if ( $self->get('reason') ) { + my $reason = FS::reason->new_or_existing( + reason => $self->get('reason'), + class => 'F', + type => 'Refund reason', + ); + if ($@) { + return "failed to add refund reason: $@"; + } + $self->set('reasonnum', $reason->get('reasonnum')); + $self->set('reason', ''); } } - $self->setfield('reason', ''); - if ( $self->crednum ) { my $cust_credit = qsearchs('cust_credit', { 'crednum' => $self->crednum } ) or do { @@ -304,6 +310,7 @@ sub check { || $self->ut_numbern('_date') || $self->ut_textn('paybatch') || $self->ut_enum('closed', [ '', 'Y' ]) + || $self->ut_foreign_keyn('source_paynum', 'cust_pay', 'paynum') ; return $error if $error; @@ -508,11 +515,29 @@ sub reason { ( $self->addlinfo ? ' '.$self->addlinfo : '' ); } +sub _upgrade_schema { + #my ($class, %opts) = @_; + + my $sql = 'UPDATE cust_refund SET source_paynum = NULL + WHERE source_paynum IS NOT NULL + AND NOT EXISTS ( SELECT 1 FROM cust_pay + WHERE paynum = cust_refund.source_paynum ) + '; + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + ''; +} + # Used by FS::Upgrade to migrate to a new database. sub _upgrade_data { # class method my ($class, %opts) = @_; $class->_upgrade_reasonnum(%opts); $class->_upgrade_otaker(%opts); + + local $ignore_empty_reasonnum = 1; + + # don't set paycardtype until 4.x + #$class->upgrade_set_cardtype; } =back