This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / httemplate / edit / cust_main.cgi
1 <% include('/elements/header.html',
2       $title,
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 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospectnum %>">
18
19 % if ( $custnum ) { 
20   Customer #<B><% $cust_main->display_custnum %></B> - 
21   <B><FONT COLOR="#<% $cust_main->statuscolor %>">
22     <% ucfirst($cust_main->status) %>
23   </FONT></B>
24   <BR><BR>
25 % } 
26
27 %# agent, agent_custid, refnum (advertising source), referral_custnum
28 <% include('cust_main/top_misc.html', $cust_main, 'custnum' => $custnum ) %>
29
30 %# birthdate
31 % if ( $conf->exists('cust_main-enable_birthdate') ) {
32   <BR>
33   <% include('cust_main/birthdate.html', $cust_main) %>
34 % }
35
36 %# latitude and longitude
37 % if ( $conf->exists('cust_main-require_censustract') ) {
38 %   my ($latitude, $longitude) = $cust_main->service_coordinates;
39 %   $latitude ||= $conf->config('company_latitude') || '';
40 %   $longitude ||= $conf->config('company_longitude') || '';
41   <INPUT NAME="latitude" TYPE="hidden" VALUE="<% $latitude |h %>">
42   <INPUT NAME="longitude" TYPE="hidden" VALUE="<% $longitude |h %>">
43 % }
44
45 %# contact info
46
47 %  my $same_checked = '';
48 %  my $ship_disabled = '';
49 %  my @ship_style = ();
50 %  unless ( $cust_main->ship_last && $same ne 'Y' ) {
51 %    $same_checked = 'CHECKED';
52 %    $ship_disabled = 'DISABLED';
53 %    push @ship_style, 'background-color:#dddddd';
54 %    foreach (
55 %      qw( last first company address1 address2 city county state zip country
56 %          daytime night fax )
57 %    ) {
58 %      $cust_main->set("ship_$_", $cust_main->get($_) );
59 %    }
60 %  }
61
62 <BR>
63 <FONT SIZE="+1"><B>Billing address</B></FONT>
64
65 <% include('cust_main/contact.html',
66              'cust_main'    => $cust_main,
67              'pre'          => '',
68              'onchange'     => 'bill_changed(this)',
69              'disabled'     => '',
70              'ss'           => $ss,
71              'stateid'      => $stateid,
72              'same_checked' => $same_checked, #for address2 "Unit #" labeling
73           )
74 %>
75
76 <SCRIPT>
77 function bill_changed(what) {
78   if ( what.form.same.checked ) {
79 % for (qw( last first company address1 address2 city zip daytime night fax )) { 
80     what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
81 % } 
82
83     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
84
85     function fix_ship_city() {
86       what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
87       what.form.ship_city.style.display = what.form.city.style.display;
88       what.form.ship_city_select.style.display = what.form.city_select.style.display;
89     }
90
91     function fix_ship_county() {
92       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
93       ship_county_changed(what.form.ship_county, fix_ship_city );
94     }
95
96     function fix_ship_state() {
97       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
98       ship_state_changed(what.form.ship_state, fix_ship_county );
99     }
100
101     ship_country_changed(what.form.ship_country, fix_ship_state );
102
103   }
104 }
105 function samechanged(what) {
106   if ( what.checked ) {
107     bill_changed(what);
108
109 %   my @fields = qw( last first company address1 address2 city city_select county state zip country daytime night fax );
110 %   for (@fields) { 
111       what.form.ship_<%$_%>.disabled = true;
112       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
113 %   } 
114
115 %   if ( $conf->exists('cust_main-require_address2') ) {
116       document.getElementById('address2_required').style.visibility = '';
117       document.getElementById('address2_label').style.visibility = '';
118       document.getElementById('ship_address2_required').style.visibility = 'hidden';
119       document.getElementById('ship_address2_label').style.visibility = 'hidden';
120 %   }
121
122   } else {
123
124 %   for (@fields) { 
125       what.form.ship_<%$_%>.disabled = false;
126       what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
127 %   } 
128
129 %   if ( $conf->exists('cust_main-require_address2') ) {
130       document.getElementById('address2_required').style.visibility = 'hidden';
131       document.getElementById('address2_label').style.visibility = 'hidden';
132       document.getElementById('ship_address2_required').style.visibility = '';
133       document.getElementById('ship_address2_label').style.visibility = '';
134 %   }
135
136   }
137 }
138 </SCRIPT>
139
140 <BR>
141 <FONT SIZE="+1"><B>Service address</B></FONT>
142
143 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
144 <% include('cust_main/contact.html',
145              'cust_main' => $cust_main,
146              'pre'       => 'ship_',
147              'onchange'  => '',
148              'disabled'  => $ship_disabled,
149              'style'     => \@ship_style
150           )
151 %>
152
153 %# billing info
154 <% include( 'cust_main/billing.html', $cust_main,
155                'payinfo'        => $payinfo,
156                'invoicing_list' => \@invoicing_list,
157            )
158 %>
159
160 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
161 % if (!$ro_comments || $cust_main->comments) {
162
163     <BR>Comments
164     <% &ntable("#cccccc") %>
165       <TR>
166         <TD>
167           <TEXTAREA NAME = "comments"
168                     COLS = 80
169                     ROWS = 5
170                     WRAP = "HARD"
171                     <% $ro_comments %>
172           ><% $cust_main->comments %></TEXTAREA>
173         </TD>
174       </TR>
175     </TABLE>
176
177 % }
178
179 % unless ( $custnum ) {
180
181     <% include('cust_main/first_pkg.html', $cust_main,
182                  'pkgpart_svcpart' => $pkgpart_svcpart,
183                  'disable_empty'   =>
184                    scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
185                  #svc_acct
186                  'username'        => $username,
187                  'password'        => $password,
188                  'popnum'          => $popnum,
189                  'saved_domsvc'    => $saved_domsvc,
190                  %svc_phone,
191                  %svc_dsl,
192               )
193     %>
194
195 % }
196
197 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
198
199 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
200
201 %# cust_main/bottomfixup.js
202 % foreach my $hidden (
203 %    'payauto',
204 %    'payinfo', 'payinfo1', 'payinfo2', 'paytype',
205 %    'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
206 %    'paystart_month', 'paystart_year', 'payissue',
207 %    'payip',
208 %    'paid',
209 % ) {
210     <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
211 % } 
212
213 <% include('cust_main/bottomfixup.html') %>
214
215 <BR>
216 <INPUT TYPE    = "button"
217        NAME    = "submitButton"
218        ID      = "submitButton"
219        VALUE   = "<% $custnum ?  "Apply Changes" : "Add Customer" %>"
220        onClick = "this.disabled=true; bottomfixup(this.form);"
221 >
222 </FORM>
223
224 <% include('/elements/footer.html') %>
225
226 <%init>
227
228 my $curuser = $FS::CurrentUser::CurrentUser;
229
230 #probably redundant given the checks below...
231 die "access denied"
232   unless $curuser->access_right('New customer')
233      ||  $curuser->access_right('Edit customer');
234
235 my $conf = new FS::Conf;
236
237 #get record
238
239 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
240 my $same = '';
241 my $pkgpart_svcpart = ''; #first_pkg
242 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
243 my %svc_phone = ();
244 my %svc_dsl = ();
245 my $prospectnum = '';
246 my $locationnum = '';
247
248 if ( $cgi->param('error') ) {
249
250   $cust_main = new FS::cust_main ( {
251     map { $_, scalar($cgi->param($_)) } fields('cust_main')
252   } );
253
254   $custnum = $cust_main->custnum;
255
256   die "access denied"
257     unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
258
259   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
260   $same = $cgi->param('same');
261   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
262   $ss = $cust_main->ss;           # don't mask an entered value on errors
263   $stateid = $cust_main->stateid; # don't mask an entered value on errors
264   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
265
266   $prospectnum = $cgi->param('prospectnum') || '';
267
268   $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
269
270   $locationnum = $cgi->param('locationnum') || '';
271
272   #svc_acct
273   $username = $cgi->param('username');
274   $password = $cgi->param('_password');
275   $popnum = $cgi->param('popnum');
276   $saved_domsvc = $cgi->param('domsvc') || '';
277   if ( $saved_domsvc =~ /^(\d+)$/ ) {
278     $saved_domsvc = $1;
279   } else {
280     $saved_domsvc = '';
281   }
282
283   #svc_phone
284   $svc_phone{$_} = $cgi->param($_)
285     foreach qw( countrycode phonenum sip_password pin phone_name );
286
287   #svc_dsl (phonenum came in with svc_phone)
288   $svc_phone{$_} = $cgi->param($_)
289     foreach qw( password isp_chg isp_prev vendor_qual_id );
290
291 } elsif ( $cgi->keywords ) { #editing
292
293   die "access denied"
294     unless $curuser->access_right('Edit customer');
295
296   my( $query ) = $cgi->keywords;
297   $query =~ /^(\d+)$/;
298   $custnum=$1;
299   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
300   if ( $cust_main->dbdef_table->column('paycvv')
301        && length($cust_main->paycvv)             ) {
302     my $paycvv = $cust_main->paycvv;
303     $paycvv =~ s/./*/g;
304     $cust_main->paycvv($paycvv);
305   }
306   @invoicing_list = $cust_main->invoicing_list;
307   $ss = $cust_main->masked('ss');
308   $stateid = $cust_main->masked('stateid');
309   $payinfo = $cust_main->paymask;
310
311 } else { #new customer
312
313   die "access denied"
314     unless $curuser->access_right('New customer');
315
316   $custnum='';
317   $cust_main = new FS::cust_main ( {} );
318   $cust_main->otaker( &getotaker );
319   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
320   @invoicing_list = ();
321   push @invoicing_list, 'POST'
322     unless $conf->exists('disablepostalinvoicedefault');
323   $ss = '';
324   $stateid = '';
325   $payinfo = '';
326
327   if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
328     my $qualnum = $1;
329     my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
330       or die "unknown qualnum $qualnum";
331
332     my $prospect_main = $qual->cust_or_prospect;
333     $prospectnum = $prospect_main->prospectnum
334       or die "qualification not on a prospect";
335
336     $cust_main->agentnum( $prospect_main->agentnum );
337     $cust_main->company(  $prospect_main->company  );
338
339     #first contact? -> name
340     my @contacts = $prospect_main->contact;
341     my $contact = $contacts[0];
342     $cust_main->first( $contact->first );
343     $cust_main->set( 'last', $contact->get('last') );
344     #contact phone numbers?
345
346     #location -> address  (all prospect quals have location, right?)
347     my $cust_location = $qual->cust_location;
348     $cust_location->dealternize;
349     $cust_main->$_( $cust_location->$_ )
350       foreach qw( address1 address2 city county state zip country geocode );
351
352     #locationnum -> package order
353     $locationnum = $qual->locationnum;
354
355     #pkgpart handled by lock_pkgpart below
356
357     #service telephone & vendor_qual_id -> svc_dsl
358     $svc_dsl{$_} = $qual->$_
359       foreach qw( phonenum vendor_qual_id );
360   }
361
362   if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
363     my $pkgpart = $1;
364     my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
365       or die "unknown pkgpart $pkgpart";
366     my $svcpart = $part_pkg->svcpart;
367     $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
368   }
369
370 }
371
372 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
373 $cgi->delete( grep !$keep{$_}, $cgi->param );
374
375 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
376 $title .= ": ". $cust_main->name if $custnum;
377
378 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
379
380 </%init>