[freeside-commits] branch FREESIDE_4_BRANCH updated. ea2203e7bfa850d6e74338614130346d45c1bcbb

Christopher Burger burgerc at freeside.biz
Tue Oct 23 07:25:04 PDT 2018


The branch, FREESIDE_4_BRANCH has been updated
       via  ea2203e7bfa850d6e74338614130346d45c1bcbb (commit)
       via  3a740c3c1862c2253de3c3f5914a72b06e855023 (commit)
      from  ed72ea9bc6909be8dfaa317eb4e5681702d6fb4f (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 ea2203e7bfa850d6e74338614130346d45c1bcbb
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Oct 23 10:06:37 2018 -0400

    RT# 71289 - fixed duplicate contact changes in customer history

diff --git a/httemplate/view/cust_main/change_history.html b/httemplate/view/cust_main/change_history.html
index 4ff604d7a..11777b54c 100644
--- a/httemplate/view/cust_main/change_history.html
+++ b/httemplate/view/cust_main/change_history.html
@@ -151,7 +151,7 @@ foreach my $table ( keys %tables ) {
   elsif ($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 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
+      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
     ";
 
     ## get list with add and remove dates of contacts for customer
@@ -159,7 +159,7 @@ foreach my $table ( keys %tables ) {
       'table' => "h_cust_contact",
       'select' => "a.contactnum, a.min_history_date, a.max_history_date, history_action AS max_history_action",
       'addl_from' => $contact_addl_from,
-      'extra_sql' => " WHERE history_date = a.max_history_date",
+      'extra_sql' => " WHERE historynum = a.max_historynum",
     });
 
     foreach my $c (@h_cust_contacts) {

commit 3a740c3c1862c2253de3c3f5914a72b06e855023
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Mon Oct 22 19:18:51 2018 -0400

    RT# 71289 - add contact changes to customer change history

diff --git a/httemplate/elements/change_history_common.html b/httemplate/elements/change_history_common.html
index 4c05f4e3a..f22e09360 100644
--- a/httemplate/elements/change_history_common.html
+++ b/httemplate/elements/change_history_common.html
@@ -53,6 +53,8 @@
 %     $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} )
 %        if $single_cust && $h_table_descripsub{$item->table};
 %   } else {
+%     my @fields = $item->fields;
+%     push @fields, 'message_dest' if $item->table eq 'h_contact';
 %     $description = join(', ',
 %             map  { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ ) 
 %                                  ? 'N/A'
@@ -71,7 +73,7 @@
 %                      : ( $item->get($_) =~ /\S/ )
 %                  }
 %             grep { ! /^(history|custnum$)/i }
-%                  $item->fields
+%                  @fields
 %     );
 %     if ( $single_cust && $h_table_descripsub{$item->table} ) {
 %        $description = &{ $h_table_descripsub{$item->table} }( $item );
@@ -229,6 +231,7 @@ my %h_table_labelsub = (
   #'h_phone_device'
   #'h_cust_tag'      => $tag_labelsub,
   'h_contact'  => $contact_labelsub,
+  'h_cust_contact'  => $contact_labelsub,
 );
 
 my $tag_descripsub = sub {
diff --git a/httemplate/view/cust_main/change_history.html b/httemplate/view/cust_main/change_history.html
index d8f0d1efc..4ff604d7a 100644
--- a/httemplate/view/cust_main/change_history.html
+++ b/httemplate/view/cust_main/change_history.html
@@ -49,6 +49,7 @@ tie my %tables, 'Tie::IxHash',
   #? it gets provisioned anyway 'phone_avail'         => 'Phone',
   'cust_tag'          => 'Tag',
   'contact'           => 'Contact',
+  'cust_contact'      => 'Contact',
 ;
 
 my $pkg_join = "JOIN cust_pkg USING ( pkgnum )";
@@ -69,7 +70,6 @@ my %table_join = (
   'radius_usergroup' => $svc_join,
   'phone_device'     => $svc_join,
   'cust_pkg_discount'=> $pkg_join,
-  'contact'          => "JOIN cust_contact USING ( contactnum )",
 );
 
 %table_join = (%table_join, map { $_ => $svc_join } @svc_tables);
@@ -147,16 +147,59 @@ my $extra_sql = ' AND custnum = '. $cust_main->custnum;
 
 my %foundsvcs;
 foreach my $table ( keys %tables ) {
-  $extra_sql = ' AND cust_contact.custnum = '. $cust_main->custnum if $table eq 'contact';
-  my @items = qsearch({
-    'table'     => "h_$table",
-    'addl_from' => $table_join{$table},
-    'hashref'   => { 'history_date' =>  { op=>'>=', value=>$newer_than }, },
-    'extra_sql' => $extra_sql,
-  });
-  %foundsvcs = (%foundsvcs, map { $_->svcnum => 1 } @items)
-    if $table =~ /^svc/;
-  push @history, @items;
+  if ($table eq 'cust_contact') { next; } #skip as dont need to search table but hack to show contact name
+  elsif ($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 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
+    ";
+
+    ## get list with add and remove dates of contacts for customer
+    my @h_cust_contacts = qsearch({
+      'table' => "h_cust_contact",
+      'select' => "a.contactnum, a.min_history_date, a.max_history_date, history_action AS max_history_action",
+      'addl_from' => $contact_addl_from,
+      'extra_sql' => " WHERE history_date = a.max_history_date",
+    });
+
+    foreach my $c (@h_cust_contacts) {
+     my $max_date_sql;
+     $max_date_sql = " AND history_date <= ".$c->{Hash}->{max_history_date} if $c->{Hash}->{max_history_action} eq 'delete';
+
+     ## get history of contact while attached to customer
+     my @contact_history = qsearch({
+       'table'      => "h_contact",
+       'hashref'    => {
+          'history_date' =>  { op=>'>=', value=>$c->{Hash}->{min_history_date} },
+          'contactnum'   => $c->{Hash}->{contactnum},
+        },
+        '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;
+    }
+  }
+  else {
+    my @items = qsearch({
+      'table'     => "h_$table",
+      'addl_from' => $table_join{$table},
+      'hashref'   => { 'history_date' =>  { op=>'>=', value=>$newer_than }, },
+      'extra_sql' => $extra_sql,
+    });
+    %foundsvcs = (%foundsvcs, map { $_->svcnum => 1 } @items)
+      if $table =~ /^svc/;
+    push @history, @items;
+  }
 }
 
 ### Load svcs that are no longer linked (cust_svc has been deleted)

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

Summary of changes:
 httemplate/elements/change_history_common.html |  5 +-
 httemplate/view/cust_main/change_history.html  | 65 +++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 12 deletions(-)




More information about the freeside-commits mailing list