15c9f45b21f0ef04de0b6c5e0ff4cae501d06b53
[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>
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 %# cust_main/bottomfixup.js
186 % foreach my $hidden (
187 %    'payauto',
188 %    'payinfo', 'payinfo1', 'payinfo2', 'paytype',
189 %    'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
190 %    'paystart_month', 'paystart_year', 'payissue',
191 %    'payip',
192 %    'paid',
193 % ) {
194     <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
195 % } 
196
197 <% include('cust_main/bottomfixup.html') %>
198
199 <BR>
200 <INPUT TYPE    = "button"
201        NAME    = "submitButton"
202        ID      = "submitButton"
203        VALUE   = "<% $custnum ?  "Apply Changes" : "Add Customer" %>"
204        onClick = "this.disabled=true; bottomfixup(this.form);"
205 >
206 </FORM>
207
208 <% include('/elements/footer.html') %>
209
210 <%init>
211
212 my $curuser = $FS::CurrentUser::CurrentUser;
213
214 #probably redundant given the checks below...
215 die "access denied"
216   unless $curuser->access_right('New customer')
217      ||  $curuser->access_right('Edit customer');
218
219 my $conf = new FS::Conf;
220
221 #get record
222
223 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
224 my $same = '';
225 my $pkgpart_svcpart = ''; #first_pkg
226 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
227 my %svc_phone = ();
228
229 if ( $cgi->param('error') ) {
230
231   $cust_main = new FS::cust_main ( {
232     map { $_, scalar($cgi->param($_)) } fields('cust_main')
233   } );
234
235   $custnum = $cust_main->custnum;
236
237   die "access denied"
238     unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
239
240   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
241   $same = $cgi->param('same');
242   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
243   $ss = $cust_main->ss;           # don't mask an entered value on errors
244   $stateid = $cust_main->stateid; # don't mask an entered value on errors
245   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
246
247   $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
248
249   #svc_acct
250   $username = $cgi->param('username');
251   $password = $cgi->param('_password');
252   $popnum = $cgi->param('popnum');
253   $saved_domsvc = $cgi->param('domsvc') || '';
254   if ( $saved_domsvc =~ /^(\d+)$/ ) {
255     $saved_domsvc = $1;
256   } else {
257     $saved_domsvc = '';
258   }
259
260   #svc_phone
261   $svc_phone{$_} = $cgi->param($_)
262     foreach qw( countrycode phonenum sip_password pin phone_name );
263
264 } elsif ( $cgi->keywords ) { #editing
265
266   die "access denied"
267     unless $curuser->access_right('Edit customer');
268
269   my( $query ) = $cgi->keywords;
270   $query =~ /^(\d+)$/;
271   $custnum=$1;
272   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
273   if ( $cust_main->dbdef_table->column('paycvv')
274        && length($cust_main->paycvv)             ) {
275     my $paycvv = $cust_main->paycvv;
276     $paycvv =~ s/./*/g;
277     $cust_main->paycvv($paycvv);
278   }
279   @invoicing_list = $cust_main->invoicing_list;
280   $ss = $cust_main->masked('ss');
281   $stateid = $cust_main->masked('stateid');
282   $payinfo = $cust_main->paymask;
283
284 } else { #new customer
285
286   die "access denied"
287     unless $curuser->access_right('New customer');
288
289   $custnum='';
290   $cust_main = new FS::cust_main ( {} );
291   $cust_main->otaker( &getotaker );
292   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
293   @invoicing_list = ();
294   push @invoicing_list, 'POST'
295     unless $conf->exists('disablepostalinvoicedefault');
296   $ss = '';
297   $stateid = '';
298   $payinfo = '';
299
300 }
301
302 my $error = $cgi->param('error');
303 $cgi->delete_all();
304 $cgi->param('error', $error);
305
306 my $action = $custnum ? 'Edit' : 'Add';
307 $action .= ": ". $cust_main->name if $custnum;
308
309 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
310
311 </%init>