From: Ivan Kohler Date: Mon, 21 Oct 2013 03:59:32 +0000 (-0700) Subject: normalize contact phone formatting X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=92862c52a70620257a455b25c239ce03d1692608;p=freeside.git normalize contact phone formatting --- diff --git a/FS/FS/contact_phone.pm b/FS/FS/contact_phone.pm index 55cb09dc3..7ba85234a 100644 --- a/FS/FS/contact_phone.pm +++ b/FS/FS/contact_phone.pm @@ -131,6 +131,29 @@ sub check { $self->SUPER::check; } +sub phonenum_pretty { + my $self = shift; + + #until/unless we have the upgrade strip all whitespace + (my $phonenum = $self->phonenum ) =~ s/\D//g; + + if ( $self->countrycode == 1 ) { + + $phonenum =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ + or return $self->phonenum; #wtf? + + $phonenum = "($1) $2-$3"; + $phonenum .= " x$4" if $4; + return $phonenum; + + } else { + warn "don't know how to format phone numbers for country +". $self->countrycode; + #also, the UI doesn't have a good way for you to enter them yet or parse a countrycode from the number + return $self->phonenum; + } + +} + =back =head1 BUGS diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html index 3d5177612..8abce058e 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -31,7 +31,7 @@ % 'phonetypenum' => $1, % }); % if ( $contact_phone ) { -% $value = $contact_phone->phonenum; +% $value = $contact_phone->phonenum_pretty; % $value .= 'x'.$contact_phone->extension % if $contact_phone->extension; % $value = '+'. $contact_phone->countrycode. " $value" diff --git a/httemplate/view/cust_main/contacts_new.html b/httemplate/view/cust_main/contacts_new.html index 63a050c04..a851d99ed 100644 --- a/httemplate/view/cust_main/contacts_new.html +++ b/httemplate/view/cust_main/contacts_new.html @@ -22,7 +22,7 @@ % }) % or next;    <% $phone_type->typename %> phone - <% $contact_phone->phonenum |h %> + <% $contact_phone->phonenum_pretty |h %> % }