- 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( \%hash );
- die $error if $error;
-
-}
+ # scatter start dates within the first 6 months
+ my $now = time;
+ my $period = 60*60*24*180;
+ my $start = $now + int(rand($period));
+
+ # give each customer half of the specified set of packages
+ for (my $i = 0; $i <= scalar(@pkgs)/2; $i++) {
+
+ my $pkgpart = $pkgs[ ($num + $i) % scalar(@pkgs) ],
+ my @svcs;
+ my $cust_pkg = new FS::cust_pkg {
+ 'pkgpart' => $pkgpart,
+ 'start_date' => $start,
+ };
+ foreach my $pkg_svc (qsearch('pkg_svc', { pkgpart => $pkgpart,
+ quantity => {op => '>', value => 0},
+ }))
+ {
+ my $part_svc = $pkg_svc->part_svc;
+ my $svc;
+ if ( $part_svc->svcdb eq 'svc_acct' ) {
+ $svc = new FS::svc_acct {
+ 'username' => $faker->username,
+ };
+ $svc->set_password;
+
+ while ( FS::svc_acct->count('username = ?', $svc->username) ) {
+ my $username = $svc->username;
+ $username++;
+ $svc->username($username);
+ }
+ } elsif ( $part_svc->svcdb eq 'svc_broadband' ) {
+ $svc = new FS::svc_broadband {
+ 'ip_addr' => sprintf('10.%u.%u.%u',
+ int(rand(255)),
+ int(rand(255)),
+ int(rand(255))
+ ),
+ 'mac_addr' => sprintf('00:00:%02x:%02x:%02x:%02x',
+ int(rand(255)),
+ int(rand(255)),
+ int(rand(255)),
+ int(rand(255))
+ ),
+ };
+ } elsif ( $part_svc->svcdb eq 'svc_phone' ) {
+ my $phonenum = $faker->phone_number;
+ $phonenum =~ s/\D//g;
+ $svc = new FS::svc_phone {
+ 'phonenum' => $phonenum,
+ 'pin' => sprintf('%05u', int(rand(100000))),
+ };
+ } elsif ( $part_svc->svcdb eq 'svc_domain' ) {
+ my $domain;
+ do {
+ $domain = $faker->domain_word . '.com';
+ } until FS::svc_domain->count('domain = ?', $domain) == 0;
+ $svc = new FS::svc_domain {
+ domain => $domain
+ };
+ } else {
+ # unsupported svc_x; do nothing
+ next;
+ }
+ $svc->set('svcpart', $part_svc->svcpart);
+ push @svcs, $svc;
+ } # foreach $pkg_svc
+
+ $error = $cust_main->order_pkg(
+ cust_pkg => $cust_pkg,
+ svcs => \@svcs,
+ );
+ die Dumper($cust_pkg) . "\ninserting cust_pkg:\n$error\n" if $error;
+ } # package
+
+} # customer