add pre-bill event stage for late fees, RT#5589
[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 event_stage { 'pre-bill'; }
13
14 sub option_fields {
15   ( 
16     'percent'  => { label=>'Percent', size=>2, },
17     'reason'   => 'Reason',
18     'taxclass' => { label=>'Tax class', type=>'select-taxclass', },
19     'nextbill' => { label=>'Hold late fee until next invoice', type=>'checkbox', value=>'Y' },
20   );
21 }
22
23 sub default_weight { 10; }
24
25 sub do_action {
26   my( $self, $cust_bill ) = @_;
27
28   #my $cust_main = $self->cust_main($cust_bill);
29   my $cust_main = $cust_bill->cust_main;
30
31   my $amount =
32     sprintf('%.2f', $cust_bill->owed * $self->option('percent') / 100 );
33
34   my %charge = (
35     'amount'     => $amount,
36     'pkg'        => $self->option('reason'),
37     'taxclass'   => $self->option('taxclass'),
38   );
39
40   $charge{'start_date'} = $cust_main->next_bill_date #unless its more than N months away?
41     if $self->option('nextbill');
42
43   my $error = $cust_main->charge( \%charge );
44
45   die $error if $error;
46
47   '';
48 }
49
50 1;