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, cust_pkg, or cust_bill events; this will return
118 PARAMS can be additional params to pass to qsearch; this really only works
119 for 'hashref' and 'order_by'.
125 my $custnum = shift or return;
127 $custnum =~ /^\d+$/ or die "bad custnum $custnum";
130 my $where = ($params{hashref} && keys (%{ $params{hashref} }))
134 table => 'cust_event_fee',
135 addl_from => 'JOIN cust_event USING (eventnum) ' .
136 'JOIN part_event USING (eventpart) ',
137 extra_sql => "$where eventtable = 'cust_main' ".
138 "AND cust_event.tablenum = $custnum",
142 table => 'cust_event_fee',
143 addl_from => 'JOIN cust_event USING (eventnum) ' .
144 'JOIN part_event USING (eventpart) ' .
145 'JOIN cust_bill ON (cust_event.tablenum = cust_bill.invnum)',
146 extra_sql => "$where eventtable = 'cust_bill' ".
147 "AND cust_bill.custnum = $custnum",
151 table => 'cust_event_fee',
152 addl_from => 'JOIN cust_event USING (eventnum) ' .
153 'JOIN part_event USING (eventpart) ' .
154 'JOIN cust_pay_batch ON (cust_event.tablenum = cust_pay_batch.paybatchnum)',
155 extra_sql => "$where eventtable = 'cust_pay_batch' ".
156 "AND cust_pay_batch.custnum = $custnum",
160 table => 'cust_event_fee',
161 addl_from => 'JOIN cust_event USING (eventnum) ' .
162 'JOIN part_event USING (eventpart) ' .
163 'JOIN cust_pkg ON (cust_event.tablenum = cust_pkg.pkgnum)',
164 extra_sql => "$where eventtable = 'cust_pkg' ".
165 "AND cust_pkg.custnum = $custnum",
176 L<FS::cust_event>, L<FS::part_fee>, L<FS::Record>