finish existing customer dsl order, RT#7111
[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         if(loop_type == '0') {
28             phonenum.value = '';
29             phonenum.disabled = true;        
30         }
31         else phonenum.disabled = false;
32   }
33 </SCRIPT>
34 "; };
35
36 my $edit_cb = sub {
37     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
38     my @exports = $part_svc->part_export_dsl_pull;
39     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
40         if ( scalar(@exports) > 1 );
41
42     if ( scalar(@exports) == 1 ) {
43         my $export = @exports[0];                
44         if($export->exporttype eq 'ikano') {
45             @fields = ( 'password', 'monitored', );
46
47             foreach my $hf ( keys %$ti_fields ) {
48                 push @fields, {
49                     field => $hf,
50                     type => 'hidden',
51                     value => $svc_x->$hf,
52                 } unless ( $hf eq 'password' || $hf eq 'monitored' );
53             }
54         }
55         # else add any other export-specific stuff here
56     }
57     else {
58         push @fields, qw( first last company phonenum circuitnum rate_band vpi vci );
59     }
60 };
61
62 my $new_cb = sub {
63     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
64     my @exports = $part_svc->part_export_dsl_pull;
65     die "more than one DSL-pulling export for svcpart ".$part_svc->svcpart
66       if ( scalar(@exports) > 1 );
67
68     my $cust_main = $cust_pkg->cust_main;
69
70     @fields = (
71         { field => 'first',
72           value => $cust_main->ship_first ? $cust_main->ship_first
73                                           : $cust_main->first,
74         },
75         { field => 'last',
76           value => $cust_main->ship_last ? $cust_main->ship_last
77                                          : $cust_main->last,
78         },
79         { field => 'company',
80           value => $cust_pkg->cust_main->ship_company,
81           value => $cust_main->ship_company ? $cust_main->ship_company
82                                             : $cust_main->company,
83         },
84     );
85
86     my $vendor_qual_id = '';
87     my $qual = '';
88     if ( $cgi->param('qualnum') ) {
89
90       $qual =
91         qsearchs('qual', { 'qualnum' => scalar($cgi->param('qualnum')) } )
92           or die 'unknown qualnum';
93
94       $vendor_qual_id = $qual->vendor_qual_id;
95
96       push @fields, { 'field' => 'qualnum',
97                       'type'  => 'hidden',
98                       'value' => $qual->qualnum,
99                     },
100                     { 'field' => 'phonenum',
101                       'type'  => 'fixed',
102                       'value' => $qual->phonenum,
103                     };
104     
105     } else {
106
107       my $phonenum = $cust_main->ship_daytime ? $cust_main->ship_daytime
108                                            : $cust_main->daytime;
109       $phonenum =~ s/[^0-9]//g;
110
111       push @fields,
112         { field => 'phonenum',
113           value => $phonenum,
114         };
115
116     }
117
118     if ( scalar(@exports) == 1 ) {
119         my $export = @exports[0];                
120         if($export->exporttype eq 'ikano') {
121             my $ddd = $cust_pkg->start_date;
122             $ddd = time unless $ddd;
123
124             my @quals = $export->quals_by_cust_and_pkg($cust_pkg->cust_main->custnum,$cust_pkg->pkgpart);
125             my @prequalids;
126             my %prequal_labels;
127             foreach my $qual ( @quals ) {
128                 my $prequalid = $qual->vendor_qual_id;
129                 push @prequalids, $prequalid;
130                 $prequal_labels{$prequalid} = "$prequalid - qualification #"
131                                                             .$qual->qualnum;
132             }
133
134             if ( $vendor_qual_id ) {
135               splice @fields, -1, 0,
136                   { field    => 'loop_type',
137                     type     => 'fixed',
138                     value    => ( $qual->phonenum ? '' : '0' ),
139                     formatted_value => ( $qual->phonenum ? 'Line-share'
140                                                          : 'Standalone' ),
141                   };
142             } else {
143               splice @fields, -1, 0,
144                   { field    => 'loop_type',
145                     type     => 'select',
146                     options  => [ '', '0' ],
147                     labels   => { '' => 'Line-share', '0', => 'Standalone' },
148                     onchange => 'ikano_loop_type_changed',
149                   };
150             }
151
152             push @fields,
153                 'password', 
154                 { field => 'isp_chg', type => 'checkbox', value=>'Y', },
155                 'isp_prev',
156             ;
157
158             if ( $vendor_qual_id ) {
159               push @fields,
160                 { field => 'vendor_qual_id',
161                   type  => 'fixed',
162                   value => $vendor_qual_id,
163                 };
164             } else {
165               push @fields,
166                 { field    => 'vendor_qual_id', 
167                   type     => 'select',
168                   options  => \@prequalids,
169                   labels   => \%prequal_labels,
170                   onchange => 'ikano_vendor_qual_id_changed',
171                 };
172             }
173
174             push @fields,
175                 { field => 'vendor_order_type', 
176                   type  => 'hidden', 
177                   value => 'NEW' },
178                 { field => 'desired_due_date',
179                   type  => 'fixed',
180                   formatted_value => 
181                     time2str($date_format,$ddd),
182                   value => $ddd, 
183                 },
184             ;
185         }
186         # else add any other export-specific stuff here
187
188     } else { # display non-export and non-Ikano fields
189         push @fields, qw( rate_band circuitnum vpi vci );
190     }
191 };
192
193 my $error_cb = sub {
194     my( $cgi ) = @_;
195     #my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt) = @_;
196     if ( $cgi->param('svcnum') ) {
197       &{ $edit_cb }( @_ );
198     } else {
199       &{ $new_cb }( @_ );
200     }
201 };
202
203 </%init>