summaryrefslogtreecommitdiff
path: root/bin/cust_main-bulk_change
blob: 02931abed9b486f357729c6fef12c376a6d3964e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl

use strict;
use vars qw( $opt_p $opt_t );
use Getopt::Std;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearchs);
use FS::cust_main;
use FS::cust_tag;

getopts('p:t:');

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 (<STDIN>) {

  unless ( /^\s*(\d+)\s*$/ ) { 
    warn "unparsable line: $_";
    next;
  }
  my $custnum = $1;

  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
  unless ( $cust_main ) {
    warn "unknown custnum $custnum\n";
    next;
  }

  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;
  }

  if ( $opt_p ) {
    $cust_main->payby($opt_p);

    my $error = $cust_main->replace;
    die "$error\n" if $error;
  }

}

sub usage {
  die "usage: cust_main-bulk_change [ -p NEW_PAYBY ] [ -t tagnum ] employee_username <custnums.txt\n";
}

=head1 NAME

cust_main-bulk_change

=head1 SYNOPSIS

  cust_main-bulk_change [ -p NEW_PAYBY ] [ -t tagnum ] username <custnums.txt

=head1 DESCRIPTION

Command-line tool to make bulk changes to a group of customers.

-p: new payby, for example, I<CARD> or I<DCRD>

-t: tagnum to add if not present

user: Employee username

=head1 BUGS

=head1 SEE ALSO

L<FS::payinfo_Mixin>, L<FS::cust_main>, L<FS::payby>

=cut

1;