This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / httemplate / browse / part_event.html
1 <% include( 'elements/browse.html',
2                 'title'              => 'Billing Event Definitions',
3                 'html_init'          => $html_init,
4                 'name'               => 'billing event definitions',
5                 'disableable'        => 1,
6                 'disabled_statuspos' => 2,
7                 'agent_virt'         => 1,
8                 'agent_null_right'   => 'Edit global billing events',
9                 'agent_pos'          => 3,
10                 'query'              => { 'select'    => 'part_event.*',
11                                           'table'     => 'part_event',
12                                           'addl_from' => $join_conditions,
13                                           'hashref'   => {},
14                                           'order_by'  => $order_conditions,
15                                         },
16                 'count_query'        => $count_query,
17                 'header'             => [ '#',
18                                           'Event',
19                                           'Type',
20                                           'Check freq.',
21                                           'Conditions',
22                                           'Action',
23                                         ],
24                 'fields'             => [ 'eventpart',
25                                           'event',
26                                           $eventtable_sub,
27                                           $check_freq_sub,
28                                           $conditions_sub,
29                                           $action_sub,
30                                         ],
31                 'links'              => [ $link,
32                                           $link,
33                                           '',
34                                           '',
35                                           '',
36                                           '',
37                                         ],
38                 'align'              => 'rllccc',
39           )
40 %>
41 <%once>
42
43 my $eventtable_labels = FS::part_event->eventtable_labels;
44 my $eventtable_sub = sub { $eventtable_labels->{ shift->eventtable }; };
45
46 my $check_freq_labels = FS::part_event->check_freq_labels;
47 my $check_freq_sub = sub { $check_freq_labels->{ shift->check_freq }; };
48
49 my $conditions_sub = sub {
50   my $part_event = shift;
51   my $addl = 0;
52
53   [
54     map {
55            my $part_event_condition = $_;
56            my %options = $part_event_condition->options;
57
58            [
59              {
60                'data'       => $part_event_condition->description,
61                'width'      => '100%',
62                'align'      => 'center',
63                'colspan'    => 2,
64                'style'      => ( $addl++ ? 'border-top: 1px solid gray' : '' ), 
65              },
66            ],
67
68            map {
69
70              my $data = $options{$_};
71              if ( ref($data) ) {
72                $data = join('<BR>', keys %$data); #XXX display hash values too?
73              }
74
75              [
76                {
77                  'data'   => $part_event_condition->option_label($_). ':',
78                  'align'  => 'right',
79                  'valign' => 'top',
80                  'size'   => '-1',
81                },
82                {
83                  'data'  => $data,
84                  'align' => 'left',
85                  'size'  => '-1',
86                },
87              ];
88
89            } keys %options
90
91         }
92         $part_event->part_event_condition
93
94   ];
95
96 };
97
98 my $action_sub = sub {
99   my $part_event = shift;
100
101   my %options = $part_event->options;
102   
103   [
104
105     [
106       {
107         'data'       => $part_event->description,
108         'width'      => '100%',
109         'align'      => 'center',
110         'colspan'    => 2,
111       },
112     ],
113
114     map {
115           [
116             {
117               'data'  => $part_event->option_label($_). ':',
118               'align' => 'right',
119               'size'  => '-1',
120             },
121             {
122              'data'  => $options{$_},
123              'align' => 'left',
124               'size'  => '-1',
125             },
126           ];
127         }
128
129         keys %options
130   ];
131
132 };
133
134 my $link = [ $p.'edit/part_event.html?', 'eventpart' ];
135
136 </%once>
137 <%init>
138
139 die "access denied"
140   unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
141       || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');
142
143 my $html_init =
144   #XXX better description
145   'Events are billing, collection or other actions triggered when certain '.
146   'customer, invoice, package or other conditions are met.<BR><BR>'.
147   qq!<FORM METHOD="POST" ACTION="${p}edit/part_event.html">!.
148   qq!<A HREF="${p}edit/part_event.html"><I>Add a new event</I></A>!.
149   '&nbsp;or&nbsp;<SELECT NAME="clone"><OPTION></OPTION>';
150
151 foreach my $part_event ( qsearch('part_event', {'diabled'=>''}) ) {
152   $html_init .=  '<OPTION VALUE="'. $part_event->eventpart. '">'.
153                   $part_event->eventpart. ': '. $part_event->event. '</OPTION>';
154 }
155
156 $html_init .= '</SELECT><INPUT TYPE="submit" VALUE="Clone existing event">'.
157               '</FORM><BR>';
158      
159 my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '.
160                   $FS::CurrentUser::CurrentUser->agentnums_sql(
161                     'null_right'    => 'Edit global billing events',
162                     'viewall_right' => 'None',
163                   );
164
165 my $join_conditions  = FS::part_event_condition->join_conditions_sql;
166 my $order_conditions = FS::part_event_condition->order_conditions_sql;
167
168 </%init>