Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / browse / part_svc.cgi
1 <% include('/elements/header.html', 'Service Definition Listing') %>
2
3 <SCRIPT>
4 function part_export_areyousure(href) {
5   if (confirm("Are you sure you want to delete this export?") == true)
6     window.location.href = href;
7 }
8 </SCRIPT>
9
10     Service definitions are the templates for items you offer to your customers.<BR><BR>
11
12 <FORM METHOD="POST" ACTION="<% $p %>edit/part_svc.cgi">
13 <A HREF="<% $p %>edit/part_svc.cgi"><I>Add a new service definition</I></A>
14 % if ( @part_svc ) { 
15 &nbsp;or&nbsp;<SELECT NAME="clone"><OPTION></OPTION>
16 % foreach my $part_svc ( @part_svc ) { 
17
18   <OPTION VALUE="<% $part_svc->svcpart %>"><% $part_svc->svc %></OPTION>
19 % } 
20
21 </SELECT><INPUT TYPE="submit" VALUE="Clone existing service">
22 % } 
23
24 </FORM><BR>
25
26 <% $total %> service definitions
27 <% $cgi->param('showdisabled')
28       ? do { $cgi->param('showdisabled', 0);
29              '( <a href="'. $cgi->self_url. '">hide disabled services</a> )'; }
30       : do { $cgi->param('showdisabled', 1);
31              '( <a href="'. $cgi->self_url. '">show disabled services</a> )'; }
32 %>
33 % $cgi->param('showdisabled', ( 1 ^ $cgi->param('showdisabled') ) ); 
34
35 <% include('/elements/table-grid.html') %>
36 %   my $bgcolor1 = '#eeeeee';
37 %   my $bgcolor2 = '#ffffff';
38 %   my $bgcolor = '';
39
40   <TR>
41
42     <TH CLASS="grid" BGCOLOR="#cccccc"><A HREF="<% do { $cgi->param('orderby', 'svcpart'); $cgi->self_url } %>">#</A></TH>
43
44 % if ( $cgi->param('showdisabled') ) { 
45       <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
46 % } 
47
48     <TH CLASS="grid" BGCOLOR="#cccccc"><A HREF="<% do { $cgi->param('orderby', 'svc'); $cgi->self_url; } %>">Service</A></TH>
49
50     <TH CLASS="grid" BGCOLOR="#cccccc">Table</TH>
51
52     <TH CLASS="grid" BGCOLOR="#cccccc"><A HREF="<% do { $cgi->param('orderby', 'active'); $cgi->self_url; } %>"><FONT SIZE=-1>Customer<BR>Services</FONT></A></TH>
53
54     <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Customer<BR>Self-service</FONT></TH>
55
56     <TH CLASS="grid" BGCOLOR="#cccccc">Export</TH>
57
58     <TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>
59
60     <TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>
61
62     <TH COLSPAN=2 CLASS="grid" BGCOLOR="#cccccc">Modifier</TH>
63
64     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="font-size: smaller;">Required</TH>
65
66   </TR>
67 % my $conf = FS::Conf->new;
68 % foreach my $part_svc ( @part_svc ) {
69 %     my $svcdb = $part_svc->svcdb;
70 %     my $svc_x = "FS::$svcdb"->new( { svcpart => $part_svc->svcpart } );
71 %     my @dfields = $svc_x->fields;
72 %     push @dfields, 'usergroup' if $svcdb eq 'svc_acct' #double kludge
73 %                                or ($svcdb eq 'svc_broadband' 
74 %                                    and $conf->exists('svc_broadband-radius'));
75 %     my @fields =
76 %       grep { my $col = $part_svc->part_svc_column($_);
77 %              my $def = FS::part_svc->svc_table_fields($svcdb)->{$_};
78 %              $svc_x->pvf($_)
79 %              or $_ ne 'svcnum' && (
80 %                $col->columnflag || ( $col->columnlabel !~ /^\S*$/
81 %                                      && $col->columnlabel ne $def->{'label'}
82 %                                    )
83 %                                 || ( $col->required
84 %                                      && !$def->{'required'}
85 %                                    )
86 %              )
87 %            }
88 %            @dfields ;
89 %     my $rowspan = scalar(@fields) || 1;
90 %     $rowspan++ if $part_svc->restrict_edit_password;
91 %     my $url = "${p}edit/part_svc.cgi?". $part_svc->svcpart;
92 %
93 %     if ( $bgcolor eq $bgcolor1 ) {
94 %       $bgcolor = $bgcolor2;
95 %     } else {
96 %       $bgcolor = $bgcolor1;
97 %     }
98
99
100   <TR>
101
102     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
103       <A HREF="<% $url %>"><% $part_svc->svcpart %></A>
104     </TD>
105
106 % if ( $cgi->param('showdisabled') ) { 
107     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
108       <% $part_svc->disabled
109             ? '<FONT COLOR="#FF0000"><B>Disabled</B></FONT>'
110             : '<FONT COLOR="#00CC00"><B>Enabled</B></FONT>'
111       %>
112     </TD>
113 % } 
114
115     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<% $url %>">
116       <% $part_svc->svc %></A></TD>
117
118     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
119       <% $svcdb %></TD>
120
121     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
122 % my $svcurl_active = svc_url( 'ahref' => 1, 'm' => $m, 'action' => 'search', 'part_svc' => $part_svc, 'query' => "svcpart=". $part_svc->svcpart . "&cancelled=0");
123 % my $svcurl_cancel = svc_url( 'ahref' => 1, 'm' => $m, 'action' => 'search', 'part_svc' => $part_svc, 'query' => "svcpart=". $part_svc->svcpart . "&cancelled=1");
124       <FONT COLOR="#00CC00"><B><% $num_cust_svc_active{$part_svc->svcpart} %></B></FONT>&nbsp;<% $num_cust_svc_active{$part_svc->svcpart} ? $svcurl_active : '' %>active<% $num_cust_svc_active{$part_svc->svcpart} ? '</A>' : '' %>
125 % if ( $num_cust_svc_cancelled{$part_svc->svcpart} ) { 
126         <BR><FONT COLOR="#FF0000"><B><% $num_cust_svc_cancelled{$part_svc->svcpart} %></B></FONT>&nbsp;<% $svcurl_cancel %>cancelled</A>
127 % }
128 % if ( $num_cust_svc{$part_svc->svcpart} ) { 
129         <BR><FONT SIZE="-1">[ <A HREF="<%$p%>edit/bulk-cust_svc.html?svcpart=<% $part_svc->svcpart %>">change</A> ]</FONT>
130 % } 
131
132     </TD>
133
134 % tie my %selfservice_access, 'Tie::IxHash', #false laziness w/edit/part_svc.cgi
135 %   ''         => 'Yes',
136 %   'hidden'   => 'Hidden',
137 %   'readonly' => 'Read-only',
138 % ;
139     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
140       <% $selfservice_access{$part_svc->selfservice_access} %></TD>
141
142     <TD ROWSPAN=<% $rowspan %> CLASS="inv" BGCOLOR="<% $bgcolor %>">
143       <TABLE CLASS="inv">
144 %
145 %#  my @part_export =
146 %map { qsearchs('part_export', { exportnum => $_->exportnum } ) } qsearch('export_svc', { svcpart => $part_svc->svcpart } ) ;
147 %  foreach my $part_export (
148 %    map { qsearchs('part_export', { exportnum => $_->exportnum } ) } 
149 %      qsearch('export_svc', { svcpart => $part_svc->svcpart } )
150 %  ) {
151 %
152
153         <TR>
154           <TD><A HREF="<% $p %>edit/part_export.cgi?<% $part_export->exportnum %>"><% $part_export->label_html %></A></TD>
155         </TR>
156 %  } 
157
158       </TABLE>
159     </TD>
160
161 %     unless ( @fields ) {
162 %       for ( 1..5 ) {  
163           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"</TD>
164 %       }
165 %     }
166 %   
167 %     my($n1)='';
168 %     foreach my $field ( sort @fields ) {
169 %
170 %       #a few lines of false laziness w/edit/part_svc.cgi
171 %       my $def = FS::part_svc->svc_table_fields($svcdb)->{$field};
172 %       my $formatter = $def->{format} || sub { shift };
173 %
174 %       my $part_svc_column = $part_svc->part_svc_column($field);
175 %       my $label = $part_svc_column->columnlabel || $def->{'label'};
176 %       my $flag = $part_svc_column->columnflag;
177
178      <% $n1 %>
179      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $field %></TD>
180      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $label %></TD>
181      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $flag{$flag} %></TD>
182      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
183 % my $value = &$formatter($part_svc->part_svc_column($field)->columnvalue);
184 % if ( $flag =~ /^[MAH]$/ ) { 
185 %   my $select_table = ($flag eq 'H') ? 'hardware_class' : 'inventory_class';
186 %   foreach my $classnum ( split(',', $value) ) {
187 %     $select_class{$classnum} =
188 %       qsearchs($select_table, { 'classnum' => $classnum } );
189
190       <% $select_class{$classnum}
191             ? $select_class{$classnum}->classname
192             : "WARNING: $select_table.classnum $classnum not found" %><BR>
193 %   }
194 % } else { 
195
196             <% $value %>
197 % }
198
199      </TD>
200      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
201 % if ($part_svc_column->required) {
202        Yes
203 % }
204      </TD>
205 %     $n1="</TR><TR>";
206 %     } #foreach $field
207 %   if ( $part_svc->restrict_edit_password ) {
208    <TR>
209      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" COLSPAN=4 ALIGN="left">
210       <B><% emt('Password editing restricted.') %></B>
211      </TD>
212    </TR>
213 %   }
214
215   </TR>
216 % }  #foreach $part_svc
217
218 </TABLE>
219 </BODY>
220 </HTML>
221 <%init>
222  
223 die "access denied"
224   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
225
226 #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
227 my %flag = (
228   ''  => '',
229   'D' => 'Default',
230   'F' => 'Fixed (unchangeable)',
231   'S' => 'Selectable choice',
232   #'M' => 'Manual selection from inventory',
233   'M' => 'Manual selected from inventory',
234   #'A' => 'Automatically fill in from inventory',
235   'A' => 'Automatically filled in from inventory',
236   'H' => 'Selected from hardware class',
237   'X' => 'Excluded',
238 );
239
240 my %search;
241 if ( $cgi->param('showdisabled') ) {
242   %search = ();
243 } else {
244   %search = ( 'disabled' => '' );
245 }
246
247 my @part_svc =
248   sort { $a->getfield('svcpart') <=> $b->getfield('svcpart') }
249     qsearch('part_svc', \%search );
250 my $total = scalar(@part_svc);
251
252 ## The Active/Cancelled distinction is a bit awkward,
253 ## active currently includes unattached and suspended services,
254 ## but we've previously referred to EVERY existing cust_svc as "Active",
255 ## and we don't really want to know numbers by individual package status,
256 ## so for now the UI will distinguish these as "Active" and "Cancelled",
257 ## but please let's not go so far as to introduce the idea of "Service Status"
258
259 my %num_cust_svc_active;
260 my %num_cust_svc_cancelled;
261 my %num_cust_svc;
262 foreach my $part_svc (@part_svc) {
263   $num_cust_svc{$part_svc->svcpart} = $part_svc->num_cust_svc;
264   $num_cust_svc_cancelled{$part_svc->svcpart} = $part_svc->num_cust_svc_cancelled;
265   $num_cust_svc_active{$part_svc->svcpart} = $num_cust_svc{$part_svc->svcpart} - $num_cust_svc_cancelled{$part_svc->svcpart};
266 }
267
268 if ( $cgi->param('orderby') eq 'active' ) {
269   @part_svc = sort { $num_cust_svc{$b->svcpart} <=>
270                      $num_cust_svc{$a->svcpart}     } @part_svc;
271 } elsif ( $cgi->param('orderby') eq 'svc' ) { 
272   @part_svc = sort { lc($a->svc) cmp lc($b->svc) } @part_svc;
273 }
274
275 my %select_class = ();
276
277 </%init>