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