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