don't look up or display census tracts for non-U.S. addresses, #32249
[freeside.git] / httemplate / view / cust_main / locations.html
1 <STYLE>
2 div.loclabel {
3   display: inline-block;
4   padding-left: 4px; 
5   padding-right: 4px; 
6   background-color: #cccccc;
7   border: 1px solid black;
8   border-bottom: 0px;
9   border-radius: 4px 4px 0 0; 
10 }
11 div.disabled {
12   font-style: italic;
13   color: #808080;
14 }
15 table.location {
16   width: 100%;
17   padding: 1px;
18   border-spacing: 0px;
19 }
20 .location-head th {
21   padding-bottom: 0px; 
22   padding-left: 0px; 
23   border-bottom: 1px solid black;
24   vertical-align: bottom;
25   text-align: left;
26   width: 100%;
27 }
28 </STYLE>
29 % foreach my $locationnum (@sorted) {
30 %   my $packages = $packages_in{$locationnum};
31 %   my $loc = $locations{$locationnum};
32 %   next if $loc->disabled and scalar(@$packages) == 0;
33 <TABLE CLASS="grid location">
34 <TR CLASS="location-head">
35 <TH COLSPAN=5>
36 <DIV CLASS="<% $loc->disabled ? 'loclabel disabled' : 'loclabel' %>">
37 <% $loc->location_label %>
38 %   if ( $loc->country eq 'US' ) { # only U.S. census tracts for now
39 %     if ( $loc->censustract ) {
40           <BR>
41           <FONT SIZE=-1>
42           <% $loc->censustract %> (<% $loc->censusyear %> census)
43           </FONT>
44 %     } elsif ( $conf->exists('cust_main-require_censustract') ) {
45           <BR>
46           <FONT SIZE=-1 COLOR="#ee3300">
47           <% emt('Census tract unknown') %>
48           </FONT>
49 %     }
50 %   }
51 </DIV>
52 <DIV STYLE="display: inline; float:right;">
53 % if ( $locationnum && !$loc->disabled && ! $opt{no_links} ) {
54 <% edit_location_link($locationnum) %>
55 % }
56 % if ( $locationnum && !$loc->disabled && !$active{$locationnum} && ! $opt{no_links} ) {
57 &nbsp;<% disable_location_link($locationnum) %>
58 % }
59 </DIV></TH></TR>
60 %   if (@$packages) {
61       <& packages/section.html,
62            'packages'  => $packages,
63            'cust_main' => $cust_main,
64            'no_links'  => $opt{no_links}
65       &>
66 %   }
67 </TABLE><BR>
68 % } #foreach $locationnum
69 <%init>
70 my %opt = @_;
71 my $cust_main = $opt{'cust_main'};
72 my $all_packages = $opt{'packages'};
73 my $conf = FS::Conf->new;
74
75 my %locations = map { $_->locationnum => $_ } qsearch({
76     'table'     => 'cust_location',
77     'hashref'   => { 'custnum' => $cust_main->custnum },
78     'order_by'  => 'ORDER BY country, state, city, address1, locationnum',
79   });
80 my @sections = keys %locations;
81 my %packages_in = map { $_ => [] } (@sections);
82
83 my %active = (); # groups with non-canceled packages
84 foreach my $cust_pkg ( @$all_packages ) {
85   my $key = $cust_pkg->locationnum;
86   push @{ $packages_in{$key} }, $cust_pkg;
87   $active{$key} = 1 if !$cust_pkg->getfield('cancel');
88 }
89 # prevent disabling these
90 $active{$cust_main->ship_locationnum} = 1;
91 $active{$cust_main->bill_locationnum} = 1;
92
93 my @sorted = (
94   $cust_main->ship_locationnum,
95   grep ( { $active{$_} && $_ != $cust_main->ship_locationnum } @sections),
96   grep ( { !$active{$_} } @sections),
97 );
98
99 sub edit_location_link {
100   my $locationnum = shift;
101   include( '/elements/popup_link.html',
102     'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
103     'label'       => '('.emt('Edit location').')',
104     'actionlabel' => emt('Edit'),
105   );
106 }
107
108 sub disable_location_link {
109   my $locationnum = shift;
110   include( '/elements/popup_link.html',
111     'action'      => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum",
112     'label'       => '('.emt('Disable location').')',
113     'actionlabel' => emt('Disable'),
114   );
115 }
116
117 </%init>