NG auth: autocreate records for external users, RT#21563
[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 and !$loc->disabled ) {
32 <% edit_location_link($locationnum) %>
33 % }
34 % if ( $locationnum and !$loc->disabled and !$active{$locationnum} ) {
35 &nbsp;<% disable_location_link($locationnum) %>
36 % }
37 </SPAN></TH></TR>
38 %   if (@$packages) {
39 <& packages/section.html, 'packages' => $packages &>
40 %   }
41 </TABLE><BR>
42 % } #foreach $locationnum
43 <%init>
44 my %opt = @_;
45 my $cust_main = $opt{'cust_main'};
46 my $all_packages = $opt{'packages'};
47
48 my %locations = map { $_->locationnum => $_ } qsearch({
49     'table'     => 'cust_location',
50     'hashref'   => { 'custnum' => $cust_main->custnum },
51     'order_by'  => 'ORDER BY country, state, city, address1, locationnum',
52   });
53 my @sections = keys %locations;
54 my %packages_in = map { $_ => [] } (@sections);
55
56 my %active = (); # groups with non-canceled packages
57 foreach my $cust_pkg ( @$all_packages ) {
58   my $key = $cust_pkg->locationnum;
59   push @{ $packages_in{$key} }, $cust_pkg;
60   $active{$key} = 1 if !$cust_pkg->getfield('cancel');
61 }
62 # prevent disabling these
63 $active{$cust_main->ship_locationnum} = 1;
64 $active{$cust_main->bill_locationnum} = 1;
65
66 my @sorted = (
67   $cust_main->ship_locationnum,
68   grep ( { $active{$_} && $_ != $cust_main->ship_locationnum } @sections),
69   grep ( { !$active{$_} } @sections),
70 );
71
72 sub edit_location_link {
73   my $locationnum = shift;
74   include( '/elements/popup_link.html',
75     'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
76     'label'       => '('.emt('Edit location').')',
77     'actionlabel' => emt('Edit'),
78   );
79 }
80
81 sub disable_location_link {
82   my $locationnum = shift;
83   include( '/elements/popup_link.html',
84     'action'      => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum",
85     'label'       => '('.emt('Disable location').')',
86     'actionlabel' => emt('Disable'),
87   );
88 }
89
90 </%init>