X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fcust_main-bulk_change;h=e0390127276260765619b934358642702096444c;hp=618856cdcdea47ebca9479c0d8dba72c1d3a3a7e;hb=7a24977570328ce710e55d13cfd0fe5c5c40e67a;hpb=b5c4237a34aef94976bc343c8d9e138664fc3984 diff --git a/bin/cust_main-bulk_change b/bin/cust_main-bulk_change index 618856cdc..e03901272 100755 --- a/bin/cust_main-bulk_change +++ b/bin/cust_main-bulk_change @@ -1,19 +1,23 @@ #!/usr/bin/perl use strict; -use vars qw( $opt_p ); +use vars qw( $opt_a $opt_p $opt_t $opt_k $opt_c ); 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_tag; +use FS::cust_pkg; -getopts('p:'); +getopts('a:p:t:k:c:'); my $user = shift or &usage; adminsuidsetup $user; $FS::cust_main::skip_fuzzyfiles = 1; $FS::cust_main::skip_fuzzyfiles = 1; +$FS::cust_main::import = 1; +$FS::cust_main::import = 1; while () { @@ -29,17 +33,46 @@ while () { next; } - if ( $opt_p ) { - $cust_main->payby($opt_p); + my %cust_tag = ( custnum=>$custnum, tagnum=>$opt_t ); + if ( $opt_t && ! qsearchs('cust_tag', \%cust_tag) ) { + my $cust_tag = new FS::cust_tag \%cust_tag; + my $error = $cust_tag->insert; + die "$error\n" if $error; } - my $error = $cust_main->replace; - die "$error\n" if $error; + 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 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. --p: new payby, for example, I or I. +-c: Cancel customer user: Employee username