1 package FS::cust_event_fee;
4 use base qw( FS::Record FS::FeeOrigin_Mixin );
5 use FS::Record qw( qsearch qsearchs );
10 FS::cust_event_fee - Object methods for cust_event_fee records
14 use FS::cust_event_fee;
16 $record = new FS::cust_event_fee \%hash;
17 $record = new FS::cust_event_fee { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::cust_event_fee object links a billing event that charged a fee
30 (an L<FS::cust_event>) to the resulting invoice line item (an
31 L<FS::cust_bill_pkg> object). FS::cust_event_fee inherits from FS::Record
32 and FS::FeeOrigin_Mixin. The following fields are currently supported:
36 =item eventfeenum - primary key
38 =item eventnum - key of the cust_event record that required the fee to be
39 created. This is a unique column; there's no reason for a single event
40 instance to create more than one fee.
42 =item billpkgnum - key of the cust_bill_pkg record representing the fee
43 on an invoice. This is also a unique column but can be NULL to indicate
44 a fee that hasn't been billed yet. In that case it will be billed the next
45 time billing 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
50 bill, rather than causing a bill to be produced immediately.
60 Creates a new event-fee link. To add the record to the database,
65 sub table { 'cust_event_fee'; }
69 Adds this record to the database. If there is an error, returns the error,
70 otherwise returns false.
74 Delete this record from the database.
76 =item replace OLD_RECORD
78 Replaces the OLD_RECORD with this one in the database. If there is an error,
79 returns the error, otherwise returns false.
83 Checks all fields to make sure this is a valid example. If there is
84 an error, returns the error, otherwise returns false. Called by the insert
93 $self->ut_numbern('eventfeenum')
94 || $self->ut_foreign_key('eventnum', 'cust_event', 'eventnum')
95 || $self->ut_foreign_keyn('billpkgnum', 'cust_bill_pkg', 'billpkgnum')
96 || $self->ut_foreign_key('feepart', 'part_fee', 'feepart')
97 || $self->ut_flag('nextbill')
99 return $error if $error;
110 =item _by_cust CUSTNUM[, PARAMS]
112 See L<FS::FeeOrigin_Mixin/by_cust>. This is the implementation for
113 event-triggered fees.
119 my $custnum = shift or return;
121 $custnum =~ /^\d+$/ or die "bad custnum $custnum";
124 my $where = ($params{hashref} && keys (%{ $params{hashref} }))
128 table => 'cust_event_fee',
129 addl_from => 'JOIN cust_event USING (eventnum) ' .
130 'JOIN part_event USING (eventpart) ',
131 extra_sql => "$where eventtable = 'cust_main' ".
132 "AND cust_event.tablenum = $custnum",
136 table => 'cust_event_fee',
137 addl_from => 'JOIN cust_event USING (eventnum) ' .
138 'JOIN part_event USING (eventpart) ' .
139 'JOIN cust_bill ON (cust_event.tablenum = cust_bill.invnum)',
140 extra_sql => "$where eventtable = 'cust_bill' ".
141 "AND cust_bill.custnum = $custnum",
145 table => 'cust_event_fee',
146 addl_from => 'JOIN cust_event USING (eventnum) ' .
147 'JOIN part_event USING (eventpart) ' .
148 'JOIN cust_pay_batch ON (cust_event.tablenum = cust_pay_batch.paybatchnum)',
149 extra_sql => "$where eventtable = 'cust_pay_batch' ".
150 "AND cust_pay_batch.custnum = $custnum",
154 table => 'cust_event_fee',
155 addl_from => 'JOIN cust_event USING (eventnum) ' .
156 'JOIN part_event USING (eventpart) ' .
157 'JOIN cust_pkg ON (cust_event.tablenum = cust_pkg.pkgnum)',
158 extra_sql => "$where eventtable = 'cust_pkg' ".
159 "AND cust_pkg.custnum = $custnum",
166 See L<FS::FeeOrigin_Mixin/cust_bill>. This version simply returns the event
167 object if the event is an invoice event.
173 my $object = $self->cust_event->cust_X;
174 if ( $object->isa('FS::cust_bill') ) {
183 See L<FS::FeeOrigin_Mixin/cust_bill>. This version simply returns the event
184 object if the event is a package event.
190 my $object = $self->cust_event->cust_X;
191 if ( $object->isa('FS::cust_pkg') ) {
198 # stubs - remove in 4.x
202 FS::cust_event->by_key($self->eventnum);
209 L<FS::cust_event>, L<FS::FeeOrigin_Mixin>, L<FS::Record>