RT# 83436 - fixed Advanced Broadband Service Report when displaying phone numbers
[freeside.git] / FS / FS / UI / Web.pm
index 8a1d502..2d12f7d 100644 (file)
@@ -7,7 +7,7 @@ use Carp qw( confess );
 use HTML::Entities;
 use FS::Conf;
 use FS::Misc::DateTime qw( parse_datetime day_end );
-use FS::Record qw(dbdef);
+use FS::Record qw(dbdef qsearch);
 use FS::cust_main;  # are sql_balance and sql_date_balance in the right module?
 
 #use vars qw(@ISA);
@@ -357,6 +357,24 @@ sub cust_header {
   $header2method{'Cust#'} = 'display_custnum'
     if $conf->exists('cust_main-default_agent_custid');
 
+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;
+
+    my @phones;
+    foreach (FS::cust_main::contact_list_name_phones($self)) {
+      my $data = [
+        {
+          'data'  => $_->first.' '.$_->last.' '.FS::contact_phone::phonenum_pretty($_),
+        },
+      ];
+      push @phones, $data if $_->phonetypenum eq $phone_type->phonetypenum;
+    }
+  return \@phones;
+  };
+}
+
   my %header2colormethod = (
     'Cust. Status' => 'cust_statuscolor',
   );
@@ -414,7 +432,14 @@ sub cust_sort_fields {
   cust_header(@_) if( @_ or !@cust_fields );
   #inefficientish, but tiny lists and only run once per page
 
-  map { $_ eq 'custnum' ? 'custnum' : '' } @cust_fields;
+  my @sort_fields;
+  foreach (@cust_fields) {
+    if ($_ eq "custnum") { push @sort_fields, 'custnum'; }
+    elsif ($_ eq "contact" || $_ eq "name") { push @sort_fields, '(last, first)'; }
+    elsif ($_ eq "company") { push @sort_fields, 'company'; }
+    else { push @sort_fields, ''; }
+  }
+  return @sort_fields;
 
 }
 
@@ -450,7 +475,7 @@ sub cust_sql_fields {
     }
   }
 
-  foreach my $field (qw(daytime night mobile fax )) {
+  foreach my $field (qw(daytime night mobile fax)) {
     push @fields, $field if (grep { $_ eq $field } @cust_fields);
   }
   push @fields, 'agent_custid';
@@ -471,9 +496,9 @@ sub cust_sql_fields {
 =item join_cust_main [ TABLE[.CUSTNUM] ] [ LOCATION_TABLE[.LOCATIONNUM] ]
 
 Returns an SQL join phrase for the FROM clause so that the fields listed
-in L<cust_sql_fields> will be available.  Currently joins to cust_main 
+in L</cust_sql_fields> will be available.  Currently joins to cust_main
 itself, as well as cust_location (under the aliases 'bill_location' and
-'ship_location') if address fields are needed.  L<cust_header()> should have
+'ship_location') if address fields are needed.  L</cust_header> should have
 been called already.
 
 All of these will be left joins; if you want to exclude rows with no linked