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