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