summaryrefslogtreecommitdiff
path: root/bin/cust_main.restore-paymask
blob: c6c8a75ec9d97d6871b96b3075890ed2e81277e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl

use strict;
use FS::UID qw( adminsuidsetup );
use FS::Record qw( qsearch dbh );

adminsuidsetup shift
  or die "Usage: cust_main.restore-paymask freeside_username\n";

foreach my $cust_main ( 
  qsearch({ 'table' => 'cust_main',
            'extra_sql' => q[WHERE payby IN ('CARD','DCRD') AND paymask IS NULL OR paymask = 'N/A (tokenized)'],
         })
) {

  my $custnum = $cust_main->custnum;

  my $paymask = FS::Record->scalar_sql(qq[
    SELECT paymask FROM h_cust_main WHERE custnum = $custnum AND history_action = 'replace_old' AND paymask IS NOT NULL AND paymask != 'N/A (tokenized)' ORDER BY historynum desc LIMIT 1
  ]);

  #dbh->do(
  print
    qq[UPDATE cust_main SET paymask = '$paymask' WHERE custnum = $custnum;]
  ."\n"
  ;

  #print "$custnum: $paymask\n";
}

1;