1 package FS::cust_event_fee;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
11 FS::cust_event_fee - Object methods for cust_event_fee records
15 use FS::cust_event_fee;
17 $record = new FS::cust_event_fee \%hash;
18 $record = new FS::cust_event_fee { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::cust_event_fee object links a billing event that charged a fee
31 (an L<FS::cust_event>) to the resulting invoice line item (an
32 L<FS::cust_bill_pkg> object). FS::cust_event_fee inherits from FS::Record.
33 The following fields are currently supported:
37 =item eventfeenum - primary key
39 =item eventnum - key of the cust_event record that required the fee to be
40 created. This is a unique column; there's no reason for a single event
41 instance to create more than one fee.
43 =item billpkgnum - key of the cust_bill_pkg record representing the fee
44 on an invoice. This is also a unique column but can be NULL to indicate
45 a fee that hasn't been billed yet. In that case it will be billed the next
46 time billing runs for the customer.
48 =item feepart - key of the fee definition (L<FS::part_fee>).
50 =item nextbill - 'Y' if the fee should be charged on the customer's next
51 bill, rather than causing a bill to be produced immediately.
61 Creates a new event-fee link. To add the record to the database,
66 sub table { 'cust_event_fee'; }
70 Adds this record to the database. If there is an error, returns the error,
71 otherwise returns false.
75 Delete this record from the database.
77 =item replace OLD_RECORD
79 Replaces the OLD_RECORD with this one in the database. If there is an error,
80 returns the error, otherwise returns false.
84 Checks all fields to make sure this is a valid example. If there is
85 an error, returns the error, otherwise returns false. Called by the insert
90 # the check method should currently be supplied - FS::Record contains some
91 # data checking routines
97 $self->ut_numbern('eventfeenum')
98 || $self->ut_foreign_key('eventnum', 'cust_event', 'eventnum')
99 || $self->ut_foreign_keyn('billpkgnum', 'cust_bill_pkg', 'billpkgnum')
100 || $self->ut_foreign_key('feepart', 'part_fee', 'feepart')
101 || $self->ut_flag('nextbill')
103 return $error if $error;
114 =item by_cust CUSTNUM[, PARAMS]
116 Finds all cust_event_fee records belonging to the customer CUSTNUM. Currently
117 fee events can be cust_main, cust_pkg, or cust_bill events; this will return
120 PARAMS can be additional params to pass to qsearch; this really only works
121 for 'hashref' and 'order_by'.
127 my $custnum = shift or return;
129 $custnum =~ /^\d+$/ or die "bad custnum $custnum";
132 my $where = ($params{hashref} && keys (%{ $params{hashref} }))
136 table => 'cust_event_fee',
137 addl_from => 'JOIN cust_event USING (eventnum) ' .
138 'JOIN part_event USING (eventpart) ',
139 extra_sql => "$where eventtable = 'cust_main' ".
140 "AND cust_event.tablenum = $custnum",
144 table => 'cust_event_fee',
145 addl_from => 'JOIN cust_event USING (eventnum) ' .
146 'JOIN part_event USING (eventpart) ' .
147 'JOIN cust_bill ON (cust_event.tablenum = cust_bill.invnum)',
148 extra_sql => "$where eventtable = 'cust_bill' ".
149 "AND cust_bill.custnum = $custnum",
153 table => 'cust_event_fee',
154 addl_from => 'JOIN cust_event USING (eventnum) ' .
155 'JOIN part_event USING (eventpart) ' .
156 'JOIN cust_pay_batch ON (cust_event.tablenum = cust_pay_batch.paybatchnum)',
157 extra_sql => "$where eventtable = 'cust_pay_batch' ".
158 "AND cust_pay_batch.custnum = $custnum",
162 table => 'cust_event_fee',
163 addl_from => 'JOIN cust_event USING (eventnum) ' .
164 'JOIN part_event USING (eventpart) ' .
165 'JOIN cust_pkg ON (cust_event.tablenum = cust_pkg.pkgnum)',
166 extra_sql => "$where eventtable = 'cust_pkg' ".
167 "AND cust_pkg.custnum = $custnum",
176 FS::cust_event->by_key($self->eventnum);
181 FS::part_fee->by_key($self->feepart);
188 L<FS::cust_event>, L<FS::part_fee>, L<FS::Record>