fix ticketing system error on bootstrap of new install
[freeside.git] / bin / payment-faker
1 #!/usr/bin/perl
2
3 use Date::Parse;
4 use FS::UID qw(adminsuidsetup);
5 use FS::Record qw(qsearch);
6 use FS::cust_pay;
7 use FS::cust_credit;
8
9 my $user;
10 $user = shift or die "usage: payment-faker $user";
11 adminsuidsetup($user);
12
13 for $month ( 1 .. 11 ) {
14
15   print "month $month\n";
16
17   system(qq!freeside-daily -d "$month/1/2006" $user!);
18
19   foreach my $cust_main ( qsearch('cust_main', {} ) ) {
20     next unless $cust_main->balance > 0;
21     my $item = '';
22     if ( rand() > .95 ) {
23       $item = new FS::cust_credit {
24         'amount' => $cust_main->balance,
25         '_date'  => str2time("$month/1/2006"),
26         'reason' => 'testing',
27       };
28     } else {
29
30       if ( rand() > .5 ) {
31         $payby = 'BILL';
32         $payinfo = int(rand(10000));
33       } else {
34         $payby = 'CARD';
35         $payinfo = '4111111111111111';
36       }
37
38       $item = new FS::cust_pay {
39         'paid'   => $cust_main->balance,
40         '_date'  => str2time("$month/1/2006"),
41         'payby'  => $payby,
42         'payinfo' => $payinfo,
43       };
44     }
45
46     $item->custnum($cust_main->custnum);
47     my $error = $item->insert;
48     die $error if $error;
49     $cust_main->apply_payments;
50     $cust_main->apply_credits;
51
52   }
53
54 }