From 2b199169bd62b8582eedb872b4e76bee48899e81 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Wed, 22 May 2019 21:15:35 -0400 Subject: [PATCH] RT# 77532 - created method to display phone types --- FS/FS/UI/Web.pm | 3 +-- FS/FS/phone_type.pm | 12 ++++++++++++ httemplate/elements/contact.html | 2 +- httemplate/elements/select-cust-fields.html | 2 +- httemplate/elements/tr-select-cust-fields.html | 2 +- httemplate/search/contact.html | 2 +- httemplate/search/elements/options_cust_contacts.html | 2 +- httemplate/view/cust_main/contacts_new.html | 2 +- 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 9eb49c430..76071d900 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -357,7 +357,7 @@ sub cust_header { $header2method{'Cust#'} = 'display_custnum' if $conf->exists('cust_main-default_agent_custid'); -foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { +foreach my $phone_type ( FS::phone_type->get_phone_types() ) { $header2method{'Contact '.$phone_type->typename.' phone(s)'} = sub { my $self = shift; my $num = $phone_type->phonetypenum; @@ -373,7 +373,6 @@ foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { } return \@phones; }; - } my %header2colormethod = ( diff --git a/FS/FS/phone_type.pm b/FS/FS/phone_type.pm index ded6b918a..3d9dced6f 100644 --- a/FS/FS/phone_type.pm +++ b/FS/FS/phone_type.pm @@ -91,6 +91,18 @@ sub check { $self->SUPER::check; } +=item get_phone_types + +returns a list of phone_types. + +=cut + +sub get_phone_types { + ## only using mobile(3) and work(1) right now. + my @phone_types = qsearch({table=>'phone_type', order_by=>'ORDER BY weight DESC', extra_sql => " WHERE phonetypenum IN ('1','3')"}); + return @phone_types; +} + # Used by FS::Setup to initialize a new database. sub _populate_initial_data { my ($class, %opts) = @_; diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html index 599f6629d..308b846bc 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -180,7 +180,7 @@ unless ($opt{'for_prospect'}) { } my $first = 0; -foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { +foreach my $phone_type ( FS::phone_type->get_phone_types() ) { next if $phone_type->typename =~ /^(Home|Fax)$/; my $f = 'phonetypenum'.$phone_type->phonetypenum; $label{$f} = $phone_type->typename. ' phone'; diff --git a/httemplate/elements/select-cust-fields.html b/httemplate/elements/select-cust-fields.html index 7396808b1..63e92ac3d 100644 --- a/httemplate/elements/select-cust-fields.html +++ b/httemplate/elements/select-cust-fields.html @@ -3,7 +3,7 @@ my @fields = FS::ConfDefaults->cust_fields_avail(); my $contact_phone_list; - foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { + foreach my $phone_type ( FS::phone_type->get_phone_types() ) { $contact_phone_list .= " | Contact ".$phone_type->typename." phone(s)"; } @fields = map {s/\| Contact phone\(s\)/$contact_phone_list/g; $_; } @fields; diff --git a/httemplate/elements/tr-select-cust-fields.html b/httemplate/elements/tr-select-cust-fields.html index 62b8144e3..0af432ae7 100644 --- a/httemplate/elements/tr-select-cust-fields.html +++ b/httemplate/elements/tr-select-cust-fields.html @@ -8,7 +8,7 @@ my( $cust_fields, %opt ) = @_; my @fields = FS::ConfDefaults->cust_fields_avail(); my $contact_phone_list; -foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { +foreach my $phone_type ( FS::phone_type->get_phone_types() ) { $contact_phone_list .= " | Contact ".$phone_type->typename." phone(s)"; } @fields = map {s/\| Contact phone\(s\)/$contact_phone_list/g; $_; } @fields; diff --git a/httemplate/search/contact.html b/httemplate/search/contact.html index 0f2b283b5..5def389cc 100644 --- a/httemplate/search/contact.html +++ b/httemplate/search/contact.html @@ -153,7 +153,7 @@ my $get_phone_sub = sub { }; my @phones; -foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { +foreach my $phone_type ( FS::phone_type->get_phone_types() ) { push @phones, { label => $phone_type->typename.' Phone', field => $get_phone_sub->($phone_type->phonetypenum), }; } diff --git a/httemplate/search/elements/options_cust_contacts.html b/httemplate/search/elements/options_cust_contacts.html index 8a6b76913..372bc6755 100644 --- a/httemplate/search/elements/options_cust_contacts.html +++ b/httemplate/search/elements/options_cust_contacts.html @@ -12,7 +12,7 @@ <% mt('Email') |h %> -% foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) { +% foreach my $phone_type ( FS::phone_type->get_phone_types() ) { <% $phone_type->typename. ' Phone' |h %> diff --git a/httemplate/view/cust_main/contacts_new.html b/httemplate/view/cust_main/contacts_new.html index 9252b2197..bd213d1dd 100644 --- a/httemplate/view/cust_main/contacts_new.html +++ b/httemplate/view/cust_main/contacts_new.html @@ -80,7 +80,7 @@ %} <%once> -my @phone_type = qsearch({table=>'phone_type', order_by=>'weight'}); +my @phone_type = FS::phone_type->get_phone_types(); <%init> -- 2.11.0