1 package FS::part_event::Action;
4 use base qw( FS::part_event );
9 FS::part_event::Action - Base class for event actions
13 package FS::part_event::Action::myaction;
15 use base FS::part_event::Action;
19 FS::part_event::Action is a base class for event action classes.
23 These methods are implemented in each action class.
29 Action classes must define a description method. This method should return a
30 scalar description of the action.
32 =item eventtable_hashref
34 Action classes must define a eventtable_hashref method if they can only be
35 triggered against some kinds of tables. This method should return a hash
36 reference of eventtables (values set true indicate the action can be performed):
38 sub eventtable_hashref {
42 'cust_pay_batch' => 0,
49 sub eventtable_hashref {
53 'cust_pay_batch' => 1,
60 Action classes may define an event_stage method to indicate a preference
61 for being run at a non-standard stage of the billing and collection process.
63 This method may currently return "collect" (the default) or "pre-bill".
73 Action classes may define an option_fields method to indicate that they
74 accept one or more options.
76 This method should return a list of option names and option descriptions.
77 Each option description can be a scalar description, for simple options, or a
78 hashref with the following values:
82 =item label - Description
84 =item type - Currently text, money, checkbox, checkbox-multiple, select, select-agent, select-pkg_class, select-part_referral, select-table, fixed, hidden, (others can be implemented as httemplate/elements/tr-TYPE.html mason components). Defaults to text.
86 =item size - Size for text fields
88 =item validation - (optional) Validate optionvalue using the given object method, such as ut_textn, ut_email
90 =item options - For checkbox-multiple and select, a list reference of available option values.
92 =item option_labels - For select, a hash reference of availble option values and labels.
94 =item value - for checkbox, fixed, hidden
96 =item table - for select-table
98 =item name_col - for select-table
100 =item NOTE: See httemplate/elements/select-table.html for a full list of the optinal options for the select-table type
104 NOTE: A database connection is B<not> yet available when this subroutine is
111 'field' => 'description',
113 'another_field' => { 'label'=>'Amount', 'type'=>'money', },
115 'third_field' => { 'label' => 'Types',
117 'options' => [ 'h', 's' ],
118 'option_labels' => { 'h' => 'Happy',
133 Action classes may define a default weighting. Weights control execution order
134 relative to other actions (that are triggered at the same time).
145 Action classes may define a deprecated method that returns true, indicating
146 that this action is deprecated.
155 =item will_send_invoice
157 Action classes may define a will_send_invoice method that returns true, indicating
158 that this action is sending out an invoice.
163 sub will_send_invoice {
167 =item do_action CUSTOMER_EVENT_OBJECT
169 Action classes must define an action method. This method is triggered if
170 all conditions have been met.
172 The object which triggered the event (an FS::cust_main, FS::cust_bill or
173 FS::cust_pkg object) is passed as an argument.
175 To retreive option values, call the option method on the desired option, i.e.:
177 my( $self, $cust_object ) = @_;
178 $value_of_field = $self->option('field');
180 To indicate sucessful completion, simply return. Optionally, you can return a
181 string of information status information about the sucessful completion, or
182 simply return the empty string.
184 To indicate a failure and that this event should retry, die with the desired
191 These methods are defined in the base class for use in action classes.
195 =item cust_main CUST_OBJECT
197 Return the customer object (see L<FS::cust_main>) associated with the provided
198 object (the object itself if it is already a customer object).
203 my( $self, $cust_object ) = @_;
205 $cust_object->isa('FS::cust_main') ? $cust_object : $cust_object->cust_main;
209 =item cust_pkg OBJECT
211 Return the package object (L<FS::cust_pkg>) associated with the provided
212 object. The object must be either a service (L<FS::svc_Common>) or a
218 my( $self, $object ) = @_;
219 $object->isa('FS::cust_pkg') ? $object :
220 $object->isa('FS::svc_Common') ? $object->cust_svc->cust_pkg :
224 =item option_label OPTIONNAME
226 Returns the label for the specified option name.
231 my( $self, $optionname ) = @_;
233 my %option_fields = $self->option_fields;
235 ref( $option_fields{$optionname} )
236 ? $option_fields{$optionname}->{'label'}
237 : $option_fields{$optionname}
241 =item option_fields_hashref
243 Returns the option fields as an (ordered) hash reference.
247 sub option_fields_hashref {
249 tie my %hash, 'Tie::IxHash', $self->option_fields;
253 =item option_fields_listref
255 Returns just the option field names as a list reference.
259 sub option_fields_listref {
261 my $hashref = $self->option_fields_hashref;