X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fcust_main-bulk_change;h=47a9ae30a1ab14ff36f15d39e817f641b7b9bb6e;hp=02931abed9b486f357729c6fef12c376a6d3964e;hb=2a56c671635687bf2648eb3a7cf4bce228101af3;hpb=71dbaf665d70de080f9dc7a02e1ff1a1f651a416 diff --git a/bin/cust_main-bulk_change b/bin/cust_main-bulk_change index 02931abed..47a9ae30a 100755 --- a/bin/cust_main-bulk_change +++ b/bin/cust_main-bulk_change @@ -1,14 +1,16 @@ #!/usr/bin/perl use strict; -use vars qw( $opt_p $opt_t ); +use vars qw( $opt_a $opt_p $opt_t $opt_k $opt_c $opt_v $opt_E ); use Getopt::Std; use FS::UID qw(adminsuidsetup); -use FS::Record qw(qsearchs); +use FS::Record qw(qsearch qsearchs); use FS::cust_main; +use FS::cust_main::Search; use FS::cust_tag; +use FS::cust_pkg; -getopts('p:t:'); +getopts('a:p:t:k:c:vE'); my $user = shift or &usage; adminsuidsetup $user; @@ -20,16 +22,38 @@ $FS::cust_main::import = 1; while () { - unless ( /^\s*(\d+)\s*$/ ) { - warn "unparsable line: $_"; - next; + my ($custnum,$cust_main); + if ($opt_E) { + # don't really need to validate input here, search will quote safely + unless ( /^\s*(.*)\s*$/ ) { + warn "unparsable line: $_"; + next; + } + my @cust_main = FS::cust_main::Search::email_search( 'email' => $1 ); + if (@cust_main > 1) { + warn "muliple matching customers for address, skipping: $_"; + next; + } elsif (@cust_main < 1) { + warn "could not find matching customer for address, skipping: $_"; + next; + } + $cust_main = $cust_main[0]; + $custnum = $cust_main->custnum; + } else { + unless ( /^\s*(\d+)\s*$/ ) { + warn "unparsable line: $_"; + next; + } + my $custnum = $1; + $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); + unless ( $cust_main ) { + warn "unknown custnum $custnum\n"; + next; + } } - my $custnum = $1; - my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); - unless ( $cust_main ) { - warn "unknown custnum $custnum\n"; - next; + if ( $opt_v ) { + print $cust_main->custnum . ": " . $cust_main->name . "\n"; } my %cust_tag = ( custnum=>$custnum, tagnum=>$opt_t ); @@ -39,17 +63,39 @@ while () { die "$error\n" if $error; } - if ( $opt_p ) { - $cust_main->payby($opt_p); + if ( $opt_p || $opt_a ) { + $cust_main->agentnum($opt_a) if $opt_a; + $cust_main->payby($opt_p) if $opt_p; my $error = $cust_main->replace; die "$error\n" if $error; } + if ( $opt_k ) { + foreach my $k (split(/\s*,\s*/, $opt_k)) { + my($old, $new) = split(/\s*:\s*/, $k); + foreach my $cust_pkg ( qsearch('cust_pkg', { + 'custnum' => $cust_main->custnum, + 'pkgpart' => $old, + }) + ) + { + $cust_pkg->pkgpart($new); + my $error = $cust_pkg->replace; + die "$error\n" if $error; + } + } + } + + if ( $opt_c ) { + my @error = $cust_main->cancel( 'reason' => $opt_c ); + die join(' / ', @error). "\n" if @error; + } + } sub usage { - die "usage: cust_main-bulk_change [ -p NEW_PAYBY ] [ -t tagnum ] employee_username or I -t: tagnum to add if not present +-k: old_pkgpart:new_pkgpart, for example, I<5:4>. Multiple entries can be comma-separated. + +-c: Cancel customer + +-v: verbose + +-E: input is customer emails, rather than customer numbers + user: Employee username =head1 BUGS