X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay_pending.pm;h=b61635d2f10aef4be89c362a6409de6311291b79;hb=091ece4edf3e59b5246d66e2de950e9b234cfaf3;hp=22c929345f5c7378c76c298a18db3599bc2d7d6a;hpb=de27e71335e90813543e5c87025a6bce23bb7645;p=freeside.git diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm index 22c929345..b61635d2f 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -133,6 +133,10 @@ L id. Payment number (L) of the completed payment. +=item void_paynum + +Payment number of the payment if it's been voided. + =item invnum Invoice number (L) to try to apply this payment to. @@ -221,6 +225,7 @@ sub check { || $self->ut_foreign_keyn('paynum', 'cust_pay', 'paynum' ) || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum') || $self->ut_foreign_keyn('invnum', 'cust_bill', 'invnum') + || $self->ut_foreign_keyn('void_paynum', 'cust_pay_void', 'paynum' ) || $self->ut_flag('manual') || $self->ut_numbern('discount_term') || $self->payinfo_check() #payby/payinfo/paymask/paydate @@ -459,6 +464,20 @@ sub _upgrade_data { #class method my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; + # For cust_pay_pending records linked to voided payments, move the paynum + # to void_paynum. + $sql = + "UPDATE cust_pay_pending SET void_paynum = paynum, paynum = NULL + WHERE paynum IS NOT NULL AND void_paynum IS NULL AND EXISTS( + SELECT 1 FROM cust_pay_void + WHERE cust_pay_void.paynum = cust_pay_pending.paynum + ) AND NOT EXISTS( + SELECT 1 FROM cust_pay + WHERE cust_pay.paynum = cust_pay_pending.paynum + )"; + $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + } =back