1 package FS::cust_event_fee;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
9 FS::cust_event_fee - Object methods for cust_event_fee records
13 use FS::cust_event_fee;
15 $record = new FS::cust_event_fee \%hash;
16 $record = new FS::cust_event_fee { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::cust_event_fee object links a billing event that charged a fee
29 (an L<FS::cust_event>) to the resulting invoice line item (an
30 L<FS::cust_bill_pkg> object). FS::cust_event_fee inherits from FS::Record.
31 The following fields are currently supported:
35 =item eventfeenum - primary key
37 =item eventnum - key of the cust_event record that required the fee to be
38 created. This is a unique column; there's no reason for a single event
39 instance to create more than one fee.
41 =item billpkgnum - key of the cust_bill_pkg record representing the fee
42 on an invoice. This is also a unique column but can be NULL to indicate
43 a fee that hasn't been billed yet. In that case it will be billed the next
44 time billing runs for the customer.
46 =item feepart - key of the fee definition (L<FS::part_fee>).
48 =item nextbill - 'Y' if the fee should be charged on the customer's next
49 bill, rather than causing a bill to be produced immediately.
59 Creates a new event-fee link. To add the record to the database,
64 sub table { 'cust_event_fee'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
73 Delete this record from the database.
75 =item replace OLD_RECORD
77 Replaces the OLD_RECORD with this one in the database. If there is an error,
78 returns the error, otherwise returns false.
82 Checks all fields to make sure this is a valid example. If there is
83 an error, returns the error, otherwise returns false. Called by the insert
88 # the check method should currently be supplied - FS::Record contains some
89 # data checking routines
95 $self->ut_numbern('eventfeenum')
96 || $self->ut_foreign_key('eventnum', 'cust_event', 'eventnum')
97 || $self->ut_foreign_keyn('billpkgnum', 'cust_bill_pkg', 'billpkgnum')
98 || $self->ut_foreign_key('feepart', 'part_fee', 'feepart')
99 || $self->ut_flag('nextbill')
101 return $error if $error;
112 =item by_cust CUSTNUM[, PARAMS]
114 Finds all cust_event_fee records belonging to the customer CUSTNUM. Currently
115 fee events can be cust_main or cust_bill events; this will return both.
117 PARAMS can be additional params to pass to qsearch; this really only works
118 for 'hashref' and 'order_by'.
124 my $custnum = shift or return;
126 $custnum =~ /^\d+$/ or die "bad custnum $custnum";
129 my $where = ($params{hashref} && keys (%{ $params{hashref} }))
133 table => 'cust_event_fee',
134 addl_from => 'JOIN cust_event USING (eventnum) ' .
135 'JOIN part_event USING (eventpart) ',
136 extra_sql => "$where eventtable = 'cust_main' ".
137 "AND cust_event.tablenum = $custnum",
141 table => 'cust_event_fee',
142 addl_from => 'JOIN cust_event USING (eventnum) ' .
143 'JOIN part_event USING (eventpart) ' .
144 'JOIN cust_bill ON (cust_event.tablenum = cust_bill.invnum)',
145 extra_sql => "$where eventtable = 'cust_bill' ".
146 "AND cust_bill.custnum = $custnum",
157 L<FS::cust_event>, L<FS::part_fee>, L<FS::Record>