This commit was generated by cvs2svn to compensate for changes in r6252,
[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">Export</TH>
55
56     <TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>
57
58     <TH COLSPAN=2 CLASS="grid" BGCOLOR="#cccccc">Modifier</TH>
59
60   </TR>
61
62 % foreach my $part_svc ( @part_svc ) {
63 %     my $svcdb = $part_svc->svcdb;
64 %     my $svc_x = "FS::$svcdb"->new( { svcpart => $part_svc->svcpart } );
65 %     my @dfields = $svc_x->fields;
66 %     push @dfields, 'usergroup' if $svcdb eq 'svc_acct'; #kludge
67 %     my @fields =
68 %       grep { $svc_x->pvf($_)
69 %           or $_ ne 'svcnum' && $part_svc->part_svc_column($_)->columnflag }
70 %            @dfields ;
71 %     my $rowspan = scalar(@fields) || 1;
72 %     my $url = "${p}edit/part_svc.cgi?". $part_svc->svcpart;
73 %
74 %     if ( $bgcolor eq $bgcolor1 ) {
75 %       $bgcolor = $bgcolor2;
76 %     } else {
77 %       $bgcolor = $bgcolor1;
78 %     }
79
80
81   <TR>
82
83     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
84       <A HREF="<% $url %>"><% $part_svc->svcpart %></A>
85     </TD>
86
87 % if ( $cgi->param('showdisabled') ) { 
88     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
89       <% $part_svc->disabled
90             ? '<FONT COLOR="#FF0000"><B>Disabled</B></FONT>'
91             : '<FONT COLOR="#00CC00"><B>Enabled</B></FONT>'
92       %>
93     </TD>
94 % } 
95
96     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<% $url %>">
97       <% $part_svc->svc %></A></TD>
98
99     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
100       <% $svcdb %></TD>
101
102     <TD ROWSPAN=<% $rowspan %> CLASS="grid" BGCOLOR="<% $bgcolor %>">
103       <FONT COLOR="#00CC00"><B><% $num_active_cust_svc{$part_svc->svcpart} %></B></FONT>&nbsp;<% $num_active_cust_svc{$part_svc->svcpart} ? svc_url( 'ahref' => 1, 'm' => $m, 'action' => 'search', 'part_svc' => $part_svc, 'query' => "svcpart=". $part_svc->svcpart ) : '<A NAME="zero">' %>active</A>
104
105 % if ( $num_active_cust_svc{$part_svc->svcpart} ) { 
106         <BR><FONT SIZE="-1">[ <A HREF="<%$p%>edit/bulk-cust_svc.html?svcpart=<% $part_svc->svcpart %>">change</A> ]</FONT>
107 % } 
108
109     </TD>
110
111     <TD ROWSPAN=<% $rowspan %> CLASS="inv" BGCOLOR="<% $bgcolor %>">
112       <TABLE CLASS="inv">
113 %
114 %#  my @part_export =
115 %map { qsearchs('part_export', { exportnum => $_->exportnum } ) } qsearch('export_svc', { svcpart => $part_svc->svcpart } ) ;
116 %  foreach my $part_export (
117 %    map { qsearchs('part_export', { exportnum => $_->exportnum } ) } 
118 %      qsearch('export_svc', { svcpart => $part_svc->svcpart } )
119 %  ) {
120 %
121
122         <TR>
123           <TD><A HREF="<% $p %>edit/part_export.cgi?<% $part_export->exportnum %>"><% $part_export->exportnum %>:&nbsp;<% $part_export->exporttype %>&nbsp;to&nbsp;<% $part_export->machine %></A></TD>
124         </TR>
125 %  } 
126
127       </TABLE>
128     </TD>
129
130 %     unless ( @fields ) {
131 %       for ( 1..3 ) {  
132           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"</TD>
133 %       }
134 %     }
135 %   
136 %     my($n1)='';
137 %     foreach my $field ( @fields ) {
138 %       my $formatter =
139 %            FS::part_svc->svc_table_fields($svcdb)->{$field}->{format}
140 %            || sub { shift };
141 %       my $flag = $part_svc->part_svc_column($field)->columnflag;
142 %
143
144      <% $n1 %>
145      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $field %></TD>
146      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $flag{$flag} %></TD>
147
148      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
149 % my $value = &$formatter($part_svc->part_svc_column($field)->columnvalue);
150 %          if ( $flag =~ /^[MA]$/ ) { 
151 %            $inventory_class{$value}
152 %              ||= qsearchs('inventory_class', { 'classnum' => $value } );
153 %       
154
155             <% $inventory_class{$value}
156                   ? $inventory_class{$value}->classname
157                   : "WARNING: inventory_class.classnum $value not found" %>
158 % } else { 
159
160             <% $value %>
161 % } 
162
163      </TD>
164 %     $n1="</TR><TR>";
165 %     }
166 %
167
168   </TR>
169 % } 
170
171 </TABLE>
172 </BODY>
173 </HTML>
174 <%init>
175  
176 die "access denied"
177   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
178
179 #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
180 my %flag = (
181   ''  => '',
182   'D' => 'Default',
183   'F' => 'Fixed (unchangeable)',
184   'S' => 'Selectable choice',
185   #'M' => 'Manual selection from inventory',
186   'M' => 'Manual selected from inventory',
187   #'A' => 'Automatically fill in from inventory',
188   'A' => 'Automatically filled in from inventory',
189   'X' => 'Excluded',
190 );
191
192 my %search;
193 if ( $cgi->param('showdisabled') ) {
194   %search = ();
195 } else {
196   %search = ( 'disabled' => '' );
197 }
198
199 my @part_svc =
200   sort { $a->getfield('svcpart') <=> $b->getfield('svcpart') }
201     qsearch('part_svc', \%search );
202 my $total = scalar(@part_svc);
203
204 my %num_active_cust_svc = map { $_->svcpart => $_->num_cust_svc } @part_svc;
205
206 if ( $cgi->param('orderby') eq 'active' ) {
207   @part_svc = sort { $num_active_cust_svc{$b->svcpart} <=>
208                      $num_active_cust_svc{$a->svcpart}     } @part_svc;
209 } elsif ( $cgi->param('orderby') eq 'svc' ) { 
210   @part_svc = sort { lc($a->svc) cmp lc($b->svc) } @part_svc;
211 }
212
213 my %inventory_class = ();
214
215 </%init>