X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fview%2Fcust_main%2Fchange_history.html;h=933d66c8afafc944722a2efb6699a73d67bd1e8c;hb=HEAD;hp=a781c73721b5c3e130b9d3fbeb26376000a8c929;hpb=6df492990ea195513430f3a56d537e57e50b6913;p=freeside.git diff --git a/httemplate/view/cust_main/change_history.html b/httemplate/view/cust_main/change_history.html index a781c7372..933d66c8a 100644 --- a/httemplate/view/cust_main/change_history.html +++ b/httemplate/view/cust_main/change_history.html @@ -32,6 +32,7 @@ tie my %years, 'Tie::IxHash', tie my %tables, 'Tie::IxHash', 'cust_main' => 'Customer', 'cust_main_invoice' => 'Invoice destination', + 'cust_main_note' => 'Note', 'cust_pkg' => 'Package', #? or just svc_* ? 'cust_svc' => 'svc_acct' => 'Account', @@ -47,6 +48,10 @@ tie my %tables, 'Tie::IxHash', 'cust_pkg_discount' => 'Discount', #? it gets provisioned anyway 'phone_avail' => 'Phone', 'cust_tag' => 'Tag', + 'contact' => 'Contact', + 'cust_contact' => 'Contact', + 'contact_phone' => 'Contact', + 'contact_email' => 'Contact', ; my $pkg_join = "JOIN cust_pkg USING ( pkgnum )"; @@ -140,17 +145,51 @@ my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24 local($FS::Record::nowarn_classload) = 1; +my $extra_sql = ' AND custnum = '. $cust_main->custnum; + my %foundsvcs; foreach my $table ( keys %tables ) { - my @items = qsearch({ - 'table' => "h_$table", - 'addl_from' => $table_join{$table}, - 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than }, }, - 'extra_sql' => ' AND custnum = '. $cust_main->custnum, - }); - %foundsvcs = (%foundsvcs, map { $_->svcnum => 1 } @items) - if $table =~ /^svc/; - push @history, @items; + 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 + "; + + ## 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 historynum = a.max_historynum", + }); + + 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_$table", + 'hashref' => { + 'history_date' => { op=>'>=', value=>($c->{Hash}->{min_history_date} - 1) }, + 'contactnum' => $c->{Hash}->{contactnum}, + }, + 'extra_sql' => $max_date_sql, + }); + push @history, @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)