merge NG auth, RT#21563
[freeside.git] / httemplate / misc / 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 = ( zip => $zip5,
8 %                 map { $_ => $location->$_ }
9 %                   qw ( city state geocode )
10 %               );
11 %   map { $value{$_} = $location{$_} } qw ( city state )
12 %     if $location{country} eq 'CA';
13 %
14 %   my $value = encode_entities(encode_json({ %value })
15 %                              );
16 %   my $content = '';
17 %   $content .= $location->$_. '&nbsp;' x ( $max{$_} - length($location->$_) )
18 %     foreach qw( city county state );
19 %   $content .=   $location->cityflag eq 'I' ? 'Y' : 'N' ;
20 %   my $selected = '' ;
21 %   if ($geocode && $location->geocode eq $geocode) {
22 %     $selected = 'SELECTED';
23 %   }
24   <OPTION VALUE="<% $value %>" STYLE="<% $style %>" <% $selected %>><% $content %>
25 % }
26 </SELECT><BR><BR>
27
28 <TABLE><TR>
29   <TD> <BUTTON TYPE="button" onClick="set_geocode(document.getElementById('geocodes'));"><IMG SRC="<%$p%>images/tick.png" ALT=""> Set location </BUTTON></TD>
30   <TD><BUTTON TYPE="button" onClick="document.<% $formname %>.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission </BUTTON></TD>
31 </TR>
32 </TABLE>
33
34 </CENTER>
35 </FORM>
36 <%init>
37
38 my $conf = new FS::Conf;
39
40 my %location = ();
41
42 ($location{data_vendor}) = $cgi->param('data_vendor') =~ /^([-\w]+)$/;
43 ($location{city})        = $cgi->param('city')        =~ /^([\w ]+)$/;
44 ($location{state})       = $cgi->param('state')       =~ /^(\w+)$/;
45 ($location{zip})         = $cgi->param('zip')         =~ /^([-\w ]+)$/;
46 ($location{country})     = $cgi->param('country')     =~ /^([\w ]+)$/;
47
48 my($geocode)             = $cgi->param('geocode')     =~ /^([\w]+)$/;
49
50 my($formname)            = $cgi->param('formname')    =~ /^([\w]*)$/;
51 $formname ||= 'CustomerForm';
52
53 my($zip5, $zip4) = split('-', $location{zip});
54
55 #only support US & CA
56 my $hashref = { 'data_vendor' => $location{data_vendor} };
57 $hashref->{zip} = $location{country} eq 'CA' ? substr($zip5,0,1) : $zip5,
58
59 my @keys = keys(%$hashref);
60 my @cust_tax_location = ();
61 until ( @cust_tax_location ) {
62   @cust_tax_location = qsearch({ table    => 'cust_tax_location',
63                                  hashref  =>  $hashref,
64                                  order_by =>  'LIMIT 50',
65                               });
66   last unless scalar(@keys);
67   delete $hashref->{ shift @keys };
68
69
70 my %max = ( city => 4, county => 6, state => 5);
71 foreach my $location (@cust_tax_location) {
72   foreach ( qw( city county state ) ) {
73     my $length = length($location->$_);
74     $max{$_} = ($length > $max{$_}) ? $length : $max{$_};
75   }
76 }
77 foreach ( qw( city county state ) ) {
78   $max{$_} = $location{$_} if $location{$_} > $max{$_};
79   $max{$_}++;
80 }
81
82 my $header = '&nbsp;&nbsp;';
83 $header .= $_. '&nbsp;' x ( $max{lc($_)} - length($_) )
84   foreach qw( City County State );
85 $header .=   "In city?";
86
87 my $style = "font-family:monospace;";
88
89 </%init>