summaryrefslogtreecommitdiff
path: root/httemplate/view/cust_main/locations.html
blob: 98c933645cbaada7eaf9b2434807fbb5948394eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<STYLE>
span.loclabel {
  padding-left: 4px; 
  padding-right: 4px; 
  background-color: #cccccc;
  border: 1px solid black
}
</STYLE>
% foreach my $locationnum (@sorted) {
%   my $packages = $packages_in{$locationnum};
%   my $loc = $locations{$locationnum};
%   next if $loc->disabled and scalar(@$packages) == 0;
<& /elements/table-grid.html &>
<TR><TH COLSPAN=3 ALIGN="left" VALIGN="bottom" 
STYLE="padding-bottom: 0px; 
  padding-left: 0px; 
  border-bottom-style: solid;
  border-bottom-color: black;
  border-bottom-width: 1px;">
<SPAN CLASS="loclabel">
%   if (! $locationnum) {
<% mt('Default service location:') |h %> 
%   }
%   elsif ( $loc->disabled ) {
<FONT COLOR="#808080"><I>
%   }
<% $loc->location_label %></SPAN>
<SPAN STYLE="float:right;">
% if ( $locationnum and !$loc->disabled ) {
<% edit_location_link($locationnum) %>
% }
% if ( $locationnum and !$loc->disabled and !$active{$locationnum} ) {
&nbsp;<% disable_location_link($locationnum) %>
% }
</SPAN></TH></TR>
%   if (@$packages) {
<& packages/section.html, 'packages' => $packages &>
%   }
</TABLE><BR>
% } #foreach $locationnum
<%init>
my %opt = @_;
my $cust_main = $opt{'cust_main'};
my $all_packages = $opt{'packages'};

my %locations = map { $_->locationnum => $_ } qsearch({
    'table'     => 'cust_location',
    'hashref'   => { 'custnum' => $cust_main->custnum },
    'order_by'  => 'ORDER BY country, state, city, address1, locationnum',
  });
my @sections = keys %locations;
$locations{''} = $cust_main;
my %packages_in = map { $_ => [] } ('', @sections);

my %active = (); # groups with non-canceled packages
foreach my $cust_pkg ( @$all_packages ) {
  my $key = $cust_pkg->locationnum;
  push @{ $packages_in{$key} }, $cust_pkg;
  $active{$key} = 1 if !$cust_pkg->getfield('cancel');
}

my @sorted = (
  '',
  grep ( { $active{$_} } @sections),
  grep ( { !$active{$_} } @sections),
);

sub edit_location_link {
  my $locationnum = shift;
  include( '/elements/popup_link.html',
    'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
    'label'       => '('.emt('Edit location').')',
    'actionlabel' => emt('Edit'),
  );
}

sub disable_location_link {
  my $locationnum = shift;
  include( '/elements/popup_link.html',
    'action'      => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum",
    'label'       => '('.emt('Disable location').')',
    'actionlabel' => emt('Disable'),
  );
}

</%init>