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