combine ticket notification scrips, #15353
[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
18 while (<STDIN>) {
19
20   unless ( /^\s*(\d+)\s*$/ ) { 
21     warn "unparsable line: $_";
22     next;
23   }
24   my $custnum = $1;
25
26   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
27   unless ( $cust_main ) {
28     warn "unknown custnum $custnum\n";
29     next;
30   }
31
32   if ( $opt_p ) {
33     $cust_main->payby($opt_p);
34   }
35
36   my $error = $cust_main->replace;
37   die "$error\n" if $error;
38
39 }
40
41 sub usage {
42   die "usage: cust_main-bulk_change -p NEW_PAYBY employee_username <custnums.txt\n";
43 }
44
45 =head1 NAME
46
47 cust_main-bulk_change
48
49 =head1 SYNOPSIS
50
51   cust_main-bulk_change -p NEW_PAYBY username <custnums.txt
52
53 =head1 DESCRIPTION
54
55 Command-line tool to change the payby field for a group of customers.
56
57 -p: new payby, for example, I<CARD> or I<DCRD>.
58
59 user: Employee username
60
61 =head1 BUGS
62
63 =head1 SEE ALSO
64
65 L<FS::payinfo_Mixin>, L<FS::cust_main>, L<FS::payby>
66
67 =cut
68
69 1;