6 use Business::CreditCard;
7 use FS::UID qw(adminsuidsetup);
8 use FS::Record qw(qsearch);
15 #my @pkgs = ( 4, 5, 6 );
18 use vars qw( $opt_p $opt_a $opt_k );
21 my $agentnum = $opt_a || 1;
23 my @pkgs = $opt_k ? split(/,\s*/, $opt_k) : ( 2, 3, 4 );
25 my $user = shift or die &usage;
26 my $num = shift or die &usage;
27 adminsuidsetup($user);
32 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 );
35 until ( $num-- <= 0 ) {
37 my $faker = new Data::Faker;
39 my $cust_main = new FS::cust_main {
40 'agentnum' => $agentnum,
42 'first' => $faker->first_name,
43 'last' => $faker->last_name,
44 'company' => ( $num % 2 ? $faker->company. ', '. $faker->company_suffix : '' ), #half with companies..
45 'address1' => $faker->street_address,
46 'city' => 'Tofutown', #missing, so everyone is from tofutown# $faker->city,
47 #'state' => $faker->us_state_abbr,
48 'state' => $states[ int(rand($#states)) ],
49 'zip' => $faker->us_zip_code,
51 'daytime' => $faker->phone_number,
52 'night' => $faker->phone_number,
53 #forget it, these can have extensions# 'fax' => ( $num % 2 ? $faker->phone_number : '' ), #ditto
54 #bah, forget shipping addresses
56 'payip' => $faker->ip_address,
59 if ( $opt_p eq 'CARD' || ( !$opt_p && rand() > .33 ) ) {
60 $cust_main->payby('CARD');
61 my $cardnum = '4123'. sprintf('%011u', int(rand(100000000000)) );
62 $cust_main->payinfo( $cardnum. generate_last_digit($cardnum) );
63 $cust_main->paydate( '2009-05-01' );
64 } elsif ( $opt_p eq 'CHEK' || ( !$opt_p && rand() > .66 ) ) {
65 $cust_main->payby('CHEK');
66 my $payinfo = sprintf('%7u@%09u', int(rand(10000000)), int(rand(1000000000)) );
67 $cust_main->payinfo($payinfo);
68 $cust_main->payname( 'First International Bank of Testing' );
71 # could insert invoicing_list and other stuff too.. hell, could insert
72 # packages, services, more
73 # but i just wanted 10k customers to test the pager and this was good enough
74 # not anymore, here's some services and packages
77 my $year = 31556736; #60*60*24*365.24
78 my $setup = $now - int(rand($year));
80 my $cust_pkg = new FS::cust_pkg {
81 'pkgpart' => $pkgs[ int(rand(scalar(@pkgs))) ],
83 #some dates in here would be nice
92 my $svc_acct = new FS::svc_acct {
93 'svcpart' => $svcpart,
94 'username' => $faker->username,
97 while ( qsearch( 'svc_acct', { 'username' => $svc_acct->username } ) ) {
98 my $username = $svc_acct->username;
100 $svc_acct->username($username);
104 tie my %hash, 'Tie::RefHash',
105 $cust_pkg => [ $svc_acct ],
108 my $error = $cust_main->insert( \%hash );
109 die $error if $error;
115 my $sec = $end-$start;
117 my $persec = $onum / $sec;
118 print "$onum customers inserted in $sec seconds ($persec customers/sec)\n";
123 die "Usage:\n\n customer-faker [ -p payby ] [ -a agentnum ] [ -k pkgpart,pkgpart,pkgpart... ] user num_fakes\n";