fix late fees, RT#5665
[freeside.git] / FS / FS / part_event / Action / cust_bill_fee_percent.pm
1 package FS::part_event::Action::cust_bill_fee_percent;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5
6 sub description { 'Late fee (percentage of invoice)'; }
7
8 sub eventtable_hashref {
9   { 'cust_bill' => 1 };
10 }
11
12 sub option_fields {
13   ( 
14     'percent'  => { label=>'Percent', size=>2, },
15     'reason'   => 'Reason',
16     'taxclass' => { label=>'Tax class', type=>'select-taxclass', },
17     'nextbill' => { label=>'Hold late fee until next invoice', type=>'checkbox', value=>'Y' },
18   );
19 }
20
21 sub default_weight { 10; }
22
23 sub do_action {
24   my( $self, $cust_bill ) = @_;
25
26   #my $cust_main = $self->cust_main($cust_bill);
27   my $cust_main = $cust_bill->cust_main;
28
29   my $amount =
30     sprintf('%.2f', $cust_bill->owed * $self->option('percent') / 100 );
31
32   my %charge = (
33     'amount'     => $amount,
34     'pkg'        => $self->option('reason'),
35     'taxclass'   => $self->option('taxclass'),
36   );
37
38   $charge{'start_date'} = $cust_main->next_bill_date #unless its more than N months away?
39     if $self->option('nextbill');
40
41   my $error = $cust_main->charge( \%charge );
42
43   die $error if $error;
44
45   '';
46 }
47
48 1;