1 <% include( 'elements/browse.html',
2 'title' => 'Billing Event Definitions',
3 'html_init' => $html_init,
4 'name' => 'billing event definitions',
6 'disabled_statuspos' => 2,
8 'agent_null_right' => 'Edit global billing events',
10 'query' => { 'select' => 'part_event.*',
11 'table' => 'part_event',
12 'addl_from' => $join_conditions,
13 'hashref' => $hashref,
14 'order_by' => $order_conditions,
16 'count_query' => $count_query,
24 'fields' => [ 'eventpart',
43 my $link = [ $p.'edit/part_event.html?', 'eventpart' ];
46 my $part_event = shift;
47 my $onclick = include('/elements/popup_link_onclick.html',
48 action => $p.'view/part_event-targets.html?eventpart='.
49 $part_event->eventpart,
50 actionlabel => 'Event query', #no, XSS - '.$part_event->event,
53 close_text => 'Close',
58 'data' => encode_entities($part_event->event),
59 'link' => $p.'edit/part_event.html?'.$part_event->eventpart,
65 'onclick' => $onclick,
71 my $eventtable_labels = FS::part_event->eventtable_labels;
72 my $eventtable_sub = sub { $eventtable_labels->{ shift->eventtable }; };
74 my $check_freq_labels = FS::part_event->check_freq_labels;
75 my $check_freq_sub = sub { $check_freq_labels->{ shift->check_freq }; };
77 my $conditions_sub = sub {
78 my $part_event = shift;
84 my $part_event_condition = $_;
85 my %options = $part_event_condition->options;
87 my $desc = $part_event_condition->description;
89 if ( $cgi->param('test_eventtable_num') =~ /^(\d+)$/ ) {
93 if ( $cgi->param('eventtable') =~ /^(cust_main|cust_pkg|cust_bill)$/ ) {
94 my $eventtable = "FS::$1";
95 my $object = $eventtable->by_key($tablenum);
97 my $cust_event = $part_event->new_cust_event($object);
99 my $test = $part_event_condition->condition(
101 'cust_event' => $cust_event,
104 my $yesno = $test ? '(<FONT COLOR="#00ff00">yes</FONT>)'
105 : '(<FONT COLOR="#ff0000">no</FONT>)';
117 'style' => ( $addl++ ? 'border-top: 1px solid gray' : '' ),
123 my $data = $options{$_};
125 $data = join('<BR>', keys %$data); #XXX display hash values too?
130 'data' => $part_event_condition->option_label($_). ':',
145 $part_event->part_event_condition
151 my $action_sub = sub {
152 my $part_event = shift;
154 my %options = $part_event->options;
160 'data' => $part_event->description,
170 'data' => $part_event->option_label($_). ':',
175 'data' => $options{$_},
191 unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
192 || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');
196 #XXX better description
197 'Events are billing, collection or other actions triggered when certain '.
198 'customer, invoice, package or other conditions are met.<BR><BR>'.
199 qq!<FORM METHOD="POST" ACTION="${p}edit/part_event.html">!.
200 qq!<A HREF="${p}edit/part_event.html"><I>Add a new event</I></A>!.
201 ' or <SELECT NAME="clone"><OPTION></OPTION>';
203 foreach my $part_event ( qsearch('part_event', {'disabled'=>''}) ) {
204 $html_init .= '<OPTION VALUE="'. $part_event->eventpart. '">'.
205 $part_event->eventpart. ': '.
206 encode_entities($part_event->event).
210 $html_init .= '</SELECT><INPUT TYPE="submit" VALUE="Clone existing event">'.
215 my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '.
216 $FS::CurrentUser::CurrentUser->agentnums_sql(
217 'null_right' => 'Edit global billing events',
218 'viewall_right' => 'None',
221 if ( $cgi->param('eventtable') =~ /^(\w+)$/ ) {
222 $hashref->{eventtable} = $1;
223 $count_query .= " AND eventtable = '$1' ";
227 if ( $cgi->param('test_eventtable_num') =~ /^(\d+)$/ ) {
231 my $join_conditions = FS::part_event_condition->join_conditions_sql('', 'time' => time);
232 my $order_conditions = FS::part_event_condition->order_conditions_sql;