From: ivan Date: Fri, 9 Jan 2009 04:06:26 +0000 (+0000) Subject: pick/enter a location when ordering a package, RT#4499 X-Git-Tag: root_of_webpay_support~146 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=20bddf47a41b6d064b3cfa4c41e55c157cf0c3de pick/enter a location when ordering a package, RT#4499 --- diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 0a608ddb0..e0f58b814 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -105,6 +105,7 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use FS::cust_main qw(smart_search); use FS::cust_main::Import; use FS::cust_main_county; + use FS::cust_location; use FS::cust_pay; use FS::cust_pkg; use FS::part_pkg_taxclass; diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 0544dcfba..50d2a1846 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -158,6 +158,27 @@ sub country_full { code2country($self->country); } +=item line + +Returns this location on one line + +=cut + +sub line { + my $self = shift; + my $cydefault = FS::conf->new->config('countrydefault') || 'US'; + + my $line = $self->address1; + $line .= ', '. $self->address2 if $self->address2; + $line .= ', '. $self->city; + $line .= ' ('. $self->county. ' county)' if $self->county; + $line .= ', '. $self->state if $self->state; + $line .= ' '. $self->zip if $self->zip; + $line .= ' '. code2country($self->country) if $self->country ne $cydefault; + + $line; +} + =back =head1 BUGS diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 2b94dca33..fb6808107 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -36,6 +36,7 @@ use FS::cust_credit; use FS::cust_refund; use FS::part_referral; use FS::cust_main_county; +use FS::cust_location; use FS::tax_rate; use FS::cust_tax_location; use FS::part_pkg_taxrate; @@ -1721,6 +1722,17 @@ sub cust_pkg { shift->all_pkgs(@_); } +=item cust_location + +Returns all locations (see L) for this customer. + +=cut + +sub cust_location { + my $self = shift; + qsearch('cust_location', { 'custnum' => $self->custnum } ); +} + =item ncancelled_pkgs Returns all non-cancelled packages (see L) for this customer. diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html index d93d41728..27dd38516 100644 --- a/httemplate/edit/cust_main/contact.html +++ b/httemplate/edit/cust_main/contact.html @@ -25,55 +25,15 @@ - - <%$r%>Address - - > - - - -% my $address2_label_style = -% ( $disabled -% || ! $conf->exists('cust_main-require_address2') -% || ( !$pre && !$opt{'same_checked'} ) -% ) -% ? 'visibility:hidden' -% : ''; - - - * Unit # - - > - - - - - <%$r%>City - - > - - ><%$r%>County - - <% include('/elements/select-county.html', %select_hash ) %> - - <%$r%>State - - <% include('/elements/select-state.html', %select_hash ) %> - - <%$r%>Zip - - > - - - - - <%$r%>Country - <% include('/elements/select-country.html', %select_hash ) %> -% if ( !$pre ) { - -% } - - +<% include('/elements/location.html', + 'prefix' => $pre, + 'object' => $cust_main, + 'onchange' => $onchange, + 'disabled' => $disabled, + 'same_checked' => $opt{'same_checked'}, + 'geocode' => $opt{'geocode'}, + ) +%> <% $daytime_label %> @@ -159,20 +119,6 @@ $cust_main->set('stateid_state', $cust_main->state ) # $disabled, # ); -my %select_hash = ( - 'county' => $cust_main->get($pre.'county'), - 'state' => $cust_main->get($pre.'state'), - 'country' => $cust_main->get($pre.'country'), - 'prefix' => $pre, - 'onchange' => $onchange, - 'disabled' => $disabled, -); - -my @counties = counties( $cust_main->get($pre.'state'), - $cust_main->get($pre.'country'), - ); -my $county_style = scalar(@counties) > 1 ? '' : 'STYLE="visibility:hidden"'; - my $daytime_label = FS::Msgcat::_gettext('daytime') =~ /^(daytime)?$/ ? 'Day Phone' : FS::Msgcat::_gettext('daytime'); diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html new file mode 100644 index 000000000..bf340894a --- /dev/null +++ b/httemplate/elements/location.html @@ -0,0 +1,150 @@ +<%doc> + +Example: + + include( '/elements/location.html', + 'object' => $cust_main, # or $cust_location + 'prefix' => $pre, #only for cust_main objects + 'onchange' => $javascript, + 'disabled' => $disabled, + 'same_checked' => $same_checked, + 'geocode' => $geocode, #passed through + 'no_asterisks' => 0, #set true to disable the red asterisks next + #to required fields + ) + + + + + <%$r%>Address + + + <% $style %> + > + + + + + * Unit # + + + <% $style %> + > + + + + + <%$r%>City + + + <% $style %> + > + + ><%$r%>County + + <% include('/elements/select-county.html', %select_hash ) %> + + <%$r%>State + + <% include('/elements/select-state.html', %select_hash ) %> + + <%$r%>Zip + + + <% $style %> + > + + + + + <%$r%>Country + <% include('/elements/select-country.html', %select_hash ) %> + + +% if ( !$pre ) { + +% } + +<%init> + +my %opt = @_; + +my $pre = $opt{'prefix'}; +my $object = $opt{'object'}; +my $onchange = $opt{'onchange'}; +my $disabled = $opt{'disabled'}; + +my $conf = new FS::Conf; + +my $r = $opt{'no_asterisks'} ? '' : qq!* !; + +#false laziness with ship state +my $countrydefault = $conf->config('countrydefault') || 'US'; +$object->set($pre.'country', $countrydefault ) + unless $object->get($pre.'country'); + +my $statedefault = $conf->config('statedefault') + || ($countrydefault eq 'US' ? 'CA' : ''); +$object->set($pre.'state', $statedefault ) + unless $object->get($pre.'state') + || $object->get($pre.'country') ne $countrydefault; + +my @style = (); +push @style, 'background-color: #dddddd"' if $disabled; + +my @address2_label_style = (); +push @address2_label_style, 'visibility:hidden' + if $disabled + || ! $conf->exists('cust_main-require_address2') + || ( !$pre && !$opt{'same_checked'} ); + +my @counties = counties( $object->get($pre.'state'), + $object->get($pre.'country'), + ); +my @county_style = (); +push @county_style, 'visibility:hidden' + unless scalar(@counties) > 1; + +my $style = + scalar(@style) + ? 'STYLE="'. join(';', @style). '"' + : ''; +my $address2_label_style = + scalar(@address2_label_style) + ? 'STYLE="'. join(';', @address2_label_style). '"' + : ''; +my $county_style = + scalar(@county_style) + ? 'STYLE="'. join(';', @county_style). '"' + : ''; + +my %select_hash = ( + 'county' => $object->get($pre.'county'), + 'state' => $object->get($pre.'state'), + 'country' => $object->get($pre.'country'), + 'prefix' => $pre, + 'onchange' => $onchange, + 'disabled' => $disabled, + 'style' => \@style, +); + + diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html index c4368c271..45b0ccd5f 100644 --- a/httemplate/elements/select-country.html +++ b/httemplate/elements/select-country.html @@ -13,7 +13,7 @@ Example: disable_empty => 1, #defaults to 1, disable the empty option empty_label => 'all', #label for empty option disable_stateupdate => 0, #bool - disabled update of the select-state.html - + style => [ 'attribute:value', 'another:value' ], ); @@ -70,6 +70,7 @@ Example: ID = "<% $pre %>country" onChange = "<% $onchange %>" <% $opt{'disabled'} %> + <% $style %> > % unless ( $opt{'disable_empty'} ) { @@ -101,6 +102,12 @@ my $onchange = ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ). $opt{'onchange'}; +$opt{'style'} ||= []; +my $style = + scalar(@{$opt{style}}) + ? 'STYLE="'. join(';', @{$opt{style}}). '"' + : ''; + my $conf = new FS::Conf; my $default = $conf->config('countrydefault') || 'US'; diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html index 8ef34dbe6..59f235a23 100644 --- a/httemplate/elements/select-county.html +++ b/httemplate/elements/select-county.html @@ -14,6 +14,7 @@ Example: disabled => 0, #bool disable_empty => 1, #defaults to 1, disable the empty option empty_label => 'all', #label for empty option + style => [ 'attribute:value', 'another:value' ], ); @@ -79,6 +80,7 @@ Example: ID = "<% $pre %>county" onChange= "<% $opt{'onchange'} %>" <% $opt{'disabled'} %> + <% $style %> > % unless ( $opt{'disable_empty'} ) { @@ -123,6 +125,12 @@ $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); my $pre = $opt{'prefix'}; +$opt{'style'} ||= []; +my $style = + scalar(@{$opt{style}}) + ? 'STYLE="'. join(';', @{$opt{style}}). '"' + : ''; + my @counties = (); if ( $countyflag ) { diff --git a/httemplate/elements/select-state.html b/httemplate/elements/select-state.html index f7ac2c7bf..9b358e24d 100644 --- a/httemplate/elements/select-state.html +++ b/httemplate/elements/select-state.html @@ -14,6 +14,7 @@ Example: disable_empty => 1, #defaults to 1, disable the empty option empty_label => 'all', #label for empty option disable_countyupdate => 0, #bool - disabled update of the select-state.html + style => [ 'attribute:value', 'another:value' ], ); @@ -21,6 +22,8 @@ Example: +