summaryrefslogtreecommitdiff
path: root/httemplate/view/cust_main/locations.html
blob: 0a2e5ec2c72c351e9dd7f374ccba3013418f9b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<STYLE>
div.loclabel {
  display: inline-block;
  padding-left: 4px; 
  padding-right: 4px; 
  background-color: #cccccc;
  border: 1px solid black;
  border-bottom: 0px;
  border-radius: 4px 4px 0 0; 
}
div.disabled {
  font-style: italic;
  color: #808080;
}
table.location {
  width: 100%;
  padding: 1px;
  border-spacing: 0px;
}
.location-head th {
  padding-bottom: 0px; 
  padding-left: 0px; 
  border-bottom: 1px solid black;
  vertical-align: bottom;
  text-align: left;
  width: 100%;
}
</STYLE>
% foreach my $locationnum (@sorted) {
%   my $packages = $packages_in{$locationnum};
%   my $loc = $locations{$locationnum};
%   next if $loc->disabled and scalar(@$packages) == 0;
<TABLE CLASS="grid location">
<TR CLASS="location-head">
<TH COLSPAN=5>
<DIV CLASS="<% $loc->disabled ? 'loclabel disabled' : 'loclabel' %>">
<% $loc->location_label %>
%   if ( $loc->country eq 'US' ) { # only U.S. census tracts for now
%     if ( $loc->censustract ) {
          <BR>
          <FONT SIZE=-1>
          <% $loc->censustract %> (<% $loc->censusyear %> census)
          </FONT>
%     } elsif ( $conf->exists('cust_main-require_censustract') ) {
          <BR>
          <FONT SIZE=-1 COLOR="#ee3300">
          <% emt('Census tract unknown') %>
          </FONT>
%     }
%   }
</DIV>
<DIV STYLE="display: inline; float:right;">
% if ( $locationnum && !$loc->disabled && ! $opt{no_links} ) {
<% edit_location_link($locationnum) %>
% }
% if ( $locationnum && !$loc->disabled && !$active{$locationnum} && ! $opt{no_links} ) {
&nbsp;<% disable_location_link($locationnum) %>
% }
</DIV></TH></TR>
%   if (@$packages) {
%     my %sopt = %opt;
%     $sopt{'packages'} = $packages;
      <& packages/section.html, %sopt &>
%   }
</TABLE><BR>
% } #foreach $locationnum
<%init>
my %opt = @_;
my $cust_main = $opt{'cust_main'};
my $all_packages = $opt{'packages'};
my $conf = FS::Conf->new;

my %locations = map { $_->locationnum => $_ } qsearch({
    'table'     => 'cust_location',
    'hashref'   => { 'custnum' => $cust_main->custnum },
    'order_by'  => 'ORDER BY country, state, city, address1, locationnum',
  });
my @sections = keys %locations;
my %packages_in = map { $_ => [] } (@sections);

my %active = (); # groups with non-canceled packages
foreach my $cust_pkg ( @$all_packages ) {
  my $key = $cust_pkg->locationnum;
  push @{ $packages_in{$key} }, $cust_pkg;
  $active{$key} = 1 if !$cust_pkg->getfield('cancel');
}
# prevent disabling these
$active{$cust_main->ship_locationnum} = 1;
$active{$cust_main->bill_locationnum} = 1;

my @sorted = (
  $cust_main->ship_locationnum,
  grep ( { $active{$_} && $_ != $cust_main->ship_locationnum } @sections),
  grep ( { !$active{$_} } @sections),
);

sub edit_location_link {
  my $locationnum = shift;
  include( '/elements/popup_link.html',
    'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
    'label'       => '('.emt('Edit location').')',
    'actionlabel' => emt('Edit'),
  );
}

sub disable_location_link {
  my $locationnum = shift;
  include( '/elements/popup_link.html',
    'action'      => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum",
    'label'       => '('.emt('Disable location').')',
    'actionlabel' => emt('Disable'),
  );
}

</%init>