[freeside-commits] branch master updated. 24f8d52f90be8e99b10734f49d451e1e70afdfbc

Ivan ivan at 420.am
Sun Oct 20 20:59:32 PDT 2013


The branch, master has been updated
       via  24f8d52f90be8e99b10734f49d451e1e70afdfbc (commit)
      from  275ce0155bd34829ee97b3f0ca48228ca3c5daca (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 24f8d52f90be8e99b10734f49d451e1e70afdfbc
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Oct 20 20:59:30 2013 -0700

    normalize contact phone formatting

diff --git a/FS/FS/contact_phone.pm b/FS/FS/contact_phone.pm
index 55cb09d..7ba8523 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 3d51776..8abce05 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 63a050c..a851d99 100644
--- a/httemplate/view/cust_main/contacts_new.html
+++ b/httemplate/view/cust_main/contacts_new.html
@@ -22,7 +22,7 @@
 %                   })
 %           or next;
           <TD ALIGN="right">   <% $phone_type->typename %> phone</TD>
-          <TD BGCOLOR="#FFFFFF"><% $contact_phone->phonenum |h %></TD>
+          <TD BGCOLOR="#FFFFFF"><% $contact_phone->phonenum_pretty |h %></TD>
 %       }
 
       </TR>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/contact_phone.pm                      |   23 +++++++++++++++++++++++
 httemplate/elements/contact.html            |    2 +-
 httemplate/view/cust_main/contacts_new.html |    2 +-
 3 files changed, 25 insertions(+), 2 deletions(-)




More information about the freeside-commits mailing list