4.x style
[freeside.git] / httemplate / edit / svc_dsl.cgi
1 <% include( 'elements/svc_Common.html',
2               'table'              => 'svc_dsl',
3               'fields'             => \@fields,
4               'svc_new_callback'   => $new_cb,
5               'svc_edit_callback'  => $edit_cb,
6               'svc_error_callback' => $error_cb,
7               'html_foot'          => $html_foot,
8           )
9 %>
10 <%init>
11
12 die "access denied"
13   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
14
15 my $conf = new FS::Conf;
16 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
17
18 my $ti_fields = FS::svc_dsl->table_info->{'fields'};
19
20 my @fields = ();
21
22 my $html_foot = sub { "
23 <SCRIPT TYPE=\"text/javascript\">
24   function ikano_loop_type_changed() {
25         var loop_type = document.getElementById('loop_type').value;
26         var phonenum = document.getElementById('phonenum');
27         var gateway_access_number = document.getElementById('gateway_access_number');
28         if(loop_type == '0') {
29             phonenum.value = '';
30             phonenum.disabled = true;        
31             gateway_access_number.value = '';
32             gateway_access_number.disabled = true;
33         } else {
34             phonenum.disabled = false;
35             gateway_access_number.disabled = false;
36         }
37   }
38 </SCRIPT>
39 "; };
40
41 my $edit_cb = sub {
42     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
43     my @exports = $part_svc->part_export_dsl_pull;
44     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
45         if ( scalar(@exports) > 1 );
46
47     if ( scalar(@exports) == 1 ) {
48         my $export = @exports[0];                
49         if($export->exporttype eq 'ikano' && $export->import_mode) {
50             @fields = ();
51         }
52         elsif($export->exporttype eq 'ikano') {
53             @fields = ( 'password', 'monitored', );
54
55             if ( $svc_x->vendor_qual_id ) {
56               push @fields, { field => 'vendor_qual_id',
57                               type  => 'hidden',
58                               value => $svc_x->vendor_qual_id,
59                             };
60             } else {
61               push @fields, 'vendor_qual_id';
62             }
63
64             foreach my $hf (
65               grep { $_ !~ /^(password|monitored|vendor_qual_id)$/ }
66                 keys %$ti_fields
67             ) {
68               push @fields, {
69                 field => $hf,
70                 type  => 'hidden',
71                 value => $svc_x->$hf,
72               };
73             }
74         }
75         # else add any other export-specific stuff here
76     }
77     else {
78         push @fields, qw( first last company phonenum gateway_access_number circuitnum rate_band vpi vci );
79     }
80 };
81
82 my $new_cb = sub {
83     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
84     my @exports = $part_svc->part_export_dsl_pull;
85     die "more than one DSL-pulling export for svcpart ".$part_svc->svcpart
86       if ( scalar(@exports) > 1 );
87     
88     if ( scalar(@exports) == 1 ) {
89         my $export = @exports[0];                
90         if($export->exporttype eq 'ikano' && $export->import_mode) {
91             @fields = ( 'vendor_order_id' );
92             return;
93         }
94     }
95
96     my $cust_main = $cust_pkg->cust_main;
97
98     @fields = (
99         { field => 'first',
100           value => $cust_main->ship_first ? $cust_main->ship_first
101                                           : $cust_main->first,
102         },
103         { field => 'last',
104           value => $cust_main->ship_last ? $cust_main->ship_last
105                                          : $cust_main->last,
106         },
107         { field => 'company',
108           value => $cust_pkg->cust_main->ship_company,
109           value => $cust_main->ship_company ? $cust_main->ship_company
110                                             : $cust_main->company,
111         },
112     );
113
114     my $vendor_qual_id = '';
115     my $qual = '';
116     if ( $cgi->param('qualnum') ) {
117
118       $qual =
119         qsearchs('qual', { 'qualnum' => scalar($cgi->param('qualnum')) } )
120           or die 'unknown qualnum';
121
122       $vendor_qual_id = $qual->vendor_qual_id;
123
124       push @fields, { 'field' => 'qualnum',
125                       'type'  => 'hidden',
126                       'value' => $qual->qualnum,
127                     },
128                     { 'field' => 'phonenum',
129                       'type'  => 'fixed',
130                       'value' => $qual->phonenum,
131                     };
132     
133     } else {
134
135       my $phonenum = $cust_main->ship_daytime ? $cust_main->ship_daytime
136                                            : $cust_main->daytime;
137       $phonenum =~ s/[^0-9]//g;
138
139       push @fields,
140         { field => 'phonenum',
141           value => $phonenum,
142         };
143         { field => 'gateway_access_number',
144           value => '',
145         };
146
147
148     }
149
150     if ( scalar(@exports) == 1 ) {
151         my $export = @exports[0];                
152         if($export->exporttype eq 'ikano') {
153             my $ddd = $cust_pkg->start_date;
154             $ddd = time unless $ddd;
155
156             my @quals = $export->quals_by_cust_and_pkg($cust_pkg->cust_main->custnum,$cust_pkg->pkgpart);
157             my @prequalids;
158             my %prequal_labels;
159             foreach my $qual ( @quals ) {
160                 my $prequalid = $qual->vendor_qual_id;
161                 push @prequalids, $prequalid;
162                 $prequal_labels{$prequalid} = "$prequalid - qualification #"
163                                                             .$qual->qualnum;
164             }
165
166             if ( $vendor_qual_id ) {
167               splice @fields, -1, 0,
168                   { field    => 'loop_type',
169                     type     => 'fixed',
170                     value    => ( $qual->phonenum ? '' : '0' ),
171                     formatted_value => ( $qual->phonenum ? 'Line-share'
172                                                          : 'Standalone' ),
173                   };
174             } else {
175               splice @fields, -1, 0,
176                   { field    => 'loop_type',
177                     type     => 'select',
178                     options  => [ '', '0' ],
179                     labels   => { '' => 'Line-share', '0', => 'Standalone' },
180                     onchange => 'ikano_loop_type_changed',
181                   };
182             }
183
184             push @fields,
185                 'password', 
186                 { field => 'isp_chg', type => 'checkbox', value=>'Y', },
187                 'isp_prev',
188             ;
189
190             if ( $vendor_qual_id ) {
191               push @fields,
192                 { field => 'vendor_qual_id',
193                   type  => 'fixed',
194                   value => $vendor_qual_id,
195                 };
196             } else {
197               push @fields,
198                 { field    => 'vendor_qual_id', 
199                   type     => 'select',
200                   options  => \@prequalids,
201                   labels   => \%prequal_labels,
202                   onchange => 'ikano_vendor_qual_id_changed',
203                 };
204             }
205
206             push @fields,
207                 { field => 'vendor_order_type', 
208                   type  => 'hidden', 
209                   value => 'NEW' },
210                 { field => 'desired_due_date',
211                   type  => 'fixed',
212                   formatted_value => 
213                     time2str($date_format,$ddd),
214                   value => $ddd, 
215                 },
216             ;
217         }
218         # else add any other export-specific stuff here
219
220     } else { # display non-export and non-Ikano fields
221         push @fields, qw( rate_band circuitnum vpi vci );
222     }
223 };
224
225 my $error_cb = sub {
226     my( $cgi ) = @_;
227     #my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt) = @_;
228     if ( $cgi->param('svcnum') ) {
229       &{ $edit_cb }( @_ );
230     } else {
231       &{ $new_cb }( @_ );
232     }
233 };
234
235 </%init>