6 use Business::CreditCard;
7 use FS::UID qw(adminsuidsetup);
8 use FS::Record qw(qsearch);
16 my @pkgs = ( 2, 3, 4 );
17 #my @pkgs = ( 4, 5, 6 );
20 use vars qw( $opt_p );
23 my $user = shift or die &usage;
24 my $num = shift or die &usage;
25 adminsuidsetup($user);
30 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 );
33 until ( $num-- <= 0 ) {
35 my $faker = new Data::Faker;
37 my $cust_main = new FS::cust_main {
38 'agentnum' => $agentnum,
40 'first' => $faker->first_name,
41 'last' => $faker->last_name,
42 'company' => ( $num % 2 ? $faker->company. ', '. $faker->company_suffix : '' ), #half with companies..
43 'address1' => $faker->street_address,
44 'city' => 'Tofutown', #missing, so everyone is from tofutown# $faker->city,
45 #'state' => $faker->us_state_abbr,
46 'state' => $states[ int(rand($#states)) ],
47 'zip' => $faker->us_zip_code,
49 'daytime' => $faker->phone_number,
50 'night' => $faker->phone_number,
51 #forget it, these can have extensions# 'fax' => ( $num % 2 ? $faker->phone_number : '' ), #ditto
52 #bah, forget shipping addresses
54 'payip' => $faker->ip_address,
57 if ( $opt_p eq 'CARD' || ( !$opt_p && rand() > .33 ) ) {
58 $cust_main->payby('CARD');
59 my $cardnum = '4123'. sprintf('%011u', int(rand(100000000000)) );
60 $cust_main->payinfo( $cardnum. generate_last_digit($cardnum) );
61 $cust_main->paydate( '2009-05-01' );
62 } elsif ( $opt_p eq 'CHEK' || ( !$opt_p && rand() > .66 ) ) {
63 $cust_main->payby('CHEK');
64 my $payinfo = sprintf('%7u@%09u', int(rand(10000000)), int(rand(1000000000)) );
65 $cust_main->payinfo($payinfo);
66 $cust_main->payname( 'First International Bank of Testing' );
69 # could insert invoicing_list and other stuff too.. hell, could insert
70 # packages, services, more
71 # but i just wanted 10k customers to test the pager and this was good enough
72 # not anymore, here's some services and packages
75 my $year = 31556736; #60*60*24*365.24
76 my $setup = $now - int(rand($year));
78 my $cust_pkg = new FS::cust_pkg {
79 'pkgpart' => $pkgs[ int(rand(scalar(@pkgs))) ],
81 #some dates in here would be nice
90 my $svc_acct = new FS::svc_acct {
91 'svcpart' => $svcpart,
92 'username' => $faker->username,
95 while ( qsearch( 'svc_acct', { 'username' => $svc_acct->username } ) ) {
96 my $username = $svc_acct->username;
98 $svc_acct->username($username);
102 tie my %hash, 'Tie::RefHash',
103 $cust_pkg => [ $svc_acct ],
106 my $error = $cust_main->insert( \%hash );
107 die $error if $error;
113 my $sec = $end-$start;
115 my $persec = $onum / $sec;
116 print "$onum customers inserted in $sec seconds ($persec customers/sec)\n";
121 die "Usage:\n\n customer-faker [ -p payby ] user num_fakes\n";