From: Ivan Kohler Date: Tue, 5 Mar 2013 12:10:03 +0000 (-0800) Subject: add -a and -k options to cust_main-bulk_change script, RT#21728 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=88afd367d268cc39ec09af5d20dad488cc97f1ab;p=freeside.git add -a and -k options to cust_main-bulk_change script, RT#21728 --- diff --git a/bin/cust_main-bulk_change b/bin/cust_main-bulk_change index 6e4a8e1a3..bad626faf 100755 --- a/bin/cust_main-bulk_change +++ b/bin/cust_main-bulk_change @@ -1,14 +1,15 @@ #!/usr/bin/perl use strict; -use vars qw( $opt_p $opt_t ); +use vars qw( $opt_a $opt_p $opt_t $opt_k ); 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:t:'); +getopts('a:p:t:k:'); my $user = shift or &usage; adminsuidsetup $user; @@ -37,17 +38,34 @@ 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; + } + } + } + } 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. + user: Employee username =head1 BUGS