1 package FS::part_event::Action::fee;
4 use base qw( FS::part_event::Action );
6 sub description { 'Late fee (flat)'; }
8 sub event_stage { 'pre-bill'; }
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' },
21 { label=>"Charge no more than the customer's credit balance",
22 type=>'checkbox', value=>'Y' },
26 sub default_weight { 10; }
29 my( $self, $cust_object ) = @_;
30 if ( $self->option('limit_to_credit') ) {
31 my $balance = $cust_object->cust_main->balance;
32 if ( $balance >= 0 ) {
34 } elsif ( (-1 * $balance) < $self->option('charge') ) {
35 my $total = -1 * $balance;
36 # if it's tax exempt, then we're done
37 # XXX we also bail out if you're using external tax tables, because
38 # they're definitely NOT linear and we haven't yet had a reason to
39 # make that case work.
40 return $total if $self->option('setuptax') eq 'Y'
41 or FS::Conf->new->exists('enable_taxproducts');
44 # false laziness with xmlhttp-calculate_taxes, cust_main::Billing, etc.
45 # XXX not accurate with monthly exemptions
46 my $cust_main = $cust_object->cust_main;
48 my $charge = FS::cust_bill_pkg->new({
53 my $part_pkg = FS::part_pkg->new({
54 taxclass => $self->option('taxclass')
56 my $error = $cust_main->_handle_taxes(
57 FS::part_pkg->new({ taxclass => ($self->option('taxclass') || '') }),
60 FS::cust_pkg->new({custnum => $cust_main->custnum}),
63 warn "error estimating taxes for breakage charge: custnum ".$cust_main->custnum."\n";
66 # $taxlisthash: tax identifier => [ cust_main_county, cust_bill_pkg... ]
68 my @taxes = map { $_->[0] } values %$taxlisthash;
70 $total_rate += $_->tax;
72 return $total if $total_rate == 0; # no taxes apply
74 my $total_cents = $total * 100;
75 my $charge_cents = sprintf('%.0f', $total_cents * 100/(100 + $total_rate));
76 return ($charge_cents / 100);
80 $self->option('charge');
84 my( $self, $cust_object ) = @_;
86 my $cust_main = $self->cust_main($cust_object);
88 my $conf = new FS::Conf;
91 'amount' => $self->_calc_fee($cust_object),
92 'pkg' => $self->option('reason'),
93 'taxclass' => $self->option('taxclass'),
94 'classnum' => ( $self->option('classnum')
95 || scalar($conf->config('finance_pkgclass')) ),
96 'setuptax' => $self->option('setuptax'),
99 # amazingly, FS::cust_main::charge will allow a charge of zero
100 return '' if $charge{'amount'} == 0;
102 #unless its more than N months away?
103 $charge{'start_date'} = $cust_main->next_bill_date
104 if $self->option('nextbill');
106 my $error = $cust_main->charge( \%charge );
108 die $error if $error;