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