$(document).ready( () => { const companies = getCompanies(); const pad = 'style="padding: 12px 54px;">', hPad = '' + hPad + 'Period 1' + hPad + 'Period 2'; let compKeys = Object.keys(companies), mKeys = Object.keys(monthlySpreadsheets), lastPeriod = mKeys[0], lastMonth = lastPeriod.split('-')[1], lastYear = lastPeriod.split('-')[0], active = new Date >= new Date(lastMonth + ' 1, ' + lastYear), period1 = monthlySpreadsheets[mKeys[1]], period2 = monthlySpreadsheets[lastPeriod]; for (let i = 0; i < compKeys.length; i++) { let sideHeader = hPad + companies[compKeys[i]] + '', data1 = period1[compKeys[i]], data2 = period2[compKeys[i]]; let anchor1 = '', anchor2 = ''; let title = sideHeader.split('>')[1].split('<')[0].trim(); if (data1 && data1[0]) { let monYr = mKeys[1].split('-')[1] + ' ' + mKeys[1].split('-')[0]; anchor1 = dPad + ''; anchor1 += (data1[1]) ? monYr + '' : '' + monYr; anchor1 += ''; } if (data2 && data2[0]) { let monYr = lastMonth + ' ' + lastYear; anchor2 = dPad + ''; anchor2 += (data2[1] && active) ? monYr + '' : '' + monYr; anchor2 += ''; } if (anchor1 == '' && anchor2 == '') sideHeader = sideHeader.replace('' } $('#omcMon').html(table); });