RT# 79284 Updated discounts UI for Change Package screen
[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 = ( map { $_ => $location->$_ }
8 %                   qw ( zip city state geocode )
9 %               );
10 %   map { $value{$_} = $location{$_} } qw ( city state )
11 %     if $location{country} eq 'CA';
12 %
13 %   my $value = encode_entities(encode_json({ %value })
14 %                              );
15 %   my $content = '';
16 %   $content .= $location->$_. '&nbsp;' x ( $max{$_} - length($location->$_) )
17 %     foreach qw( city county state );
18 %   $content .=   $location->cityflag eq 'I' ? 'Y' : 'N' ;
19 %   my $selected = '' ;
20 %   if ($geocode && $location->geocode eq $geocode) {
21 %     $selected = 'SELECTED';
22 %   }
23   <OPTION VALUE="<% $value %>" STYLE="<% $style %>" <% $selected %>><% $content %>
24 % }
25 </SELECT><BR><BR>
26
27 <TABLE><TR>
28   <TD> <BUTTON TYPE="button" onClick="set_geocode(document.getElementById('geocodes'));"><IMG SRC="<%$p%>images/tick.png" ALT=""> Set location </BUTTON></TD>
29   <TD><BUTTON TYPE="button" onClick="document.<% $formname %>.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission </BUTTON></TD>
30 </TR>
31 </TABLE>
32
33 </CENTER>
34 </FORM>
35 <%init>
36
37 my $conf = new FS::Conf;
38 my $tax_engine = FS::TaxEngine->new;
39
40 my %location;
41 ($location{data_vendor}) = $conf->config('tax_data_vendor');
42 ($location{city})        = $cgi->param('city')        =~ /^([\w ]+)$/;
43 ($location{state})       = $cgi->param('state')       =~ /^(\w+)$/;
44 ($location{zip})         = $cgi->param('zip')         =~ /^([-\w ]+)$/;
45 ($location{country})     = $cgi->param('country')     =~ /^([\w ]+)$/;
46
47 my($geocode)             = $cgi->param('geocode')     =~ /^([\w]+)$/;
48
49 my($formname)            = $cgi->param('formname')    =~ /^([\w]*)$/;
50 $formname ||= 'CustomerForm';
51
52 my @cust_tax_location = $tax_engine->cust_tax_locations(\%location);
53
54 my %max = ( city => 4, county => 6, state => 5);
55 foreach my $location (@cust_tax_location) {
56   foreach ( qw( city county state ) ) {
57     my $length = length($location->$_);
58     $max{$_} = ($length > $max{$_}) ? $length : $max{$_};
59   }
60 }
61 foreach ( qw( city county state ) ) {
62   $max{$_} = $location{$_} if $location{$_} > $max{$_};
63   $max{$_}++;
64 }
65
66 my $header = '&nbsp;&nbsp;';
67 $header .= $_. '&nbsp;' x ( $max{lc($_)} - length($_) )
68   foreach qw( City County State );
69 $header .=   "In city?";
70
71 my $style = "font-family:monospace;";
72
73 </%init>