X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2Fcust_pay_pending.pm;h=48748025e71e68fe942c9199b7b62af33cd8a11d;hb=fb48167caac4b049e455531b9a3888dcd8b46c2e;hp=b61635d2f10aef4be89c362a6409de6311291b79;hpb=8b8ebd929229c8376bb81076071c5e76d2baa0ee;p=freeside.git diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm index b61635d2f..48748025e 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -213,7 +213,7 @@ sub check { my $error = $self->ut_numbern('paypendingnum') - || $self->ut_foreign_key('custnum', 'cust_main', 'custnum') + || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') || $self->ut_money('paid') || $self->ut_numbern('_date') || $self->ut_textn('payunique') @@ -232,6 +232,10 @@ sub check { ; return $error if $error; + if (!$self->custnum and !$self->get('custnum_pending')) { + return 'custnum required'; + } + $self->_date(time) unless $self->_date; # UNIQUE index should catch this too, without race conditions, but this @@ -451,6 +455,26 @@ sub decline { $self->replace; } +=item reverse [ STATUSTEXT ] + +Sets the status of this pending payment to "done" (with statustext +"reversed (manual)" unless otherwise specified). + +Currently only used when resolving pending payments manually. + +=cut + +# almost complete false laziness with decline, +# but want to avoid confusion, in case any additional steps/defaults are ever added to either +sub reverse { + my $self = shift; + my $statustext = shift || "reversed (manual)"; + + $self->status('done'); + $self->statustext($statustext); + $self->replace; +} + # _upgrade_data # # Used by FS::Upgrade to migrate to a new database. @@ -480,6 +504,19 @@ sub _upgrade_data { #class method } +sub _upgrade_schema { + my ($class, %opts) = @_; + + # fix records where jobnum points to a nonexistent queue job + my $sql = 'UPDATE cust_pay_pending SET jobnum = NULL + WHERE NOT EXISTS ( + SELECT 1 FROM queue WHERE queue.jobnum = cust_pay_pending.jobnum + )'; + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + ''; +} + =back =head1 BUGS