1 package FS::part_event::Action::fee;
3 # DEPRECATED; will most likely be removed in 4.x
6 use base qw( FS::part_event::Action );
8 sub description { 'Late fee (flat)'; }
10 sub event_stage { 'pre-bill'; }
14 'charge' => { label=>'Amount', type=>'money', }, # size=>7, },
15 'reason' => 'Reason (invoice line item)',
16 'classnum' => { label=>'Package class' => type=>'select-pkg_class', },
17 'taxclass' => { label=>'Tax class', type=>'select-taxclass', },
18 'setuptax' => { label=>'Late fee is tax exempt',
19 type=>'checkbox', value=>'Y' },
20 'nextbill' => { label=>'Hold late fee until next invoice',
21 type=>'checkbox', value=>'Y' },
23 { label=>"Charge no more than the customer's credit balance",
24 type=>'checkbox', value=>'Y' },
28 sub default_weight { 10; }
31 my( $self, $cust_object ) = @_;
32 if ( $self->option('limit_to_credit') ) {
33 my $balance = $cust_object->cust_main->balance;
34 if ( $balance >= 0 ) {
36 } elsif ( (-1 * $balance) < $self->option('charge') ) {
37 my $total = -1 * $balance;
38 # if it's tax exempt, then we're done
39 # XXX we also bail out if you're using external tax tables, because
40 # they're definitely NOT linear and we haven't yet had a reason to
41 # make that case work.
42 return $total if $self->option('setuptax') eq 'Y'
43 or FS::Conf->new->config('tax_data_vendor');
46 # false laziness with xmlhttp-calculate_taxes, cust_main::Billing, etc.
47 # XXX not accurate with monthly exemptions
48 my $cust_main = $cust_object->cust_main;
50 my $charge = FS::cust_bill_pkg->new({
55 my $part_pkg = FS::part_pkg->new({
56 taxclass => $self->option('taxclass')
58 my $error = $cust_main->_handle_taxes( $taxlisthash, $charge,
59 location => $cust_main->ship_location,
60 part_item => $part_pkg,
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;