%doc>
Example:
include('/elements/tr-select-cust_location.html',
'cgi' => $cgi,
'cust_main' => $cust_main,
#or
'prospect_main' => $prospect_main,
#optional
'empty_label' => '(default service address)',
)
%doc>
<% include('/elements/xmlhttp.html',
'url' => $p.'misc/location.cgi',
'subs' => [ 'get_location' ],
)
%>
Service location |
|
<% include('/elements/location.html',
'object' => $cust_location,
#'onchange' ? probably not
'disabled' => $disabled,
'no_asterisks' => 1,
)
%>
<%once>
my @location_fields = qw( address1 address2 city county state zip country );
%once>
<%init>
my $conf = new FS::Conf;
my $countrydefault = $conf->config('countrydefault') || 'US';
my $statedefault = $conf->config('statedefault')
|| ($countrydefault eq 'US' ? 'CA' : '');
my %opt = @_;
my $cgi = $opt{'cgi'};
my $cust_main = $opt{'cust_main'};
my $prospect_main = $opt{'prospect_main'};
my $prefix = ($cust_main && length($cust_main->ship_last)) ? 'ship_' : '';
my $locationnum;
if ( length($opt{'curr_value'}) ) {
$locationnum = $opt{'curr_value'};
} else {
$cgi->param('locationnum') =~ /^(\-?\d*)$/ or die "illegal locationnum";
$locationnum = $1;
}
#probably could use explicit controls
# (cust_main locations not editable for tax reasons)
my $editable = $cust_main ? 0 : 1; #could use explicit control
my $addnew = $cust_main ? 1 : ( $locationnum>0 ? 0 : 1 );
my $cust_location;
if ( $locationnum && $locationnum != -1 ) {
$cust_location = qsearchs('cust_location', { 'locationnum' => $locationnum } )
or die "unknown locationnum";
} else {
$cust_location = new FS::cust_location;
if ( $locationnum == -1 ) {
$cust_location->$_( $cgi->param($_) ) foreach @location_fields;
} elsif ( $cust_main ) {
$cust_location->$_( $cust_main->get($prefix.$_) ) foreach @location_fields;
}
}
my $disabled = ( $locationnum == -1 || ($editable && $locationnum) )
? ''
: 'DISABLED';
%init>