1 package FS::FeeOrigin_Mixin;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
9 # is there a nicer idiom for this?
10 our @subclasses = qw( FS::cust_event_fee FS::cust_pkg_reason_fee );
11 use FS::cust_event_fee;
12 use FS::cust_pkg_reason_fee;
16 FS::FeeOrigin_Mixin - Common interface for fee origin records
20 use FS::cust_event_fee;
22 $record = new FS::cust_event_fee \%hash;
23 $record = new FS::cust_event_fee { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::FeeOrigin_Mixin object associates the timestamped event that triggered
36 a fee (which may be a billing event, or something else like a package
37 suspension) to the resulting invoice line item (L<FS::cust_bill_pkg> object).
38 The following fields are required:
42 =item billpkgnum - key of the cust_bill_pkg record representing the fee
43 on an invoice. This is a unique column but can be NULL to indicate a fee that
44 hasn't been billed yet. In that case it will be billed the next time billing
45 runs for the customer.
47 =item feepart - key of the fee definition (L<FS::part_fee>).
49 =item nextbill - 'Y' if the fee should be charged on the customer's next bill,
50 rather than causing a bill to be produced immediately.
58 =item by_cust CUSTNUM[, PARAMS]
60 Finds all cust_event_fee records belonging to the customer CUSTNUM.
62 PARAMS can be additional params to pass to qsearch; this really only works
63 for 'hashref' and 'order_by'.
67 # invoke for all subclasses, and return the results as a flat list
72 return map { $_->_by_cust(@args) } @subclasses;
81 =item _by_cust CUSTNUM[, PARAMS]
83 The L</by_cust> search method. Each subclass must implement this.
87 If the fee origin generates a fee based on past invoices (for example, an
88 invoice event that charges late fees), this method should return the
89 L<FS::cust_bill> object that will be the basis for the fee. If this returns
90 nothing, then then fee will be based on the rest of the invoice where it
95 If the fee origin generates a fee limited in scope to one package (for
96 example, a package reconnection fee event), this method should return the
97 L<FS::cust_pkg> object the fee applies to. If it's a percentage fee, this
98 determines which charges it's a percentage of; otherwise it just affects the
99 fee description appearing on the invoice.
101 Currently not tested in combination with L</cust_bill>; be careful.
107 sub _by_cust { my $class = shift; die "'$class' must provide _by_cust method" }
113 # stubs; remove in 4.x
117 FS::part_fee->by_key($self->feepart);
122 $self->billpkgnum ? FS::cust_bill_pkg->by_key($self->billpkgnum) : '';
129 L<FS::cust_event_fee>, L<FS::cust_pkg_reason_fee>, L<FS::cust_bill_pkg>,