You could replace it like;
let html = ""
html += "<!doctype html><html lang='en'>"
html += "<style>body{font-family:arial;}.running{background:#22c55e;color:#fff;}.not-running{background:#ef4444;color:#fff;}table{border-collapse:collapse}td,th{border:1px solid #999;padding:4px;font-size:12px;}</style>"
html += `<h3>Online Downtime Report (Hosur) for the date ${msg.ddate}</h3>`
html += "<table>"
html += "<thead><tr><th>Machine</th><th>Time-From</th><th>Time-To</th><th>Duration</th><th>Reason 1</th><th>Reason 2</th></tr></thead>"
html += "<tbody>"
msg.payload.forEach((part) => {
if (part.col2 === undefined) {
const css_class = part.col1.match("not running") ? "not-running" : 'running'
html += `<tr><td colspan='6' class='${css_class}'>${part.col1}</td></tr>`
} else if (part.col1 !== 'Machine') {
const machine = msg.payload.filter(x=>x.col1.startsWith("SUM")).find(x=>x.col1.match(".*"+part.col1+".*"))
let css_class = "running"
if (machine && machine.col1.match('not running') ){
css_class = "not-running"
}
html += `<tr class="${css_class}"><td>${part.col1}</td><td>${part.col2}</td><td>${part.col3}</td><td>${part.col4}</td><td>${part.col5}</td><td>${part.col6}</td></tr>`
}
})
html += "</tbody></table></html>"
msg.payload = html
return msg
note that I made use of styles and apply them where applicable.
Note I would recommend to start with different input data.
The input already contains the sum, which originates from somewhere.