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');
9 # 'standardize_locations');
11 push @fixups, 'confirm_censustract_bill', 'confirm_censustract_ship'
12 if $conf->exists('cust_main-require_censustract');
14 my $uniqueness = $conf->config('cust_main-check_unique');
15 push @fixups, 'check_unique'
16 if $uniqueness and !$opt{'custnum'};
18 push @fixups, 'do_submit'; # always last
20 var fixups = <% encode_json(\@fixups) %>;
24 <&| /elements/onload.js &>
28 %# state machine to deal with all the asynchronous stuff we're doing
29 %# call this after each fixup on success:
30 function submit_continue() {
32 window[ fixups[fixup_position++] ].call();
37 function submit_abort() {
40 document.CustomerForm.submitButton.disabled = false;
44 function bottomfixup(what) {
46 document.CustomerForm.submitButton.disabled = true;
51 function do_submit() {
52 document.CustomerForm.submit();
55 <& /elements/standardize_locations.js,
56 'callback' => 'submit_continue();',
58 'with_census' => 1, # no with_firm, apparently
61 % # the value in pre+'censustract' is the confirmed censustract (either from
62 % # the previous saved record, or from address standardization (if the backend
63 % # supports it), or from an aborted previous submit. only need to reconfirm
65 function confirm_censustract(pre) {
66 var cf = document.CustomerForm;
67 if ( cf.elements[pre+'censustract'].value == '' ) {
68 var address_info = form_address_info();
69 address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value;
70 address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
71 address_info['prefix'] = pre;
73 '<%$p%>/misc/confirm-censustract.html',
74 'q=' + encodeURIComponent(JSON.stringify(address_info)),
76 if ( OLresponseAJAX ) {
77 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
78 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
79 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
85 } else submit_continue();
87 function confirm_censustract_bill() {
88 confirm_censustract('bill_');
91 function confirm_censustract_ship() {
92 var cf = document.CustomerForm;
93 if ( cf.elements['same'].checked ) {
96 confirm_censustract('ship_');
100 %# called from confirm-censustract.html
101 function set_censustract(tract, year, pre) {
102 var cf = document.CustomerForm;
103 cf.elements[pre + 'censustract'].value = tract;
104 cf.elements[pre + 'censusyear'].value = year;
108 function check_unique() {
109 var search_hash = {};
110 % if ($uniqueness eq 'address') {
111 search_hash['address'] = [
112 document.CustomerForm.elements['bill_address1'].value,
113 document.CustomerForm.elements['ship_address1'].value
116 %# no other options yet
118 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
119 duplicates_form(JSON.stringify(search_hash), confirm_unique);
122 function confirm_unique(arg) {
123 if ( arg.match(/\S/) ) {
124 %# arg contains a complete form to choose an existing customer, or not
125 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
126 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
127 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
128 } else { // no duplicates