@@ -577,8 +577,9 @@ class PredbatTableCard extends HTMLElement {
577577
578578 let overallTotal = { } ;
579579 let dayTotal = { } ;
580+ let dayTotalCost = 0 ;
580581 const columnsWithTotals = [ "load-column" , "pv-column" , "car-column" , "iboost-column" , "net-power-column" ,
581- "cost-column" , "clip-column" , "co2kwh-column" , "co2kg-column" , "xload-column" , "limit-column" ] ;
582+ "cost-column" , "total-column" , " clip-column", "co2kwh-column" , "co2kg-column" , "xload-column" , "limit-column" ] ;
582583
583584 // before we display the rows, lets drop any that the user doesnt want.
584585
@@ -595,6 +596,7 @@ class PredbatTableCard extends HTMLElement {
595596 let newRow = document . createElement ( 'tr' ) ;
596597
597598 let isMidnight = false ;
599+ let currentCost ;
598600 columnsToReturn . forEach ( ( column , columnIndex ) => { // Use arrow function here
599601 if ( item [ column ] !== undefined ) {
600602 //console.log(column + " " + item[column]);
@@ -609,12 +611,24 @@ class PredbatTableCard extends HTMLElement {
609611
610612 newRow . appendChild ( newColumn ) ;
611613
614+ if ( column === "cost-column" )
615+ currentCost = parseFloat ( item [ column ] . value ) ;
616+
612617 if ( columnsWithTotals . includes ( column ) ) {
613- let val = parseFloat ( item [ column ] . value . replace ( / [ ⚊ ↘ ↗ → p ☀ ] / g, '' ) ) ;
614- if ( isNaN ( val ) ) val = 0 ;
615618
616- overallTotal [ column ] = ( overallTotal [ column ] || 0 ) + val ;
617- dayTotal [ column ] = ( dayTotal [ column ] || 0 ) + val ;
619+ if ( column === "total-column" ) {
620+ if ( isMidnight ) {
621+ let currentTotal = parseFloat ( item [ column ] . value . replace ( / [ ^ 0 - 9 . \- ] / g, "" ) ) ;
622+ overallTotal [ column ] = ( overallTotal [ column ] || 0 ) + ( currentTotal * 100 ) ;
623+ dayTotal [ column ] = ( currentTotal * 100 ) + currentCost ;
624+ }
625+ } else {
626+ let val = parseFloat ( item [ column ] . value . replace ( / [ ⚊ ↘ ↗ → p ☀ ] / g, '' ) ) ;
627+ if ( isNaN ( val ) ) val = 0 ;
628+
629+ overallTotal [ column ] = ( overallTotal [ column ] || 0 ) + val ;
630+ dayTotal [ column ] = ( dayTotal [ column ] || 0 ) + val ;
631+ }
618632 }
619633
620634 } else {
@@ -649,28 +663,33 @@ class PredbatTableCard extends HTMLElement {
649663
650664 if ( columnsWithTotals . includes ( column ) && column !== 'limit-column' ) {
651665 let returnTotal ;
652- if ( column === "cost-column" ) {
666+ if ( column === "cost-column" || column === "total-column" ) {
653667 let formattedCost = "" ;
654668
655669 if ( dayTotal [ column ] < 0 ) {
656670 formattedCost = `-£${ ( Math . abs ( dayTotal [ column ] ) / 100 ) . toFixed ( 2 ) } ` ;
671+ totalCell . style . color = "rgb(58, 238, 133)" ;
657672 } else {
658673 formattedCost = `£${ ( dayTotal [ column ] / 100 ) . toFixed ( 2 ) } ` ;
674+ totalCell . style . color = "rgb(241, 130, 97)" ;
659675 }
660676 returnTotal = `<b>${ formattedCost } </b>` ;
661677 } else
662678 returnTotal = `<b>${ dayTotal [ column ] . toFixed ( 2 ) } </b>` ;
679+
663680
664681 totalCell . innerHTML = returnTotal ;
665682 }
666683
667684 if ( column === "time-column" && index === 0 )
668- totalCell . innerHTML = `<b>TOTALS</b>` ;
685+ totalCell . innerHTML = `<b>TOTALS</b>` ;
686+
687+
669688
670689 dayTotalsRow . appendChild ( totalCell ) ;
671690
672691 } ) ;
673-
692+ console . log ( dayTotalsRow ) ;
674693 newTableBody . appendChild ( dayTotalsRow ) ;
675694 for ( let i = 0 ; i < 2 ; i ++ ) {
676695 newTableBody . appendChild ( this . createDividerRows ( columnsToReturn . length , hass . themes . darkMode ) ) ;
@@ -694,8 +713,9 @@ class PredbatTableCard extends HTMLElement {
694713 totalCell . innerHTML = `<b>PLAN TOTALS</b>` ;
695714
696715 if ( columnsWithTotals . includes ( column ) && column !== 'limit-column' ) {
716+
697717 let returnTotal ;
698- if ( column === "cost-column" ) {
718+ if ( column === "cost-column" || column === "total-column" ) {
699719 let formattedCost = "" ;
700720
701721 if ( overallTotal [ column ] < 0 ) {
@@ -3588,6 +3608,8 @@ convertTimeStampToFriendly(timestamp){
35883608
35893609 let isCostReset = false ;
35903610 let currentCost = 0 ;
3611+ let currentTotal = 0 ;
3612+ let currentCostSet = false , currentTotalSet = false ;
35913613
35923614 trElements . forEach ( ( trElement , index ) => {
35933615
@@ -3691,10 +3713,17 @@ convertTimeStampToFriendly(timestamp){
36913713 bgColor = null ;
36923714 }
36933715 }
3716+
36943717
36953718 if ( headerClassesArray [ headerIndex ] === "cost-column" && ! isNaN ( parseFloat ( tdElement . innerHTML ) ) ) {
36963719 currentCost = parseFloat ( tdElement . innerHTML ) ;
3720+ currentCostSet = true ;
36973721 }
3722+
3723+ if ( headerClassesArray [ headerIndex ] === "total-column" && ! isNaN ( parseFloat ( tdElement . innerHTML ) ) ) {
3724+ currentTotal = parseFloat ( tdElement . innerHTML . replace ( / [ ^ 0 - 9 . \- ] / g, "" ) ) ;
3725+ currentTotalSet = true ;
3726+ }
36983727
36993728 if ( headerClassesArray [ headerIndex ] === "cost-column" && ! isNaN ( parseFloat ( tdElement . innerHTML ) ) && isCostReset )
37003729 totalCostCalculated += parseFloat ( tdElement . innerHTML ) ;
@@ -3704,16 +3733,10 @@ convertTimeStampToFriendly(timestamp){
37043733
37053734 let totalCostString ;
37063735
3707- if ( this . config . fix_totals ) {
3708- let value = parseFloat ( tdElement . innerHTML . replace ( / [ ^ 0 - 9 . \- ] / g, "" ) ) ;
3709- totalCostString = "£" + ( value + ( currentCost / 100 ) ) . toFixed ( 3 ) ;
3710- }
3711-
37123736 // calculate new cost
37133737 if ( isCostReset )
3714- totalCostString = "£" + ( totalCostCalculated / 100 ) . toFixed ( 2 ) ;
3715-
3716- if ( ! isCostReset && ! this . config . fix_totals )
3738+ totalCostString = "£" + ( ( totalCostCalculated - currentCost ) / 100 ) . toFixed ( 2 ) ;
3739+ else
37173740 totalCostString = tdElement . innerHTML ;
37183741
37193742 newTRObject [ headerClassesArray [ headerIndex ] ] = { "value" : totalCostString , "color" : bgColor } ;
0 commit comments