legacy tax exemption report fix, no _date
[freeside.git] / httemplate / edit / cust_main.cgi
1 <% include('/elements/header.html',
2       "Customer $action",
3       '',
4       ' onUnload="myclose()"'
5 ) %>
6
7 <% include('/elements/error.html') %>
8
9 <FORM NAME="topform" STYLE="margin-bottom: 0">
10 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
11
12 % if ( $custnum ) { 
13   Customer #<B><% $custnum %></B> - 
14   <B><FONT COLOR="#<% $cust_main->statuscolor %>">
15     <% ucfirst($cust_main->status) %>
16   </FONT></B>
17   <BR><BR>
18 % } 
19
20 <% &ntable("#cccccc") %>
21
22 %# agent
23 <% include('/elements/tr-select-agent.html', $cust_main->agentnum,
24               'label'         => "<B>${r}Agent</B>",
25               'empty_label'   => 'Select agent',
26               'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
27            )
28 %>
29
30 %# agent_custid
31 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
32
33     <TR>
34       <TD ALIGN="right">Customer identifier</TD>
35       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
36     </TR>
37
38 % } else {
39
40     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
41
42 % }
43
44 %# referral (advertising source)
45 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
46 %if ( $custnum && ! $conf->exists('editreferrals') ) {
47
48   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
49
50 % } else { 
51
52    <% include('/elements/tr-select-part_referral.html', $refnum ) %>
53 % } 
54
55
56 %# referring customer
57 %my $referring_cust_main = '';
58 %if ( $cust_main->referral_custnum
59 %     and $referring_cust_main =
60 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
61 %) {
62
63   <TR>
64     <TD ALIGN="right">Referring customer</TD>
65     <TD>
66       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
67     </TD>
68   </TR>
69   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
70 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
71
72
73   <TR>
74     <TD ALIGN="right">Referring customer</TD>
75     <TD>
76       <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
77       <% include('/elements/search-cust_main.html',
78                     'field_name' => 'referral_custnum',
79                  )
80       %>
81     </TD>
82   </TR>
83 % } else { 
84
85
86   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
87 % } 
88
89
90 </TABLE>
91
92 <!-- birthdate -->
93
94 % if ( $conf->exists('cust_main-enable_birthdate') ) {
95
96   <BR>
97   <% ntable("#cccccc", 2) %>
98   <% include ('/elements/tr-input-date-field.html',
99               'birthdate',
100               $cust_main->birthdate,
101               'Date of Birth',
102               $conf->config('date_format') || "%m/%d/%Y",
103               1)
104   %>
105
106   </TABLE>
107
108 % }
109
110 <!-- contact info -->
111
112 %  my $same_checked = '';
113 %  my $ship_disabled = '';
114 %  unless ( $cust_main->ship_last && $same ne 'Y' ) {
115 %    $same_checked = 'CHECKED';
116 %    $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"';
117 %    foreach (
118 %      qw( last first company address1 address2 city county state zip country
119 %          daytime night fax )
120 %    ) {
121 %      $cust_main->set("ship_$_", $cust_main->get($_) );
122 %    }
123 %  }
124
125 <BR><BR>
126 Billing address
127 <% include('cust_main/contact.html',
128              'cust_main'    => $cust_main,
129              'pre'          => '',
130              'onchange'     => 'bill_changed(this)',
131              'disabled'     => '',
132              'ss'           => $ss,
133              'stateid'      => $stateid,
134              'same_checked' => $same_checked, #for address2 "Unit #" labeling
135           )
136 %>
137
138 <SCRIPT>
139 function bill_changed(what) {
140   if ( what.form.same.checked ) {
141 % for (qw( last first company address1 address2 city zip daytime night fax )) { 
142
143     what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
144 % } 
145
146     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
147
148     function fix_ship_county() {
149       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
150     }
151
152     function fix_ship_state() {
153       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
154       ship_state_changed(what.form.ship_state, fix_ship_county );
155     }
156
157     ship_country_changed(what.form.ship_country, fix_ship_state );
158
159   }
160 }
161 function samechanged(what) {
162   if ( what.checked ) {
163     bill_changed(what);
164
165 %   for (qw( last first company address1 address2 city county state zip country daytime night fax )) { 
166       what.form.ship_<%$_%>.disabled = true;
167       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
168 %   } 
169
170 %   if ( $conf->exists('cust_main-require_address2') ) {
171       document.getElementById('address2_required').style.visibility = '';
172       document.getElementById('address2_label').style.visibility = '';
173       document.getElementById('ship_address2_required').style.visibility = 'hidden';
174       document.getElementById('ship_address2_label').style.visibility = 'hidden';
175 %   }
176
177   } else {
178
179 %   for (qw( last first company address1 address2 city county state zip country daytime night fax )) { 
180       what.form.ship_<%$_%>.disabled = false;
181       what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
182 %   } 
183
184 %   if ( $conf->exists('cust_main-require_address2') ) {
185       document.getElementById('address2_required').style.visibility = 'hidden';
186       document.getElementById('address2_label').style.visibility = 'hidden';
187       document.getElementById('ship_address2_required').style.visibility = '';
188       document.getElementById('ship_address2_label').style.visibility = '';
189 %   }
190
191   }
192 }
193 </SCRIPT>
194
195 <BR>
196 Service address 
197 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
198 <% include('cust_main/contact.html',
199              'cust_main' => $cust_main,
200              'pre'       => 'ship_',
201              'onchange'  => '',
202              'disabled'  => $ship_disabled,
203           )
204 %>
205
206
207 <!-- billing info -->
208
209 <% include( 'cust_main/billing.html', $cust_main,
210                'payinfo'        => $payinfo,
211                'invoicing_list' => \@invoicing_list,
212            )
213 %>
214
215 <SCRIPT>
216 function bottomfixup(what) {
217
218   var topvars = new Array(
219     'birthdate',
220
221     'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
222
223     'last', 'first', 'ss', 'company',
224     'address1', 'address2', 'city',
225     'county', 'state', 'zip', 'country',
226     'daytime', 'night', 'fax',
227     'stateid', 'stateid_state',
228
229     'same',
230
231     'ship_last', 'ship_first', 'ship_company',
232     'ship_address1', 'ship_address2', 'ship_city',
233     'ship_county', 'ship_state', 'ship_zip', 'ship_country',
234     'ship_daytime','ship_night', 'ship_fax',
235
236     'select' // XXX key
237   );
238
239   var layervars = new Array(
240     'payauto',
241     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
242     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
243     'paystart_month', 'paystart_year', 'payissue',
244     'payip',
245     'paid'
246   );
247
248   var billing_bottomvars = new Array(
249     'tax',
250     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
251     'spool_cdr'
252   );
253
254   for ( f=0; f < topvars.length; f++ ) {
255     var field = topvars[f];
256     copyelement( document.topform.elements[field],
257                  document.bottomform.elements[field]
258                );
259   }
260
261   var layerform = document.topform.select.options[document.topform.select.selectedIndex].value;
262   for ( f=0; f < layervars.length; f++ ) {
263     var field = layervars[f];
264     copyelement( document.forms[layerform].elements[field],
265                  document.bottomform.elements[field]
266                );
267   }
268
269   for ( f=0; f < billing_bottomvars.length; f++ ) {
270     var field = billing_bottomvars[f];
271     copyelement( document.billing_bottomform.elements[field],
272                  document.bottomform.elements[field]
273                );
274   }
275
276 }
277
278 function copyelement(from, to) {
279   if ( from == undefined ) {
280     to.value = '';
281   } else if ( from.type == 'select-one' ) {
282     to.value = from.options[from.selectedIndex].value;
283     //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
284   } else if ( from.type == 'checkbox' ) {
285     if ( from.checked ) {
286       to.value = from.value;
287     } else {
288       to.value = '';
289     }
290   } else {
291     if ( from.value == undefined ) {
292       to.value = '';
293     } else {
294       to.value = from.value;
295     }
296   }
297   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
298 }
299
300 </SCRIPT>
301
302 <FORM ACTION="<% popurl(1) %>process/cust_main.cgi" METHOD=POST NAME="bottomform" onSubmit="document.bottomform.submit.disabled=true; bottomfixup(this.form);" STYLE="margin-top: 0; margin-bottom: 0">
303 % foreach my $hidden (
304 %     'birthdate',
305 %
306 %     'custnum', 'agentnum', 'agent_custid', 'refnum', 'referral_custnum',
307 %     'last', 'first', 'ss', 'company',
308 %     'address1', 'address2', 'city',
309 %     'county', 'state', 'zip', 'country',
310 %     'daytime', 'night', 'fax',
311 %     'stateid', 'stateid_state',
312 %     
313 %     'same',
314 %     
315 %     'ship_last', 'ship_first', 'ship_company',
316 %     'ship_address1', 'ship_address2', 'ship_city',
317 %     'ship_county', 'ship_state', 'ship_zip', 'ship_country',
318 %     'ship_daytime','ship_night', 'ship_fax',
319 %     
320 %     'select', #XXX key
321 %
322 %     'payauto',
323 %     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
324 %     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
325 %     'paystart_month', 'paystart_year', 'payissue',
326 %     'payip',
327 %     'paid',
328 %     
329 %     'tax',
330 %     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
331 %     'spool_cdr'
332 %   ) {
333 %
334
335   <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
336 % } 
337 %
338 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
339 % if (!$ro_comments || $cust_main->comments) {
340
341 <BR>Comments
342 <% &ntable("#cccccc") %>
343   <TR>
344     <TD>
345       <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
346     </TD>
347   </TR>
348 </TABLE>
349 %
350 % }
351 %
352 %unless ( $custnum ) {
353 %  # pry the wrong place for this logic.  also pretty expensive
354 %  #use FS::part_pkg;
355 %
356 %  #false laziness, copied from FS::cust_pkg::order
357 %  my $pkgpart;
358 %  my @agents = $FS::CurrentUser::CurrentUser->agents;
359 %  if ( scalar(@agents) == 1 ) {
360 %    # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
361 %    $pkgpart = $agents[0]->pkgpart_hashref;
362 %  } else {
363 %    #can't know (agent not chosen), so, allow all
364 %    my %typenum;
365 %    foreach my $agent ( @agents ) {
366 %      next if $typenum{$agent->typenum}++;
367 %      #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
368 %      foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
369 %    }
370 %  }
371 %  #eslaf
372 %
373 %  my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
374 %    qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
375 %
376 %  if ( @part_pkg ) {
377 %
378 %    #    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
379 %    #apiabuse & undesirable wrapping
380 %
381 %    
382
383     <BR>First package
384     <% ntable("#cccccc") %>
385     
386       <TR>
387         <TD COLSPAN=2>
388           <% include('cust_main/select-domain.html',
389                        'pkgparts'      => \@part_pkg,
390                        'saved_pkgpart' => $saved_pkgpart,
391                        'saved_domsvc' => $saved_domsvc,
392                     )
393           %>
394         </TD>
395       </TR>
396
397 %        #false laziness: (mostly) copied from edit/svc_acct.cgi
398 %        #$ulen = $svc_acct->dbdef_table->column('username')->length;
399 %        my $ulen = dbdef->table('svc_acct')->column('username')->length;
400 %        my $ulen2 = $ulen+2;
401 %        my $passwordmax = $conf->config('passwordmax') || 8;
402 %        my $pmax2 = $passwordmax + 2;
403 %      
404
405     
406       <TR>
407         <TD ALIGN="right">Username</TD>
408         <TD>
409           <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
410         </TD>
411       </TR>
412     
413       <TR>
414         <TD ALIGN="right">Domain</TD>
415         <TD>
416           <SELECT NAME="domsvc">
417             <OPTION>(none)</OPTION>
418           </SELECT>
419         </TD>
420       </TR>
421     
422       <TR>
423         <TD ALIGN="right">Password</TD>
424         <TD>
425           <INPUT TYPE="text" NAME="_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $passwordmax %>>
426           (blank to generate)
427         </TD>
428       </TR>
429     
430       <TR>
431         <TD ALIGN="right">Access number</TD>
432         <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
433       </TR>
434     </TABLE>
435 % } 
436 % } 
437
438
439 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
440 <BR>
441 <INPUT TYPE="submit" NAME="submit" VALUE="<% $custnum ?  "Apply Changes" : "Add Customer" %>">
442 <BR>
443 </FORM>
444
445 <% include('/elements/footer.html') %>
446
447 <%init>
448
449 die "access denied"
450   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
451
452 #for misplaced logic below
453 #use FS::part_pkg;
454
455 #for false laziness below (now more properly lazy)
456 #use FS::svc_acct_pop;
457
458 #for (other) false laziness below
459 #use FS::agent;
460 #use FS::type_pkgs;
461
462 my $conf = new FS::Conf;
463
464 #get record
465
466 my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
467 my(@invoicing_list);
468 my ($ss,$stateid,$payinfo);
469 my $same = '';
470 if ( $cgi->param('error') ) {
471   $cust_main = new FS::cust_main ( {
472     map { $_, scalar($cgi->param($_)) } fields('cust_main')
473   } );
474   $custnum = $cust_main->custnum;
475   $saved_domsvc = $cgi->param('domsvc') || '';
476   if ( $saved_domsvc =~ /^(\d+)$/ ) {
477     $saved_domsvc = $1;
478   } else {
479     $saved_domsvc = '';
480   }
481   $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
482   if ( $saved_pkgpart =~ /^(\d+)_/ ) {
483     $saved_pkgpart = $1;
484   } else {
485     $saved_pkgpart = '';
486   }
487   $username = $cgi->param('username');
488   $password = $cgi->param('_password');
489   $popnum = $cgi->param('popnum');
490   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
491   $same = $cgi->param('same');
492   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
493   $ss = $cust_main->ss;           # don't mask an entered value on errors
494   $stateid = $cust_main->stateid; # don't mask an entered value on errors
495   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
496 } elsif ( $cgi->keywords ) { #editing
497   my( $query ) = $cgi->keywords;
498   $query =~ /^(\d+)$/;
499   $custnum=$1;
500   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
501   if ( $cust_main->dbdef_table->column('paycvv')
502        && length($cust_main->paycvv)             ) {
503     my $paycvv = $cust_main->paycvv;
504     $paycvv =~ s/./*/g;
505     $cust_main->paycvv($paycvv);
506   }
507   $saved_pkgpart = 0;
508   $saved_domsvc = 0;
509   $username = '';
510   $password = '';
511   $popnum = 0;
512   @invoicing_list = $cust_main->invoicing_list;
513   $ss = $cust_main->masked('ss');
514   $stateid = $cust_main->masked('stateid');
515   $payinfo = $cust_main->paymask;
516 } else {
517   $custnum='';
518   $cust_main = new FS::cust_main ( {} );
519   $cust_main->otaker( &getotaker );
520   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
521   $saved_pkgpart = 0;
522   $saved_domsvc = 0;
523   $username = '';
524   $password = '';
525   $popnum = 0;
526   @invoicing_list = ();
527   push @invoicing_list, 'POST'
528     unless $conf->exists('disablepostalinvoicedefault');
529   $ss = '';
530   $stateid = '';
531   $payinfo = '';
532 }
533
534 my $error = $cgi->param('error');
535 $cgi->delete_all();
536 $cgi->param('error', $error);
537
538 my $action = $custnum ? 'Edit' : 'Add';
539 $action .= ": ". $cust_main->name if $custnum;
540
541 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
542
543 </%init>