summaryrefslogtreecommitdiff
path: root/bin/customer-faker
blob: d57e5e1de866b9c9b62403ac1af8509dde5013b4 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl

use strict;
use Getopt::Std;
use Data::Faker;
use Business::CreditCard;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearch);
use FS::cust_main;
use FS::cust_pkg;
use FS::svc_acct;

my $agentnum = 1;
my $refnum = 1;

my @pkgs = ( 2, 3, 4 );
#my @pkgs = ( 4, 5, 6 );
my $svcpart = 2;

use vars qw( $opt_p );
getopts('p:');

my $user = shift or die &usage;
my $num = shift or die &usage;
adminsuidsetup($user);

my $onum = $num;
my $start = time;

my @states = qw( AL AK AS AZ AR CA CO CT DE DC FL GA GU HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND MP OH OK OR PA PR RI SC SD TN TX UT VT VI VA WA WV WI WY );
#FM MH

until ( $num-- <= 0 ) {

  my $faker = new Data::Faker;

  my $cust_main = new FS::cust_main {
    'agentnum' => $agentnum,
    'refnum'   => $refnum,
    'first'    => $faker->first_name,
    'last'     => $faker->last_name,
    'company'  => ( $num % 2 ? $faker->company. ', '. $faker->company_suffix : '' ), #half with companies..
    'address1' => $faker->street_address,
    'city'     => 'Tofutown', #missing, so everyone is from tofutown# $faker->city,
    #'state'    => $faker->us_state_abbr,
    'state'    => $states[ int(rand($#states)) ],
    'zip'      => $faker->us_zip_code,
    'country'  => 'US',
    'daytime'  => $faker->phone_number,
    'night'    => $faker->phone_number,
    #forget it, these can have extensions# 'fax'      => ( $num % 2 ? $faker->phone_number : '' ), #ditto
    #bah, forget shipping addresses
    'payby'    => 'BILL',
    'payip'    => $faker->ip_address,
  };

  if ( $opt_p eq 'CARD' || ( !$opt_p && rand() > .33 ) ) {
    $cust_main->payby('CARD');
    my $cardnum = '4123'. sprintf('%011u', int(rand(100000000000)) );
    $cust_main->payinfo( $cardnum. generate_last_digit($cardnum) );
    $cust_main->paydate( '2009-05-01' );
  } elsif ( $opt_p eq 'CHEK' || ( !$opt_p && rand() > .66 ) ) {
    $cust_main->payby('CHEK');
    my $payinfo = sprintf('%7u@%09u', int(rand(10000000)), int(rand(1000000000)) ); 
    $cust_main->payinfo($payinfo);
    $cust_main->payname( 'First International Bank of Testing' );
  }

  # could insert invoicing_list and other stuff too..  hell, could insert
  # packages, services, more
  # but i just wanted 10k customers to test the pager and this was good enough
  # not anymore, here's some services and packages
  
  my $now = time;
  my $year = 31556736; #60*60*24*365.24
  my $setup = $now - int(rand($year));

  my $cust_pkg = new FS::cust_pkg {
    'pkgpart' => $pkgs[ int(rand(scalar(@pkgs))) ],

    #some dates in here would be nice
    'setup'      => $setup,
    #'last_bill'
    #'bill'
    #'susp'
    #'expire'
    #'cancel'
  };

  my $svc_acct = new FS::svc_acct {
    'svcpart'  => $svcpart,
    'username' => $faker->username,
  };

  while ( qsearch( 'svc_acct', { 'username' => $svc_acct->username } ) ) {
    my $username = $svc_acct->username;
    $username++;
    $svc_acct->username($username);
  }

  use Tie::RefHash;
  tie my %hash, 'Tie::RefHash',
    $cust_pkg => [ $svc_acct ],
  ;

  my $error = $cust_main->insert( \%hash );
  die $error if $error;

}

my $end = time;

my $sec = $end-$start;
$sec=1 if $sec==0;
my $persec = $onum / $sec;
print "$onum customers inserted in $sec seconds ($persec customers/sec)\n";

#---

sub usage {
  die "Usage:\n\n  customer-faker [ -p payby ] user num_fakes\n";
}