This commit was generated by cvs2svn to compensate for changes in r5562,
[freeside.git] / bin / customer-faker
1 #!/usr/bin/perl
2
3 use strict;
4 use Getopt::Std;
5 use Data::Faker;
6 use Business::CreditCard;
7 use FS::UID qw(adminsuidsetup);
8 use FS::Record qw(qsearch);
9 use FS::cust_main;
10 use FS::cust_pkg;
11 use FS::svc_acct;
12
13 my $agentnum = 1;
14 my $refnum = 1;
15
16 #my @pkgs = ( 2, 3, 4 );
17 my @pkgs = ( 4, 5, 6 );
18 my $svcpart = 2;
19
20 use vars qw( $opt_p );
21 getopts('p:');
22
23 my $user = shift or die &usage;
24 my $num = shift or die &usage;
25 adminsuidsetup($user);
26
27 my $onum = $num;
28 my $start = time;
29
30 until ( $num-- <= 0 ) {
31
32   my $faker = new Data::Faker;
33
34   my $cust_main = new FS::cust_main {
35     'agentnum' => $agentnum,
36     'refnum'   => $refnum,
37     'first'    => $faker->first_name,
38     'last'     => $faker->last_name,
39     'company'  => ( $num % 2 ? $faker->company. ', '. $faker->company_suffix : '' ), #half with companies..
40     'address1' => $faker->street_address,
41     'city'     => 'Tofutown', #missing, so everyone is from tofutown# $faker->city,
42     'state'    => $faker->us_state_abbr,
43     'zip'      => $faker->us_zip_code,
44     'country'  => 'US',
45     'daytime'  => $faker->phone_number,
46     'night'    => $faker->phone_number,
47     #forget it, these can have extensions# 'fax'      => ( $num % 2 ? $faker->phone_number : '' ), #ditto
48     #bah, forget shipping addresses
49     'payby'    => 'BILL',
50     'payip'    => $faker->ip_address,
51   };
52
53   if ( $opt_p eq 'CARD' || ( !$opt_p && rand() > .33 ) ) {
54     $cust_main->payby('CARD');
55     my $cardnum = '4123'. sprintf('%011u', int(rand(100000000000)) );
56     $cust_main->payinfo( $cardnum. generate_last_digit($cardnum) );
57     $cust_main->paydate( '2009-05-01' );
58   } elsif ( $opt_p eq 'CHEK' || ( !$opt_p && rand() > .66 ) ) {
59     $cust_main->payby('CHEK');
60     my $payinfo = sprintf('%7u@%09u', int(rand(10000000)), int(rand(1000000000)) ); 
61     $cust_main->payinfo($payinfo);
62     $cust_main->payname( 'First International Bank of Testing' );
63   }
64
65   # could insert invoicing_list and other stuff too..  hell, could insert
66   # packages, services, more
67   # but i just wanted 10k customers to test the pager and this was good enough
68   # not anymore, here's some services and packages
69   
70   my $now = time;
71   my $year = 31556736; #60*60*24*365.24
72   my $setup = $now - int(rand($year));
73
74   my $cust_pkg = new FS::cust_pkg {
75     'pkgpart' => $pkgs[ int(rand(scalar(@pkgs))) ],
76
77     #some dates in here would be nice
78     'setup'      => $setup,
79     #'last_bill'
80     #'bill'
81     #'susp'
82     #'expire'
83     #'cancel'
84   };
85
86   my $svc_acct = new FS::svc_acct {
87     'svcpart'  => $svcpart,
88     'username' => $faker->username,
89   };
90
91   while ( qsearch( 'svc_acct', { 'username' => $svc_acct->username } ) ) {
92     my $username = $svc_acct->username;
93     $username++;
94     $svc_acct->username($username);
95   }
96
97   use Tie::RefHash;
98   tie my %hash, 'Tie::RefHash',
99     $cust_pkg => [ $svc_acct ],
100   ;
101
102   my $error = $cust_main->insert( \%hash );
103   die $error if $error;
104
105 }
106
107 my $end = time;
108
109 my $sec = $end-$start;
110 $sec=1 if $sec==0;
111 my $persec = $onum / $sec;
112 print "$onum customers inserted in $sec seconds ($persec customers/sec)\n";
113
114 #---
115
116 sub usage {
117   die "Usage:\n\n  customer-faker [ -p payby ] user num_fakes\n";
118 }