summaryrefslogtreecommitdiff
path: root/httemplate/edit/svc_dsl.cgi
blob: 5896f18ae4689bdaaf423ce9ea0fbdb83ca06517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<% include( 'elements/svc_Common.html',
              'table'              => 'svc_dsl',
              'fields'             => \@fields,
              'svc_new_callback'   => $new_cb,
              'svc_edit_callback'  => $edit_cb,
              'svc_error_callback' => $error_cb,
              'html_foot'          => $html_foot,
          )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?

my $conf = new FS::Conf;
my $date_format = $conf->config('date_format') || '%m/%d/%Y';

my $ti_fields = FS::svc_dsl->table_info->{'fields'};

my @fields = ();

my $html_foot = sub { "
<SCRIPT TYPE=\"text/javascript\">
  function ikano_loop_type_changed() {
        var loop_type = document.getElementById('loop_type').value;
        var phonenum = document.getElementById('phonenum');
        if(loop_type == '0') {
            phonenum.value = '';
            phonenum.disabled = true;        
        }
        else phonenum.disabled = false;
  }
</SCRIPT>
"; };

my $edit_cb = sub {
    my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
    my @exports = $part_svc->part_export_dsl_pull;
    die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
        if ( scalar(@exports) > 1 );

    if ( scalar(@exports) == 1 ) {
        my $export = @exports[0];                
        if($export->exporttype eq 'ikano') {
            @fields = ( 'password', 'monitored', );

            foreach my $hf ( keys %$ti_fields ) {
                push @fields, {
                    field => $hf,
                    type => 'hidden',
                    value => $svc_x->$hf,
                } unless ( $hf eq 'password' || $hf eq 'monitored' );
            }
        }
        # else add any other export-specific stuff here
    }
    else {
        push @fields, qw( first last company phonenum circuitnum rate_band vpi vci );
    }
};

my $new_cb = sub {
    my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
    my @exports = $part_svc->part_export_dsl_pull;
    die "more than one DSL-pulling export for svcpart ".$part_svc->svcpart
      if ( scalar(@exports) > 1 );

    my $cust_main = $cust_pkg->cust_main;

    @fields = (
        { field => 'first',
          value => $cust_main->ship_first ? $cust_main->ship_first
                                          : $cust_main->first,
        },
        { field => 'last',
          value => $cust_main->ship_last ? $cust_main->ship_last
                                         : $cust_main->last,
        },
        { field => 'company',
          value => $cust_pkg->cust_main->ship_company,
          value => $cust_main->ship_company ? $cust_main->ship_company
                                            : $cust_main->company,
        },
    );

    my $vendor_qual_id = '';
    my $qual = '';
    if ( $cgi->param('qualnum') ) {

      $qual =
        qsearchs('qual', { 'qualnum' => scalar($cgi->param('qualnum')) } )
          or die 'unknown qualnum';

      $vendor_qual_id = $qual->vendor_qual_id;

      push @fields, { 'field' => 'qualnum',
                      'type'  => 'hidden',
                      'value' => $qual->qualnum,
                    },
                    { 'field' => 'phonenum',
                      'type'  => 'fixed',
                      'value' => $qual->phonenum,
                    };
    
    } else {

      my $phonenum = $cust_main->ship_daytime ? $cust_main->ship_daytime
                                           : $cust_main->daytime;
      $phonenum =~ s/[^0-9]//g;

      push @fields,
        { field => 'phonenum',
          value => $phonenum,
        };

    }

    if ( scalar(@exports) == 1 ) {
        my $export = @exports[0];                
        if($export->exporttype eq 'ikano') {
            my $ddd = $cust_pkg->start_date;
            $ddd = time unless $ddd;

            my @quals = $export->quals_by_cust_and_pkg($cust_pkg->cust_main->custnum,$cust_pkg->pkgpart);
            my @prequalids;
            my %prequal_labels;
            foreach my $qual ( @quals ) {
                my $prequalid = $qual->vendor_qual_id;
                push @prequalids, $prequalid;
                $prequal_labels{$prequalid} = "$prequalid - qualification #"
                                                            .$qual->qualnum;
            }

            if ( $vendor_qual_id ) {
              splice @fields, -1, 0,
                  { field    => 'loop_type',
                    type     => 'fixed',
                    value    => ( $qual->phonenum ? '' : '0' ),
                    formatted_value => ( $qual->phonenum ? 'Line-share'
                                                         : 'Standalone' ),
                  };
            } else {
              splice @fields, -1, 0,
                  { field    => 'loop_type',
                    type     => 'select',
                    options  => [ '', '0' ],
                    labels   => { '' => 'Line-share', '0', => 'Standalone' },
                    onchange => 'ikano_loop_type_changed',
                  };
            }

            push @fields,
                'password', 
                { field => 'isp_chg', type => 'checkbox', value=>'Y', },
                'isp_prev',
            ;

            if ( $vendor_qual_id ) {
              push @fields,
                { field => 'vendor_qual_id',
                  type  => 'fixed',
                  value => $vendor_qual_id,
                };
            } else {
              push @fields,
                { field    => 'vendor_qual_id', 
                  type     => 'select',
                  options  => \@prequalids,
                  labels   => \%prequal_labels,
                  onchange => 'ikano_vendor_qual_id_changed',
                };
            }

            push @fields,
                { field => 'vendor_order_type', 
                  type  => 'hidden', 
                  value => 'NEW' },
                { field => 'desired_due_date',
                  type  => 'fixed',
                  formatted_value => 
                    time2str($date_format,$ddd),
                  value => $ddd, 
                },
            ;
        }
        # else add any other export-specific stuff here

    } else { # display non-export and non-Ikano fields
        push @fields, qw( rate_band circuitnum vpi vci );
    }
};

my $error_cb = sub {
    my( $cgi ) = @_;
    #my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt) = @_;
    if ( $cgi->param('svcnum') ) {
      &{ $edit_cb }( @_ );
    } else {
      &{ $new_cb }( @_ );
    }
};

</%init>