2 my %opt = @_; # custnum
3 my $conf = new FS::Conf;
5 my $company_latitude = $conf->config('company_latitude');
6 my $company_longitude = $conf->config('company_longitude');
8 my @fixups = ('standardize_locations');
10 push @fixups, 'wa_state_tax_district'
11 if $conf->exists('tax_district_method');
13 push @fixups, 'confirm_censustract_bill', 'confirm_censustract_ship'
14 if $conf->exists('cust_main-require_censustract');
16 my $uniqueness = $conf->config('cust_main-check_unique');
17 push @fixups, 'check_unique'
18 if $uniqueness and !$opt{'custnum'};
20 push @fixups, 'do_submit'; # always last
22 var fixups = <% encode_json(\@fixups) %>;
26 <&| /elements/onload.js &>
30 %# state machine to deal with all the asynchronous stuff we're doing
31 %# call this after each fixup on success:
32 function submit_continue() {
34 window[ fixups[fixup_position++] ].call();
39 function submit_abort() {
42 document.CustomerForm.submitButton.disabled = false;
46 function bottomfixup(what) {
48 document.CustomerForm.submitButton.disabled = true;
53 function do_submit() {
54 document.CustomerForm.submit();
57 <& /elements/standardize_locations.js,
58 'callback' => 'submit_continue();',
60 'with_census' => 1, # no with_firm, apparently
63 <& /elements/wa_state_tax_district.js &>
65 % # the value in pre+'censustract' is the confirmed censustract (either from
66 % # the previous saved record, or from address standardization (if the backend
67 % # supports it), or from an aborted previous submit. only need to reconfirm
69 function confirm_censustract(pre) {
70 var cf = document.CustomerForm;
71 if ( cf.elements[pre+'censustract'].value == '' ) {
72 var address_info = form_address_info();
73 address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value;
74 address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
75 address_info['prefix'] = pre;
77 '<%$p%>/misc/confirm-censustract.html',
78 'q=' + encodeURIComponent(JSON.stringify(address_info)),
80 if ( OLresponseAJAX ) {
81 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
82 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
83 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
89 } else submit_continue();
91 function confirm_censustract_bill() {
92 confirm_censustract('bill_');
95 function confirm_censustract_ship() {
96 var cf = document.CustomerForm;
97 if ( cf.elements['same'].checked ) {
100 confirm_censustract('ship_');
104 %# called from confirm-censustract.html
105 function set_censustract(tract, year, pre) {
106 var cf = document.CustomerForm;
107 cf.elements[pre + 'censustract'].value = tract;
108 cf.elements[pre + 'censusyear'].value = year;
112 function check_unique() {
113 var search_hash = {};
114 % if ($uniqueness eq 'address') {
115 search_hash['address'] = [
116 document.CustomerForm.elements['bill_address1'].value,
117 document.CustomerForm.elements['ship_address1'].value
120 %# no other options yet
122 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
123 duplicates_form(JSON.stringify(search_hash), confirm_unique);
126 function confirm_unique(arg) {
127 if ( arg.match(/\S/) ) {
128 %# arg contains a complete form to choose an existing customer, or not
129 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
130 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
131 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
132 } else { // no duplicates