From f144c3a14169d99fd93f265da690d9ce38dbae68 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 17 Dec 2007 00:59:02 +0000 Subject: [PATCH] add cust_main-require_address2 config, reimplement address2-search config ("Unit #" search in searchbar), visual indication of require_invoicing_list_email, closes: RT#2926 --- FS/FS/Conf.pm | 11 ++- FS/FS/cust_main.pm | 124 +++++++++++++++++++------------- httemplate/edit/cust_main.cgi | 85 +++++++++++++--------- httemplate/edit/cust_main/billing.html | 4 +- httemplate/edit/cust_main/contact.html | 18 ++++- httemplate/elements/header.html | 29 ++++++-- httemplate/search/cust_main.cgi | 5 +- httemplate/view/cust_main/contacts.html | 19 +++-- 8 files changed, 195 insertions(+), 100 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 0f1fcbbee..85a2b9b07 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1716,7 +1716,14 @@ worry that config_items is freeside-specific and icky. { 'key' => 'address2-search', 'section' => 'UI', - 'description' => 'Enable a "Unit" search box which searches the second address field', + 'description' => 'Enable a "Unit" search box which searches the second address field. Useful for multi-tenant applications. See also: cust_main-require_address2', + 'type' => 'checkbox', + }, + + { + 'key' => 'cust_main-require_address2', + 'section' => 'UI', + 'description' => 'Second address field is required (on service address only, if billing and service addresses differ). Also enables "Unit" labeling of address2 on customer view and edit pages. Useful for multi-tenant applications. See also: address2-search', 'type' => 'checkbox', }, @@ -2091,7 +2098,7 @@ worry that config_items is freeside-specific and icky. { 'key' => 'cust_main-require_invoicing_list_email', 'section' => '', - 'description' => 'Require at least one invoicing email address for all customer records.', + 'description' => 'Email address field is required: require at least one invoicing email address for all customer records.', 'type' => 'checkbox', }, diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 59ebfb58a..b5e689233 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1291,58 +1291,60 @@ sub check { } - my @addfields = qw( - last first company address1 address2 city county state zip - country daytime night fax - ); + if ( $self->has_ship_address + && scalar ( grep { $self->getfield($_) ne $self->getfield("ship_$_") } + $self->addr_fields ) + ) + { + my $error = + $self->ut_name('ship_last') + || $self->ut_name('ship_first') + || $self->ut_textn('ship_company') + || $self->ut_text('ship_address1') + || $self->ut_textn('ship_address2') + || $self->ut_text('ship_city') + || $self->ut_textn('ship_county') + || $self->ut_textn('ship_state') + || $self->ut_country('ship_country') + ; + return $error if $error; - if ( defined $self->dbdef_table->column('ship_last') ) { - if ( scalar ( grep { $self->getfield($_) ne $self->getfield("ship_$_") } - @addfields ) - && scalar ( grep { $self->getfield("ship_$_") ne '' } @addfields ) - ) - { - my $error = - $self->ut_name('ship_last') - || $self->ut_name('ship_first') - || $self->ut_textn('ship_company') - || $self->ut_text('ship_address1') - || $self->ut_textn('ship_address2') - || $self->ut_text('ship_city') - || $self->ut_textn('ship_county') - || $self->ut_textn('ship_state') - || $self->ut_country('ship_country') - ; - return $error if $error; + #false laziness with above + unless ( qsearchs('cust_main_county', { + 'country' => $self->ship_country, + 'state' => '', + } ) ) { + return "Unknown ship_state/ship_county/ship_country: ". + $self->ship_state. "/". $self->ship_county. "/". $self->ship_country + unless qsearch('cust_main_county',{ + 'state' => $self->ship_state, + 'county' => $self->ship_county, + 'country' => $self->ship_country, + } ); + } + #eofalse - #false laziness with above - unless ( qsearchs('cust_main_county', { - 'country' => $self->ship_country, - 'state' => '', - } ) ) { - return "Unknown ship_state/ship_county/ship_country: ". - $self->ship_state. "/". $self->ship_county. "/". $self->ship_country - unless qsearch('cust_main_county',{ - 'state' => $self->ship_state, - 'county' => $self->ship_county, - 'country' => $self->ship_country, - } ); - } - #eofalse - - $error = - $self->ut_phonen('ship_daytime', $self->ship_country) - || $self->ut_phonen('ship_night', $self->ship_country) - || $self->ut_phonen('ship_fax', $self->ship_country) - || $self->ut_zip('ship_zip', $self->ship_country) - ; - return $error if $error; + $error = + $self->ut_phonen('ship_daytime', $self->ship_country) + || $self->ut_phonen('ship_night', $self->ship_country) + || $self->ut_phonen('ship_fax', $self->ship_country) + || $self->ut_zip('ship_zip', $self->ship_country) + ; + return $error if $error; + + return "Unit # is required." + if $self->ship_address2 =~ /^\s*$/ + && $conf->exists('cust_main-require_address2'); + + } else { # ship_ info eq billing info, so don't store dup info in database + + $self->setfield("ship_$_", '') + foreach $self->addr_fields; + + return "Unit # is required." + if $self->address2 =~ /^\s*$/ + && $conf->exists('cust_main-require_address2'); - } else { # ship_ info eq billing info, so don't store dup info in database - $self->setfield("ship_$_", '') - foreach qw( last first company address1 address2 city county state zip - country daytime night fax ); - } } #$self->payby =~ /^(CARD|DCRD|CHEK|DCHK|LECB|BILL|COMP|PREPAY|CASH|WEST|MCRD)$/ @@ -1543,6 +1545,30 @@ sub check { $self->SUPER::check; } +=item addr_fields + +Returns a list of fields which have ship_ duplicates. + +=cut + +sub addr_fields { + qw( last first company + address1 address2 city county state zip country + daytime night fax + ); +} + +=item has_ship_address + +Returns true if this customer record has a separate shipping address. + +=cut + +sub has_ship_address { + my $self = shift; + scalar( grep { $self->getfield("ship_$_") ne '' } $self->addr_fields ); +} + =item all_pkgs Returns all packages (see L) for this customer. diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 579d6cfe3..be9dd1bfb 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -207,13 +207,31 @@ +% my $same_checked = ''; +% my $ship_disabled = ''; +% unless ( $cust_main->ship_last && $same ne 'Y' ) { +% $same_checked = 'CHECKED'; +% $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"'; +% foreach ( +% qw( last first company address1 address2 city county state zip country +% daytime night fax ) +% ) { +% $cust_main->set("ship_$_", $cust_main->get($_) ); +% } +% } +

Billing address -<% include('cust_main/contact.html', $cust_main, '', 'bill_changed(this)', '', 'ss' => $ss, 'stateid' => $stateid ) %> - - -% if ( defined $cust_main->dbdef_table->column('ship_last') ) { - +<% include('cust_main/contact.html', + 'cust_main' => $cust_main, + 'pre' => '', + 'onchange' => 'bill_changed(this)', + 'disabled' => '', + 'ss' => $ss, + 'stateid' => $stateid, + 'same_checked' => $same_checked, #for address2 "Unit #" labeling + ) +%> -% -% my $checked = ''; -% my $disabled = ''; -% my $disabledselect = ''; -% unless ( $cust_main->ship_last && $same ne 'Y' ) { -% $checked = 'CHECKED'; -% $disabled = 'DISABLED STYLE="background-color: #dddddd"'; -% foreach ( -% qw( last first company address1 address2 city county state zip country -% daytime night fax ) -% ) { -% $cust_main->set("ship_$_", $cust_main->get($_) ); -% } -% } -% -
Service address -(>same as billing address) -<% include('cust_main/contact.html', $cust_main, 'ship_', '', $disabled ) %> -% } +(>same as billing address) +<% include('cust_main/contact.html', + 'cust_main' => $cust_main, + 'pre' => 'ship_', + 'onchange' => '', + 'disabled' => $ship_disabled, + ) +%> diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index 394c5d8d5..6ed35c15a 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -426,7 +426,9 @@ % } - Email invoice + + <% $conf->exists('cust_main-require_invoicing_list_email') ? $r : '' %>Email address(es) + diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html index 58fee3291..21c6b2990 100644 --- a/httemplate/edit/cust_main/contact.html +++ b/httemplate/edit/cust_main/contact.html @@ -32,8 +32,16 @@ +% my $address2_label_style = +% ( $disabled +% || ! $conf->exists('cust_main-require_address2') +% || ( !$pre && !$opt{'same_checked'} ) +% ) +% ? 'visibility:hidden' +% : ''; + -   + * Unit # > @@ -107,7 +115,13 @@ <%init> -my( $cust_main, $pre, $onchange, $disabled, %opt ) = @_; +#my( $cust_main, $pre, $onchange, $disabled, %opt ) = @_; +my %opt = @_; +my $cust_main = $opt{'cust_main'}; +my $pre = $opt{'pre'}; +my $onchange = $opt{'onchange'}; +my $disabled = $opt{'disabled'}; + my $conf = new FS::Conf; foreach (qw(ss stateid)) { diff --git a/httemplate/elements/header.html b/httemplate/elements/header.html index 0ff8ecda6..dfe6b6829 100644 --- a/httemplate/elements/header.html +++ b/httemplate/elements/header.html @@ -19,6 +19,11 @@ what.value = ''; } + function clearhint_search_address2 (what) { + if ( what.value == '(Unit #)' ) + what.value = ''; + } + function clearhint_search_invoice (what) { if ( what.value == '(inv #)' ) what.value = ''; @@ -113,14 +118,14 @@ input.fsblackbuttonselected { - + % if ( $menu_position eq 'top' ) { - - - @@ -156,21 +161,31 @@ input.fsblackbuttonselected { + + + % if ( $cust_main->get("${pre}address2") ) { +% my $address2_label = +% ( $conf->exists('cust_main-require_address2') +% # && ( ( !$which && !$cust_main->has_ship_address ) +% # || ( $which && $cust_main->has_ship_address ) +% # ) +% && ! ( $which xor $cust_main->has_ship_address ) +% ) +% ? 'Unit #' +% : ' '; + + + + + - - - - % } -- 2.11.0
+ @@ -129,12 +134,12 @@ input.fsblackbuttonselected {
+
+
+% if ( $conf->exists('address2-search') ) { +
+ + +
+ +
+% } +
% if ( $FS::CurrentUser::CurrentUser->access_right('View invoices') ) {
-% if ( $FS::CurrentUser::CurrentUser->access_right('List invoices') ) { +% if ( $FS::CurrentUser::CurrentUser->access_right('List invoices') ) { Advanced -% } +% }
% } -
diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index b0f657fbb..1ddafae0b 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -688,9 +688,8 @@ % { 'address2' => { 'op' => 'ILIKE', % 'value' => $address2 } } ); % push @cust_main, qsearch( 'cust_main', -% { 'address2' => { 'op' => 'ILIKE', -% 'value' => $address2 } } ) -% if defined dbdef->table('cust_main')->column('ship_last'); +% { 'ship_address2' => { 'op' => 'ILIKE', +% 'value' => $address2 } } ); % % \@cust_main; %} diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html index 22594c5e2..20770e45b 100644 --- a/httemplate/view/cust_main/contacts.html +++ b/httemplate/view/cust_main/contacts.html @@ -25,12 +25,23 @@ Address <% $cust_main->get("${pre}address1") %>
<% $address2_label %><% $cust_main->get("${pre}address2") %>
 <% $cust_main->get("${pre}address2") %>