X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fcustomer-faker;h=236a4124774ec0b14748290495138722c11bf16f;hp=5ddc6d4ad836c774fdac1f9ea2a6b32daaa66b62;hb=75e11f1d1a5ced24496b5732e290f7762403feb8;hpb=c8cccb4a92adceb943c635fe62dad0d034462ce0 diff --git a/bin/customer-faker b/bin/customer-faker index 5ddc6d4ad..236a41247 100755 --- a/bin/customer-faker +++ b/bin/customer-faker @@ -1,17 +1,26 @@ #!/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 Getopt::Std; +use FS::cust_pkg; +use FS::svc_acct; -my $agentnum = 1; my $refnum = 1; -use vars qw( $opt_p ); -getopts('p:'); +#my @pkgs = ( 4, 5, 6 ); +my $svcpart = 2; + +use vars qw( $opt_p $opt_a $opt_k ); +getopts('p:a:k:'); + +my $agentnum = $opt_a || 1; + +my @pkgs = $opt_k ? split(/,\s*/, $opt_k) : ( 2, 3, 4 ); my $user = shift or die &usage; my $num = shift or die &usage; @@ -20,6 +29,9 @@ 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; @@ -32,7 +44,8 @@ until ( $num-- <= 0 ) { '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' => $faker->us_state_abbr, + 'state' => $states[ int(rand($#states)) ], 'zip' => $faker->us_zip_code, 'country' => 'US', 'daytime' => $faker->phone_number, @@ -58,8 +71,41 @@ until ( $num-- <= 0 ) { # 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; + my $error = $cust_main->insert( \%hash ); die $error if $error; } @@ -74,5 +120,5 @@ 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"; + die "Usage:\n\n customer-faker [ -p payby ] [ -a agentnum ] [ -k pkgpart,pkgpart,pkgpart... ] user num_fakes\n"; }