support zip5 tax lookups, correct errors with fixed format cch import, inital import...
[freeside.git] / httemplate / edit / cust_main / choose_tax_location.html
1 <FORM NAME="choosegeocodeform">
2 <CENTER><BR><B>Choose tax location</B><BR><BR>
3 <P STYLE="<% $style %>"><% $header %></P>
4
5 <SELECT NAME='geocodes' ID='geocodes' STYLE="<% $style %>">
6 % foreach my $location (@cust_tax_location) {
7 %   my $value = encode_entities(objToJson({ zip => $zip5,
8 %                                           map { $_ => $location->$_ }
9 %                                             qw ( city state geocode )
10 %                                        })
11 %                              );
12 %   my $content = '';
13 %   $content .= $location->$_. '&nbsp;' x ( $max{$_} - length($location->$_) )
14 %     foreach qw( city county state );
15 %   $content .=   $location->cityflag eq 'I' ? 'Y' : 'N' ;
16 %   my $selected = '' ;
17 %   if (!$have_selected && lc($location->city) eq lc($city)) {
18 %     $selected = 'SELECTED';
19 %   }
20   <OPTION VALUE="<% $value %>" STYLE="<% $style %>" <% $selected %>><% $content %>
21 % }
22 </SELECT><BR><BR>
23
24 <TABLE><TR>
25   <TD> <BUTTON TYPE="button" onClick="set_geocode(document.getElementById('geocodes')); document.bottomform.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Set location </BUTTON></TD>
26   <TD><BUTTON TYPE="button" onClick="document.bottomform.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission </BUTTON></TD>
27 </TR>
28 </TABLE>
29
30 </CENTER>
31 </FORM>
32 <%init>
33
34 my $conf = new FS::Conf;
35 my $have_selected = 0;
36
37 my ($data_vendor) = $cgi->param('data_vendor') =~ /^([-\w]+)$/;
38 my ($city)  = $cgi->param('city')  =~ /^([\w ]+)$/;
39 my ($state) = $cgi->param('state') =~ /^(\w+)$/;
40 my ($zip)   = $cgi->param('zip')   =~ /^([-\w]+)$/;
41
42 my($zip5, $zip4) = split('-', $zip);
43
44 my $hashref = { data_vendor => $data_vendor,
45                 #city        => $city,
46                 #state       => $state,
47                 zip         => $zip5,
48               };
49 #my @keys = qw ( city state zip );
50 my @keys = qw ( zip );
51 my @cust_tax_location = ();
52 until ( @cust_tax_location ) {
53   @cust_tax_location = qsearch( 'cust_tax_location', $hashref );
54   last unless scalar(@keys);
55   delete $hashref->{ shift @keys };
56
57
58 my %max = ( city => 4, county => 6, state => 5);
59 foreach my $location (@cust_tax_location) {
60   foreach ( qw( city county state ) ) {
61     my $length = length($location->$_);
62     $max{$_} = ($length > $max{$_}) ? $length : $max{$_};
63   }
64 }
65 $max{$_}++ foreach qw( city county state );
66
67 my $header = '&nbsp;&nbsp;';
68 $header .= $_. '&nbsp;' x ( $max{lc($_)} - length($_) )
69   foreach qw( City County State );
70 $header .=   "In city?";
71
72 my $style = "font-family:monospace;";
73
74 </%init>