leading summary page invoices #RT5086
[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',
20                     type=>'checkbox', value=>'Y' },
21     'setuptax' => { label=>'Late fee is tax exempt',
22                     type=>'checkbox', value=>'Y' },
23   );
24 }
25
26 sub default_weight { 10; }
27
28 sub do_action {
29   my( $self, $cust_bill ) = @_;
30
31   #my $cust_main = $self->cust_main($cust_bill);
32   my $cust_main = $cust_bill->cust_main;
33
34   my $conf = new FS::Conf;
35
36   my $amount =
37     sprintf('%.2f', $cust_bill->owed * $self->option('percent') / 100 );
38
39   my %charge = (
40     'amount'   => $amount,
41     'pkg'      => $self->option('reason'),
42     'taxclass' => $self->option('taxclass'),
43     'classnum'   => $conf->config('finance_pkgclass'),
44     'setuptax' => $self->option('setuptax'),
45   );
46
47   $charge{'start_date'} = $cust_main->next_bill_date #unless its more than N months away?
48     if $self->option('nextbill');
49
50   my $error = $cust_main->charge( \%charge );
51
52   die $error if $error;
53
54   '';
55 }
56
57 1;