4 use vars qw( $opt_a $opt_p $opt_t $opt_k $opt_c $opt_v $opt_E );
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
9 use FS::cust_main::Search;
13 getopts('a:p:t:k:c:vE');
15 my $user = shift or &usage;
18 $FS::cust_main::skip_fuzzyfiles = 1;
19 $FS::cust_main::skip_fuzzyfiles = 1;
20 $FS::cust_main::import = 1;
21 $FS::cust_main::import = 1;
25 my ($custnum,$cust_main);
27 # don't really need to validate input here, search will quote safely
28 unless ( /^\s*(.*)\s*$/ ) {
29 warn "unparsable line: $_";
32 my @cust_main = FS::cust_main::Search::email_search( 'email' => $1 );
34 warn "muliple matching customers for address, skipping: $_";
36 } elsif (@cust_main < 1) {
37 warn "could not find matching customer for address, skipping: $_";
40 $cust_main = $cust_main[0];
41 $custnum = $cust_main->custnum;
43 unless ( /^\s*(\d+)\s*$/ ) {
44 warn "unparsable line: $_";
48 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
49 unless ( $cust_main ) {
50 warn "unknown custnum $custnum\n";
56 print $cust_main->custnum . ": " . $cust_main->name . "\n";
59 my %cust_tag = ( custnum=>$custnum, tagnum=>$opt_t );
60 if ( $opt_t && ! qsearchs('cust_tag', \%cust_tag) ) {
61 my $cust_tag = new FS::cust_tag \%cust_tag;
62 my $error = $cust_tag->insert;
63 die "$error\n" if $error;
66 if ( $opt_p || $opt_a ) {
67 $cust_main->agentnum($opt_a) if $opt_a;
68 $cust_main->payby($opt_p) if $opt_p;
70 my $error = $cust_main->replace;
71 die "$error\n" if $error;
75 foreach my $k (split(/\s*,\s*/, $opt_k)) {
76 my($old, $new) = split(/\s*:\s*/, $k);
77 foreach my $cust_pkg ( qsearch('cust_pkg', {
78 'custnum' => $cust_main->custnum,
83 $cust_pkg->pkgpart($new);
84 my $error = $cust_pkg->replace;
85 die "$error\n" if $error;
91 my @error = $cust_main->cancel( 'reason' => $opt_c );
92 die join(' / ', @error). "\n" if @error;
98 die "usage: cust_main-bulk_change [ -a agentnum ] [ -p NEW_PAYBY ] [ -t tagnum ] [ -k old_pkgpart:new_pkgpart,... ] [-v] [-E] employee_username <custnums.txt\n";
103 cust_main-bulk_change
107 cust_main-bulk_change [ -a agentnum ] [ -p NEW_PAYBY ] [ -t tagnum ] [ -k old_pkgpart:new_pkgpart,... ] [ -c reasonnum ] username <custnums.txt
111 Command-line tool to make bulk changes to a group of customers.
115 -p: new payby, for example, I<CARD> or I<DCRD>
117 -t: tagnum to add if not present
119 -k: old_pkgpart:new_pkgpart, for example, I<5:4>. Multiple entries can be comma-separated.
125 -E: input is customer emails, rather than customer numbers
127 user: Employee username
133 L<FS::payinfo_Mixin>, L<FS::cust_main>, L<FS::payby>