summaryrefslogtreecommitdiff
path: root/FS/t/suite/02-bill_customer.t
blob: e3f6406f45bcfe852b5af9b07f587c458c7528c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl

use FS::Test;
use Test::More tests => 6;
use Test::MockTime 'set_fixed_time';
use Date::Parse 'str2time';
use FS::cust_main;

my $FS = FS::Test->new;

# After test 01: cust#2 has a package set to bill on 2016-03-20.
# Set local time.
my $date = '2016-03-20';
set_fixed_time(str2time($date));
my $cust_main = FS::cust_main->by_key(2);
my @return;

# Bill the customer.
my $error = $cust_main->bill( return_bill => \@return );
ok($error eq '', "billed on $date") or diag($error);

# should be an invoice now
my $cust_bill = $return[0];
isa_ok($cust_bill, 'FS::cust_bill');

# Apr 1 - Mar 20 = 12 days
# 12/31 * $30 = 11.61 recurring, + 20.00 setup
ok( $cust_bill->charged == 31.61, 'prorated first month correctly' );

# the package bill date should now be 2016-04-01
my @lineitems = $cust_bill->cust_bill_pkg;
ok( scalar(@lineitems) == 1, 'one package was billed' );
my $pkg = $lineitems[0]->cust_pkg;
ok( $pkg->status eq 'active', 'package is now active' );
ok( $pkg->bill == str2time('2016-04-01'), 'package bill date set correctly' );

1;