7eb52ca463a8cb518ad335aa2c26c1db97ea6bd2
[freeside.git] / httemplate / view / cust_main / locations.html
1 <STYLE>
2 span.loclabel {
3   padding-left: 4px; 
4   padding-right: 4px; 
5   background-color: #cccccc;
6   border: 1px solid black
7 }
8 table.location {
9   width: 100%;
10   padding: 1px;
11   border-spacing: 0px;
12 }
13 </STYLE>
14 % foreach my $locationnum (@sorted) {
15 %   my $packages = $packages_in{$locationnum};
16 %   my $loc = $locations{$locationnum};
17 %   next if $loc->disabled and scalar(@$packages) == 0;
18 <TABLE CLASS="grid location">
19 <TR><TH COLSPAN=3 ALIGN="left" VALIGN="bottom" 
20 STYLE="padding-bottom: 0px; 
21   padding-left: 0px; 
22   border-bottom-style: solid;
23   border-bottom-color: black;
24   border-bottom-width: 1px;">
25 <SPAN CLASS="loclabel">
26 %   if ( $loc->disabled ) {
27 <FONT COLOR="#808080"><I>
28 %   }
29 <% $loc->location_label %></SPAN>
30 <SPAN STYLE="float:right;">
31 % if ( $locationnum && !$loc->disabled && ! $opt{no_links} ) {
32 <% edit_location_link($locationnum) %>
33 % }
34 % if ( $locationnum && !$loc->disabled && !$active{$locationnum} && ! $opt{no_links} ) {
35 &nbsp;<% disable_location_link($locationnum) %>
36 % }
37 </SPAN></TH></TR>
38 %   if (@$packages) {
39       <& packages/section.html,
40            'packages'  => $packages,
41            'cust_main' => $cust_main,
42            'no_links'  => $opt{no_links}
43       &>
44 %   }
45 </TABLE><BR>
46 % } #foreach $locationnum
47 <%init>
48 my %opt = @_;
49 my $cust_main = $opt{'cust_main'};
50 my $all_packages = $opt{'packages'};
51
52 my %locations = map { $_->locationnum => $_ } qsearch({
53     'table'     => 'cust_location',
54     'hashref'   => { 'custnum' => $cust_main->custnum },
55     'order_by'  => 'ORDER BY country, state, city, address1, locationnum',
56   });
57 my @sections = keys %locations;
58 my %packages_in = map { $_ => [] } (@sections);
59
60 my %active = (); # groups with non-canceled packages
61 foreach my $cust_pkg ( @$all_packages ) {
62   my $key = $cust_pkg->locationnum;
63   push @{ $packages_in{$key} }, $cust_pkg;
64   $active{$key} = 1 if !$cust_pkg->getfield('cancel');
65 }
66 # prevent disabling these
67 $active{$cust_main->ship_locationnum} = 1;
68 $active{$cust_main->bill_locationnum} = 1;
69
70 my @sorted = (
71   $cust_main->ship_locationnum,
72   grep ( { $active{$_} && $_ != $cust_main->ship_locationnum } @sections),
73   grep ( { !$active{$_} } @sections),
74 );
75
76 sub edit_location_link {
77   my $locationnum = shift;
78   include( '/elements/popup_link.html',
79     'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
80     'label'       => '('.emt('Edit location').')',
81     'actionlabel' => emt('Edit'),
82   );
83 }
84
85 sub disable_location_link {
86   my $locationnum = shift;
87   include( '/elements/popup_link.html',
88     'action'      => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum",
89     'label'       => '('.emt('Disable location').')',
90     'actionlabel' => emt('Disable'),
91   );
92 }
93
94 </%init>