- unless ( FS::upgrade_journal->is_done('cust_main__cust_payby') ) {
-
- #we don't want to decrypt them, just stuff them as-is into cust_payby
- local(@encrypted_fields) = ();
-
- local($FS::cust_payby::ignore_expired_card) = 1;
- local($FS::cust_payby::ignore_banned_card) = 1;
-
- my @payfields = qw( payby payinfo paycvv paymask
- paydate paystart_month paystart_year payissue
- payname paystate paytype payip
- );
-
- my $search = new FS::Cursor {
- 'table' => 'cust_main',
- 'extra_sql' => " WHERE ( payby IS NOT NULL AND payby != '' ) ",
- };
-
- while (my $cust_main = $search->fetch) {
-
- unless ( $cust_main->payby =~ /^(BILL|COMP)$/ ) {
-
- my $cust_payby = new FS::cust_payby {
- 'custnum' => $cust_main->custnum,
- 'weight' => 1,
- map { $_ => $cust_main->$_(); } @payfields
- };
-
- my $error = $cust_payby->insert;
- die $error if $error;
-
- }
-
- # at the time we do this, also migrate paytype into cust_pay_batch
- # so that batches that are open before the migration can still be
- # processed
- my @cust_pay_batch = qsearch('cust_pay_batch', {
- 'custnum' => $cust_main->custnum,
- 'payby' => 'CHEK',
- 'paytype' => '',
- });
- foreach my $cust_pay_batch (@cust_pay_batch) {
- $cust_pay_batch->set('paytype', $cust_main->get('paytype'));
- my $error = $cust_pay_batch->replace;
- die "$error (setting cust_pay_batch.paytype)" if $error;
- }
-
- $cust_main->complimentary('Y') if $cust_main->payby eq 'COMP';
-
- $cust_main->invoice_attn( $cust_main->payname )
- if $cust_main->payby eq 'BILL' && $cust_main->payname;
- $cust_main->po_number( $cust_main->payinfo )
- if $cust_main->payby eq 'BILL' && $cust_main->payinfo;
-
- $cust_main->setfield($_, '') foreach @payfields;
- my $error = $cust_main->replace;
- die "Error upgradging payment information for custnum ".
- $cust_main->custnum. ": $error"
- if $error;
-
- };
-
- FS::upgrade_journal->set_done('cust_main__cust_payby');
- }
-