add -t option to cust_main-bulk_change, RT#21036
[freeside.git] / bin / cust_main-bulk_change
1 #!/usr/bin/perl
2
3 use strict;
4 use vars qw( $opt_p $opt_t );
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearchs);
8 use FS::cust_main;
9 use FS::cust_tag;
10
11 getopts('p:t:');
12
13 my $user = shift or &usage;
14 adminsuidsetup $user;
15
16 $FS::cust_main::skip_fuzzyfiles = 1;
17 $FS::cust_main::skip_fuzzyfiles = 1;
18
19 while (<STDIN>) {
20
21   unless ( /^\s*(\d+)\s*$/ ) { 
22     warn "unparsable line: $_";
23     next;
24   }
25   my $custnum = $1;
26
27   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
28   unless ( $cust_main ) {
29     warn "unknown custnum $custnum\n";
30     next;
31   }
32
33   my %cust_tag = ( custnum=>$custnum, tagnum=>$opt_t );
34   if ( $opt_t && ! qsearchs('cust_tag', \%cust_tag) ) {
35     my $cust_tag = new FS::cust_tag \%cust_tag;
36     my $error = $cust_tag->insert;
37     die "$error\n" if $error;
38   }
39
40   if ( $opt_p ) {
41     $cust_main->payby($opt_p);
42
43     my $error = $cust_main->replace;
44     die "$error\n" if $error;
45   }
46
47 }
48
49 sub usage {
50   die "usage: cust_main-bulk_change [ -p NEW_PAYBY ] [ -t tagnum ] employee_username <custnums.txt\n";
51 }
52
53 =head1 NAME
54
55 cust_main-bulk_change
56
57 =head1 SYNOPSIS
58
59   cust_main-bulk_change [ -p NEW_PAYBY ] [ -t tagnum ] username <custnums.txt
60
61 =head1 DESCRIPTION
62
63 Command-line tool to make bulk changes to a group of customers.
64
65 -p: new payby, for example, I<CARD> or I<DCRD>
66
67 -t: tagnum to add if not present
68
69 user: Employee username
70
71 =head1 BUGS
72
73 =head1 SEE ALSO
74
75 L<FS::payinfo_Mixin>, L<FS::cust_main>, L<FS::payby>
76
77 =cut
78
79 1;