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