function populateTenantHistory(tenantId) {
    var dbName = $("#DbName").val();
    getTenantHistory(dbName, tenantId, function (history) {
        var html = '<div id="tenant-history" class="tenant-content">';
        html += formatTenantHistory(history);
        html += '</div>';
        $("#tenant-history").replaceWith(html);
    });
}

function formatTenantHistory(history) {
    var html = '<table class="rentroll-table tenant-table">';
    html += '<tr>';
    html += '<th clss="default-th">Date/Time</th>';
    html += '<th clss="default-th">Action</th>';
    html += tableTenantColsHeader(false);
    html += '</tr>';
    var prevTenantValues = null;
    for (var i = 0; i < history.length; i++) {
        html += '<tr>';
        html += '<td class="default-td">';
        html += history[i]['DateTime'];
        html += '</td>'
        html += '<td class="default-td">';
        html += history[i]['Action'];
        html += '</td>';
        if (history[i]['HasValues'] === true) {
            if (prevTenantValues !== null) {
                html += tenantTDHtml(diffTenant(prevTenantValues, history[i]['TenantValues']), false);
            } else {
                html += tenantTDHtml(history[i]['TenantValues'], false);
            }
            prevTenantValues = history[i]['TenantValues'];
        }
        html += '</tr>';
    }
    html += '</table>';
    return html;
}

function diffValue(field, val1, val2) {
    if (val1 !== val2) {
        return '<b>' + formatField(field, val2) + '</b>';
    } 
    return '""';
}

function diffTenant(t1, t2) {
    t1.Total = tenantTotalRent(t1);
    t2.Total = tenantTotalRent(t2);
    var diff = {};
    for (var fieldName in t1) {
        var d = diffValue(fieldName, t1[fieldName], t2[fieldName]);
        if (isMoneyField(fieldName) && d === '""') {
            d = '<span class="small-diff-value">' + formatField(fieldName, t2[fieldName]) + '</span>';
        }
        diff[fieldName] = d;
    }
    return diff;
}



function getTenantHistory(dbName, tenantId, callback) {
    $.ajax({
        url: '/tenanthistory',
        dataType: 'json',
        data: { 'DbName': dbName, 'TenantId': tenantId },
        success: function (history) {
            callback(history);
        }
    });
}

@@ -1192,16 +1192,29 @@
 tTDHtml(
+formatTenant(
 history%5B
@@ -1231,16 +1231,17 @@
 Values'%5D
+)
 , false)
@@ -1423,25 +1423,18 @@
 lue(
-field, val1, val2
+prev, curr
 ) %7B%0A
@@ -1445,21 +1445,21 @@
 if (
-val1
+prev
  !== 
-val2
+curr
 ) %7B%0A
@@ -1485,32 +1485,12 @@
 ' + 
-formatField(field, val2)
+curr
  + '
@@ -1561,76 +1561,121 @@
     
-t1.Total = tenantTotalRent(t1);%0A    t2.Total = tenantTotalRe
+var diff = %7B%7D;%0A    var fieldName = '';%0A    var d = '';%0A    prev = formatTenant(t1);%0A    curr = formatTena
 nt(t2);%0A
     
@@ -1674,40 +1674,114 @@
 2);%0A
+%0A 
    
- var diff = %7B%7D
+for (var i = 0; i %3C tenantFields().length; i++) %7B%0A        fieldName = tenantFields()%5Bi%5D
 ;%0A    
+ 
-for (var 
+   if (
 fiel
@@ -1790,13 +1790,16 @@
 ame 
-in t1
+=== 'Id'
 ) %7B%0A
@@ -1802,27 +1802,55 @@
 ) %7B%0A        
-var
+    continue;%0A        %7D%0A       
  d = diffVal
@@ -1856,21 +1856,12 @@
 lue(
-fieldName, t1
+prev
 %5Bfie
@@ -1869,18 +1869,20 @@
 dName%5D, 
-t2
+curr
 %5BfieldNa
@@ -1996,33 +1996,12 @@
 ' + 
-formatField(fieldName, t2
+curr
 %5Bfie
@@ -2007,17 +2007,16 @@
 eldName%5D
-)
  + '%3C/sp

Fix diffTenant format bug, used for tenant hist.