RT# 71289 - now shows contact email and phone changes while attached to customer
authorChristopher Burger <burgerc@freeside.biz>
Fri, 30 Nov 2018 20:42:53 +0000 (15:42 -0500)
committerChristopher Burger <burgerc@freeside.biz>
Fri, 30 Nov 2018 20:42:53 +0000 (15:42 -0500)
httemplate/elements/change_history_common.html
httemplate/view/cust_main/change_history.html

index f22e093..d734053 100644 (file)
@@ -232,6 +232,8 @@ my %h_table_labelsub = (
   #'h_cust_tag'      => $tag_labelsub,
   'h_contact'  => $contact_labelsub,
   'h_cust_contact'  => $contact_labelsub,
+  'h_contact_phone' => $contact_labelsub,
+  'h_contact_email' => $contact_labelsub,
 );
 
 my $tag_descripsub = sub {
@@ -240,6 +242,24 @@ my $tag_descripsub = sub {
   '<SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
 };
 
+my $contact_descripsub = sub {
+  my($item, $label) = @_;
+  my $phone_type = qsearchs('phone_type',{ phonetypenum => $item->phonetypenum });
+  my @fields = $item->fields;
+  join(', ',
+    map  {
+           my $value = ( $_ eq "phonetypenum" )
+              ? $item->get($_).' ('.$phone_type->typename.')'
+              : $item->get($_);
+           $value = substr($value, 0, 77).'...' if length($value) > 80;
+           $value = encode_entities($value);
+           "<I>$_</I>:<B>$value</B>";
+         }
+         grep { ! /^(history|custnum$)/i }
+            @fields
+  );
+};
+
 my $discounts = {};
 my $discount_descripsub = sub {
   my($item) = @_;
@@ -260,6 +280,7 @@ my $discount_descripsub = sub {
 my %h_table_descripsub = (
   'h_cust_pkg_discount' => $discount_descripsub,
   'h_cust_tag'          => $tag_descripsub,
+  'h_contact_phone'     => $contact_descripsub,
 );
 
 my $cust_pkg_date_format = '%b %o, %Y';
index 11777b5..933d66c 100644 (file)
@@ -50,6 +50,8 @@ tie my %tables, 'Tie::IxHash',
   'cust_tag'          => 'Tag',
   'contact'           => 'Contact',
   'cust_contact'      => 'Contact',
+  'contact_phone'     => 'Contact',
+  'contact_email'     => 'Contact',
 ;
 
 my $pkg_join = "JOIN cust_pkg USING ( pkgnum )";
@@ -147,8 +149,7 @@ my $extra_sql = ' AND custnum = '. $cust_main->custnum;
 
 my %foundsvcs;
 foreach my $table ( keys %tables ) {
-  if ($table eq 'cust_contact') { next; } #skip as dont need to search table but hack to show contact name
-  elsif ($table eq 'contact') {
+  if ($tables{$table} eq 'Contact') {
 
     my $contact_addl_from = "
       INNER JOIN (select contactnum, min(history_date) as min_history_date, max(history_date) as max_history_date, max(historynum) as max_historynum FROM h_cust_contact WHERE custnum = ".$cust_main->custnum." AND history_date >= $newer_than GROUP BY contactnum) a ON h_cust_contact.contactnum = a.contactnum
@@ -168,25 +169,14 @@ foreach my $table ( keys %tables ) {
 
      ## get history of contact while attached to customer
      my @contact_history = qsearch({
-       'table'      => "h_contact",
+       'table'      => "h_$table",
        'hashref'    => {
-          'history_date' =>  { op=>'>=', value=>$c->{Hash}->{min_history_date} },
+          'history_date' =>  { op=>'>=', value=>($c->{Hash}->{min_history_date} - 1) },
           'contactnum'   => $c->{Hash}->{contactnum},
-        },
-        'extra_sql' => $max_date_sql,
+       },
+       'extra_sql' => $max_date_sql,
      });
-
-     ## get history of customer specific changes to contact.
-     my @cust_contact_history = qsearch({
-       'table'     => "h_cust_contact",
-       'hashref'   => {
-          'history_date' =>  { op=>'>=', value=>$c->{Hash}->{min_history_date} },
-          'contactnum'   => $c->{Hash}->{contactnum},
-          'custnum'      => $cust_main->custnum,
-        },
-     });
-
-     push @history, @contact_history; push @history, @cust_contact_history;
+     push @history, @contact_history;
     }
   }
   else {