</SCRIPT>
<TR>
- <TH ALIGN="right">Service location</TH>
+ <<%$th%> ALIGN="right"><% $opt{'label'} || 'Service location' %></<%$th%>>
<TD COLSPAN=7>
- <SELECT NAME="locationnum" onChange="locationnum_changed(this);">
+ <SELECT NAME = "locationnum"
+ ID = "locationnum"
+ onChange = "locationnum_changed(this);"
+ >
<OPTION VALUE=""><% $opt{'empty_label'} || '(default service address)' |h %>
% my @locations = $cust_main ? $cust_main->cust_location : ();
% push @locations, $cust_location
% if !$cust_main && $cust_location && $cust_location->locationnum>0;
-% foreach my $loc ( @locations ) {
+% foreach my $loc ( sort $location_sort @locations ) {
+% next if $loc->disabled;
<OPTION VALUE="<% $loc->locationnum %>"
<% $locationnum == $loc->locationnum ? 'SELECTED' : '' %>
><% $loc->line |h %>
#'onchange' ? probably not
'disabled' => $disabled,
'no_asterisks' => 1,
+ 'no_bold' => $opt{'no_bold'},
)
%>
my %opt = @_;
my $cgi = $opt{'cgi'};
+my $cust_pkg = $opt{'cust_pkg'};
my $cust_main = $opt{'cust_main'};
my $prospect_main = $opt{'prospect_main'};
$cust_location = new FS::cust_location;
if ( $locationnum == -1 ) {
$cust_location->$_( $cgi->param($_) ) foreach @location_fields;
+ } elsif ( $cust_pkg && $cust_pkg->locationnum ) {
+ my $pkg_location = $cust_pkg->cust_location;
+ $cust_location->$_( $pkg_location->$_ ) foreach @location_fields;
+ $opt{'empty_label'} ||= 'package address: '.$pkg_location->line;
} elsif ( $cust_main ) {
$cust_location->$_( $cust_main->get($prefix.$_) ) foreach @location_fields;
}
}
+my $location_sort = sub {
+ $a->country cmp $b->country
+ or lc($a->city) cmp lc($b->city)
+ or lc($a->address1) cmp lc($b->address1)
+ or lc($a->address2) cmp lc($b->address2)
+};
+
my $disabled = ( $locationnum == -1 || ($editable && $locationnum) )
? ''
: 'DISABLED';
+my $th = $opt{'no_bold'} ? 'TD' : 'TH';
+
</%init>