1 package FS::part_bill_event;
5 use FS::Record qw( qsearch qsearchs );
12 FS::part_bill_event - Object methods for part_bill_event records
16 use FS::part_bill_event;
18 $record = new FS::part_bill_event \%hash;
19 $record = new FS::part_bill_event { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::part_bill_event object represents an invoice event definition -
32 a callback which is triggered when an invoice is a certain amount of time
33 overdue. FS::part_bill_event inherits from
34 FS::Record. The following fields are currently supported:
38 =item eventpart - primary key
40 =item payby - CARD, DCRD, CHEK, DCHK, LECB, BILL, or COMP
42 =item event - event name
44 =item eventcode - event action
46 =item seconds - how long after the invoice date events of this type are triggered
48 =item weight - ordering for events with identical seconds
50 =item plan - eventcode plan
52 =item plandata - additional plan data
54 =item disabled - Disabled flag, empty or `Y'
64 Creates a new invoice event definition. To add the invoice event definition to
65 the database, see L<"insert">.
67 Note that this stores the hash reference, not a distinct copy of the hash it
68 points to. You can ask the object for a copy with the I<hash> method.
72 # the new method can be inherited from FS::Record, if a table method is defined
74 sub table { 'part_bill_event'; }
78 Adds this record to the database. If there is an error, returns the error,
79 otherwise returns false.
83 # the insert method can be inherited from FS::Record
87 Delete this record from the database.
91 # the delete method can be inherited from FS::Record
93 =item replace OLD_RECORD
95 Replaces the OLD_RECORD with this one in the database. If there is an error,
96 returns the error, otherwise returns false.
100 # the replace method can be inherited from FS::Record
104 Checks all fields to make sure this is a valid invoice event definition. If
105 there is an error, returns the error, otherwise returns false. Called by the
106 insert and replace methods.
110 # the check method should currently be supplied - FS::Record contains some
111 # data checking routines
116 $self->weight(0) unless $self->weight;
118 my $conf = new FS::Conf;
119 if ( $conf->exists('safe-part_bill_event') ) {
120 my $error = $self->ut_anything('eventcode');
121 return $error if $error;
123 my $c = $self->eventcode;
125 $c =~ /^\s*\$cust_main\->(suspend|cancel|invoicing_list_addpost|bill|collect)\(\);\s*("";)?\s*$/
127 or $c =~ /^\s*\$cust_bill\->(comp|realtime_(card|ach|lec)|batch_card|send)\(\);\s*$/
129 or $c =~ /^\s*\$cust_bill\->send(_if_newest)?\(\'[\w\-\s]+\'\s*(,\s*(\d+|\[\s*\d+(,\s*\d+)*\s*\])\s*,\s*'[\w\@\.\-\+]*'\s*)?\);\s*$/
131 or $c =~ /^\s*\$cust_main\->apply_payments; \$cust_main->apply_credits; "";\s*$/
133 or $c =~ /^\s*\$cust_main\->charge\( \s*\d*\.?\d*\s*,\s*\'[\w \!\@\#\$\%\&\(\)\-\+\;\:\"\,\.\?\/]*\'\s*\);\s*$/
135 or $c =~ /^\s*\$cust_main\->suspend_(if|unless)_pkgpart\([\d\,\s]*\);\s*$/
137 or $c =~ /^\s*\$cust_bill\->cust_suspend_if_balance_over\([\d\.\s]*\);\s*$/
141 return "illegal eventcode: $c";
146 my $error = $self->ut_numbern('eventpart')
147 || $self->ut_enum('payby', [qw( CARD DCRD CHEK DCHK LECB BILL COMP )] )
148 || $self->ut_text('event')
149 || $self->ut_anything('eventcode')
150 || $self->ut_number('seconds')
151 || $self->ut_enum('disabled', [ '', 'Y' ] )
152 || $self->ut_number('weight')
153 || $self->ut_textn('plan')
154 || $self->ut_anything('plandata')
156 #|| $self->ut_snumber('seconds')
157 return $error if $error;
160 if ( $self->plandata =~ /^(agent_)?templatename\s+(.*)$/m ) {
163 foreach my $file (qw( template
164 latex latexnotes latexreturnaddress latexfooter
166 html htmlnotes htmlreturnaddress htmlfooter
169 unless ( $conf->exists("invoice_${file}_$name") ) {
171 "invoice_${file}_$name" =>
172 join("\n", $conf->config("invoice_$file") )
183 Returns the alternate invoice template name, if any, or false if there is
184 no alternate template for this invoice event.
190 if ( $self->plan =~ /^send_(alternate|agent)$/
191 && $self->plandata =~ /^(agent_)?templatename (.*)$/m
205 The whole "eventcode" idea is bunk. This should be refactored with subclasses
206 like part_pkg/ and part_export/
210 L<FS::cust_bill>, L<FS::cust_bill_event>, L<FS::Record>, schema.html from the