work around missing id, RT#83146
[freeside.git] / FS / bin / freeside-phonenum_list
1 #!/usr/bin/perl
2
3 use strict;
4 use vars qw( $opt_c $opt_o $opt_l $opt_p $opt_b $opt_d $opt_s $opt_t );
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Conf;
8 use FS::Record qw(qsearch);
9 use FS::svc_phone;
10
11 getopts('colp:b:d:s:t:');
12
13 my $user = shift or &usage;
14 adminsuidsetup $user;
15
16 my $conf = new FS::Conf;
17 my $default_locale = $conf->config('locale') || 'en_US';
18
19 my %search = ();
20
21 $search{payby}        = [ split(/\s*,\s*/, $opt_p) ] if $opt_p;
22 $search{balance}      = $opt_b                       if $opt_b;
23 $search{balance_days} = $opt_d                       if $opt_d;
24 $search{svcpart}      = [ split(/\s*,\s*/, $opt_s) ] if $opt_s;
25 $search{cust_status}  = lc($opt_t)                   if $opt_t;
26
27 my @svc_phone = qsearch( FS::svc_phone->search(\%search) );
28
29 foreach my $svc_phone (@svc_phone) {
30   print $svc_phone->countrycode if $opt_c;
31   print $svc_phone->phonenum;
32   print '@'. $svc_phone->domain if $opt_o;
33   if ( $opt_l ) {
34     my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
35     print ','. ($cust_pkg && $cust_pkg->cust_main->locale || $default_locale);
36   }
37   print "\n";  
38 }
39
40 sub usage {
41   die "usage: freeside-phonenum_list [ -c ] [ -o ] [ -l ] [ -p payby,payby... ] [ -b balance [ -d balance_days ] ] [ -s svcpart,svcpart... ] username \n";
42 }
43
44 =head1 NAME
45
46 freeside-phonenum_list
47
48 =head1 SYNOPSIS
49   freeside-phonenum_list [ -c ] [ -o ] [ -l ] [ -p payby,payby... ] [ -b balance [ -d balance_days ] ] [ -s svcpart,svcpart... ] username
50
51 =head1 DESCRIPTION
52
53 Command-line tool to list phone numbers.
54
55 Display options:
56
57 -c: Include country code
58
59 -o: Include domain
60
61 -l: Include customer locale
62
63 Selection options:
64
65 -p: Customer payby (CARD, BILL, etc.).  Separate multiple values with commas.
66
67 -b: Customer balance over (or equal to) this amount
68
69 -d: Customer balance age over this many days 
70
71 -s: Service definition (svcpart).  Separate multiple values with commas.
72
73 -t: Customer status: prospect, active, ordered, inactive, suspended or cancelled
74
75 username: Employee username
76
77 =head1 BUGS
78
79 =head1 SEE ALSO
80
81 L<FS::svc_phone>, L<FS::cust_main>
82
83 =cut
84
85 1;
86