add svc_phone on new customer first package, RT#4315
[freeside.git] / httemplate / edit / cust_main.cgi
1 <% include('/elements/header.html',
2       "Customer $action",
3       '',
4       ' onUnload="myclose()"' #hmm, in billing.html
5 ) %>
6
7 <% include('/elements/error.html') %>
8
9 <FORM NAME   = "CustomerForm"
10       METHOD = "POST"
11       ACTION = "<% popurl(1) %>process/cust_main.cgi"
12 %#      STYLE = "margin-bottom: 0"
13 %#      STYLE="margin-top: 0; margin-bottom: 0">
14 >
15
16 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
17
18 % if ( $custnum ) { 
19   Customer #<B><% $cust_main->display_custnum %></B> - 
20   <B><FONT COLOR="#<% $cust_main->statuscolor %>">
21     <% ucfirst($cust_main->status) %>
22   </FONT></B>
23   <BR><BR>
24 % } 
25
26 %# agent, agent_custid, refnum (advertising source), referral_custnum
27 <% include('cust_main/top_misc.html', $cust_main, 'custnum' => $custnum ) %>
28
29 %# birthdate
30 % if ( $conf->exists('cust_main-enable_birthdate') ) {
31   <BR>
32   <% include('cust_main/birthdate.html', $cust_main) %>
33 % }
34
35 %# contact info
36
37 %  my $same_checked = '';
38 %  my $ship_disabled = '';
39 %  unless ( $cust_main->ship_last && $same ne 'Y' ) {
40 %    $same_checked = 'CHECKED';
41 %    $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"';
42 %    foreach (
43 %      qw( last first company address1 address2 city county state zip country
44 %          daytime night fax )
45 %    ) {
46 %      $cust_main->set("ship_$_", $cust_main->get($_) );
47 %    }
48 %  }
49
50 <BR><BR>
51 <FONT SIZE="+1"><B>Billing address</B></FONT>
52
53 <% include('cust_main/contact.html',
54              'cust_main'    => $cust_main,
55              'pre'          => '',
56              'onchange'     => 'bill_changed(this)',
57              'disabled'     => '',
58              'ss'           => $ss,
59              'stateid'      => $stateid,
60              'same_checked' => $same_checked, #for address2 "Unit #" labeling
61           )
62 %>
63
64 <SCRIPT>
65 function bill_changed(what) {
66   if ( what.form.same.checked ) {
67 % for (qw( last first company address1 address2 city zip daytime night fax )) { 
68
69     what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
70 % } 
71
72     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
73
74     function fix_ship_county() {
75       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
76     }
77
78     function fix_ship_state() {
79       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
80       ship_state_changed(what.form.ship_state, fix_ship_county );
81     }
82
83     ship_country_changed(what.form.ship_country, fix_ship_state );
84
85   }
86 }
87 function samechanged(what) {
88   if ( what.checked ) {
89     bill_changed(what);
90
91 %   for (qw( last first company address1 address2 city county state zip country daytime night fax )) { 
92       what.form.ship_<%$_%>.disabled = true;
93       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
94 %   } 
95
96 %   if ( $conf->exists('cust_main-require_address2') ) {
97       document.getElementById('address2_required').style.visibility = '';
98       document.getElementById('address2_label').style.visibility = '';
99       document.getElementById('ship_address2_required').style.visibility = 'hidden';
100       document.getElementById('ship_address2_label').style.visibility = 'hidden';
101 %   }
102
103   } else {
104
105 %   for (qw( last first company address1 address2 city county state zip country daytime night fax )) { 
106       what.form.ship_<%$_%>.disabled = false;
107       what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
108 %   } 
109
110 %   if ( $conf->exists('cust_main-require_address2') ) {
111       document.getElementById('address2_required').style.visibility = 'hidden';
112       document.getElementById('address2_label').style.visibility = 'hidden';
113       document.getElementById('ship_address2_required').style.visibility = '';
114       document.getElementById('ship_address2_label').style.visibility = '';
115 %   }
116
117   }
118 }
119 </SCRIPT>
120
121 <BR>
122 <FONT SIZE="+1"><B>Service address</B></FONT>
123
124 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
125 <% include('cust_main/contact.html',
126              'cust_main' => $cust_main,
127              'pre'       => 'ship_',
128              'onchange'  => '',
129              'disabled'  => $ship_disabled,
130           )
131 %>
132
133 %# billing info
134 <% include( 'cust_main/billing.html', $cust_main,
135                'payinfo'        => $payinfo,
136                'invoicing_list' => \@invoicing_list,
137            )
138 %>
139
140 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
141 % if (!$ro_comments || $cust_main->comments) {
142
143     <BR>Comments
144     <% &ntable("#cccccc") %>
145       <TR>
146         <TD>
147           <TEXTAREA NAME = "comments"
148                     COLS = 80
149                     ROWS = 5
150                     WRAP = "HARD"
151                     <% $ro_comments %>
152           ><% $cust_main->comments %></TEXTAREA>
153         </TD>
154       </TR>
155     </TABLE>
156
157 % }
158
159 % unless ( $custnum ) {
160
161     <% include('cust_main/first_pkg.html', $cust_main,
162                  'pkgpart_svcpart' => $pkgpart_svcpart,
163                  #svc_acct
164                  'username'        => $username,
165                  'password'        => $password,
166                  'popnum'          => $popnum,
167                  'saved_domsvc'    => $saved_domsvc,
168                  %svc_phone,
169               )
170     %>
171
172 % }
173
174 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
175
176 % foreach my $hidden (
177 %    'payauto',
178 %    'payinfo', 'payinfo1', 'payinfo2', 'paytype',
179 %    'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
180 %    'paystart_month', 'paystart_year', 'payissue',
181 %    'payip',
182 %    'paid',
183 % ) {
184     <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
185 % } 
186
187 <% include('cust_main/bottomfixup.html') %>
188
189 <BR>
190 <INPUT TYPE    = "button"
191        NAME    = "submitButton"
192        ID      = "submitButton"
193        VALUE   = "<% $custnum ?  "Apply Changes" : "Add Customer" %>"
194        onClick = "this.disabled=true; bottomfixup(this.form);"
195 >
196 </FORM>
197
198 <% include('/elements/footer.html') %>
199
200 <%init>
201
202 die "access denied"
203   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
204
205 my $conf = new FS::Conf;
206
207 #get record
208
209 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
210 my $same = '';
211 my $pkgpart_svcpart = ''; #first_pkg
212 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
213 my %svc_phone = ();
214
215 if ( $cgi->param('error') ) {
216
217   $cust_main = new FS::cust_main ( {
218     map { $_, scalar($cgi->param($_)) } fields('cust_main')
219   } );
220
221   $custnum = $cust_main->custnum;
222   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
223   $same = $cgi->param('same');
224   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
225   $ss = $cust_main->ss;           # don't mask an entered value on errors
226   $stateid = $cust_main->stateid; # don't mask an entered value on errors
227   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
228
229   $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
230
231   #svc_acct
232   $username = $cgi->param('username');
233   $password = $cgi->param('_password');
234   $popnum = $cgi->param('popnum');
235   $saved_domsvc = $cgi->param('domsvc') || '';
236   if ( $saved_domsvc =~ /^(\d+)$/ ) {
237     $saved_domsvc = $1;
238   } else {
239     $saved_domsvc = '';
240   }
241
242   #svc_phone
243   $svc_phone{$_} = $cgi->param($_)
244     foreach qw( countrycode phonenum sip_password pin phone_name );
245
246 } elsif ( $cgi->keywords ) { #editing
247
248   my( $query ) = $cgi->keywords;
249   $query =~ /^(\d+)$/;
250   $custnum=$1;
251   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
252   if ( $cust_main->dbdef_table->column('paycvv')
253        && length($cust_main->paycvv)             ) {
254     my $paycvv = $cust_main->paycvv;
255     $paycvv =~ s/./*/g;
256     $cust_main->paycvv($paycvv);
257   }
258   @invoicing_list = $cust_main->invoicing_list;
259   $ss = $cust_main->masked('ss');
260   $stateid = $cust_main->masked('stateid');
261   $payinfo = $cust_main->paymask;
262
263 } else { #new customer
264
265   $custnum='';
266   $cust_main = new FS::cust_main ( {} );
267   $cust_main->otaker( &getotaker );
268   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
269   @invoicing_list = ();
270   push @invoicing_list, 'POST'
271     unless $conf->exists('disablepostalinvoicedefault');
272   $ss = '';
273   $stateid = '';
274   $payinfo = '';
275
276 }
277
278 my $error = $cgi->param('error');
279 $cgi->delete_all();
280 $cgi->param('error', $error);
281
282 my $action = $custnum ? 'Edit' : 'Add';
283 $action .= ": ". $cust_main->name if $custnum;
284
285 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
286
287 </%init>