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