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