fdbbc396bd8a04956f6e79e65d8a54e5da14bdba
[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->censustract ) {
39         <BR>
40         <FONT SIZE=-1>
41         <% $loc->censustract %> (<% $loc->censusyear %> census)
42         </FONT>
43 %   } elsif ( $conf->exists('cust_main-require_censustract') ) {
44         <BR>
45         <FONT SIZE=-1 COLOR="#ee3300">
46         <% emt('Census tract unknown') %>
47         </FONT>
48 %   }
49 </DIV>
50 <DIV STYLE="display: inline; float:right;">
51 % if ( $locationnum && !$loc->disabled && ! $opt{no_links} ) {
52 <% edit_location_link($locationnum) %>
53 % }
54 % if ( $locationnum && !$loc->disabled && !$active{$locationnum} && ! $opt{no_links} ) {
55 &nbsp;<% disable_location_link($locationnum) %>
56 % }
57 </DIV></TH></TR>
58 %   if (@$packages) {
59       <& packages/section.html,
60            'packages'  => $packages,
61            'cust_main' => $cust_main,
62            'no_links'  => $opt{no_links}
63       &>
64 %   }
65 </TABLE><BR>
66 % } #foreach $locationnum
67 <%init>
68 my %opt = @_;
69 my $cust_main = $opt{'cust_main'};
70 my $all_packages = $opt{'packages'};
71 my $conf = FS::Conf->new;
72
73 my %locations = map { $_->locationnum => $_ } qsearch({
74     'table'     => 'cust_location',
75     'hashref'   => { 'custnum' => $cust_main->custnum },
76     'order_by'  => 'ORDER BY country, state, city, address1, locationnum',
77   });
78 my @sections = keys %locations;
79 my %packages_in = map { $_ => [] } (@sections);
80
81 my %active = (); # groups with non-canceled packages
82 foreach my $cust_pkg ( @$all_packages ) {
83   my $key = $cust_pkg->locationnum;
84   push @{ $packages_in{$key} }, $cust_pkg;
85   $active{$key} = 1 if !$cust_pkg->getfield('cancel');
86 }
87 # prevent disabling these
88 $active{$cust_main->ship_locationnum} = 1;
89 $active{$cust_main->bill_locationnum} = 1;
90
91 my @sorted = (
92   $cust_main->ship_locationnum,
93   grep ( { $active{$_} && $_ != $cust_main->ship_locationnum } @sections),
94   grep ( { !$active{$_} } @sections),
95 );
96
97 sub edit_location_link {
98   my $locationnum = shift;
99   include( '/elements/popup_link.html',
100     'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
101     'label'       => '('.emt('Edit location').')',
102     'actionlabel' => emt('Edit'),
103   );
104 }
105
106 sub disable_location_link {
107   my $locationnum = shift;
108   include( '/elements/popup_link.html',
109     'action'      => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum",
110     'label'       => '('.emt('Disable location').')',
111     'actionlabel' => emt('Disable'),
112   );
113 }
114
115 </%init>