invoice_sections_with_taxes per-agent, RT#79636
[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 %     my %sopt = %opt;
62 %     $sopt{'packages'} = $packages;
63       <& packages/section.html, %sopt &>
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>