import torrus 1.0.9
[freeside.git] / FS / FS / part_event / Action / fee.pm
1 package FS::part_event::Action::fee;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5
6 sub description { 'Late fee (flat)'; }
7
8 sub event_stage { 'pre-bill'; }
9
10 sub option_fields {
11   ( 
12     'charge'   => { label=>'Amount', type=>'money', }, # size=>7, },
13     'reason'   => 'Reason (invoice line item)',
14     'classnum' => { label=>'Package class' => type=>'select-pkg_class', },
15     'taxclass' => { label=>'Tax class', type=>'select-taxclass', },
16     'setuptax' => { label=>'Late fee is tax exempt',
17                     type=>'checkbox', value=>'Y' },
18     'nextbill' => { label=>'Hold late fee until next invoice',
19                     type=>'checkbox', value=>'Y' },
20   );
21 }
22
23 sub default_weight { 10; }
24
25 sub _calc_fee {
26   #my( $self, $cust_object ) = @_;
27   my $self = shift;
28   $self->option('charge');
29 }
30
31 sub do_action {
32   my( $self, $cust_object ) = @_;
33
34   my $cust_main = $self->cust_main($cust_object);
35
36   my $conf = new FS::Conf;
37
38   my %charge = (
39     'amount'   => $self->_calc_fee($cust_object),
40     'pkg'      => $self->option('reason'),
41     'taxclass' => $self->option('taxclass'),
42     'classnum' => ( $self->option('classnum')
43                       || scalar($conf->config('finance_pkgclass')) ),
44     'setuptax' => $self->option('setuptax'),
45   );
46
47   #unless its more than N months away?
48   $charge{'start_date'} = $cust_main->next_bill_date
49     if $self->option('nextbill');
50
51   my $error = $cust_main->charge( \%charge );
52
53   die $error if $error;
54
55   '';
56 }
57
58 1;