Skip to content

Commit 1e39861

Browse files
authored
Improve total column handling
Refactor total column calculations and logging.
1 parent 40e285b commit 1e39861

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

predbat-table-card.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,16 @@ class PredbatTableCard extends HTMLElement {
619619
if(columnsWithTotals.includes(column)){
620620

621621
if(column === "total-column"){
622+
let currentTotal = parseFloat(item[column].value.replace(/[^0-9.\-]/g, ""));
623+
if (isNaN(currentTotal)) currentTotal = 0;
624+
625+
overallTotal[column] = (currentTotal*100)+currentCost;
626+
622627
if(isMidnight){
623-
let currentTotal = parseFloat(item[column].value.replace(/[^0-9.\-]/g, ""));
624-
if (isNaN(currentTotal)) currentTotal = 0;
625-
628+
626629
overallTotal[column] = (overallTotal[column] || 0) + (currentTotal*100);
627630
dayTotal[column] = (currentTotal*100)+currentCost;
631+
628632
}
629633
} else {
630634
let val = parseFloat(item[column].value.replace(/[p]/g, ''));
@@ -648,6 +652,9 @@ class PredbatTableCard extends HTMLElement {
648652
}
649653
});
650654

655+
console.log("overallTotalDay:", dayTotal);
656+
console.log("overallTotalPlan:", overallTotal);
657+
651658
newTableBody.appendChild(newRow);
652659

653660
if(isMidnight){
@@ -720,6 +727,10 @@ class PredbatTableCard extends HTMLElement {
720727

721728
let returnTotal;
722729
if(column === "cost-column" || column === "total-column"){
730+
731+
if(column === "total-column" && dayTotal[column])
732+
overallTotal[column] = overallTotal[column] + dayTotal[column];
733+
723734
let formattedCost = "";
724735

725736
if (overallTotal[column] < 0) {

0 commit comments

Comments
 (0)