4 use vars qw( $opt_a $opt_p $opt_t $opt_k );
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
14 my $user = shift or &usage;
17 $FS::cust_main::skip_fuzzyfiles = 1;
18 $FS::cust_main::skip_fuzzyfiles = 1;
19 $FS::cust_main::import = 1;
20 $FS::cust_main::import = 1;
24 unless ( /^\s*(\d+)\s*$/ ) {
25 warn "unparsable line: $_";
30 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
31 unless ( $cust_main ) {
32 warn "unknown custnum $custnum\n";
36 my %cust_tag = ( custnum=>$custnum, tagnum=>$opt_t );
37 if ( $opt_t && ! qsearchs('cust_tag', \%cust_tag) ) {
38 my $cust_tag = new FS::cust_tag \%cust_tag;
39 my $error = $cust_tag->insert;
40 die "$error\n" if $error;
43 if ( $opt_p || $opt_a ) {
44 $cust_main->agentnum($opt_a) if $opt_a;
45 $cust_main->payby($opt_p) if $opt_p;
47 my $error = $cust_main->replace;
48 die "$error\n" if $error;
52 foreach my $k (split(/\s*,\s*/, $opt_k)) {
53 my($old, $new) = split(/\s*:\s*/, $k);
54 foreach my $cust_pkg ( qsearch('cust_pkg', {
55 'custnum' => $cust_main->custnum,
60 $cust_pkg->pkgpart($new);
61 my $error = $cust_pkg->replace;
62 die "$error\n" if $error;
70 die "usage: cust_main-bulk_change [ -a agentnum ] [ -p NEW_PAYBY ] [ -t tagnum ] [ -k old_pkgpart:new_pkgpart,... ] employee_username <custnums.txt\n";
79 cust_main-bulk_change [ -a agentnum ] [ -p NEW_PAYBY ] [ -t tagnum ] [ -k old_pkgpart:new_pkgpart,... ] username <custnums.txt
83 Command-line tool to make bulk changes to a group of customers.
87 -p: new payby, for example, I<CARD> or I<DCRD>
89 -t: tagnum to add if not present
91 -k: old_pkgpart:new_pkgpart, for example, I<5:4>. Multiple entries can be comma-separated.
93 user: Employee username
99 L<FS::payinfo_Mixin>, L<FS::cust_main>, L<FS::payby>