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