From 7ae887c0841bfd53a4f5afae8ec3f841bedb8a14 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Wed, 20 Jul 2022 11:11:31 +0200 Subject: [PATCH] calculate costs in backend --- ladelog.sh | 6 ++++-- web/logging/chargelog/ladelog.js | 15 +++++++++------ web/logging/chargelog/ladelog.php | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ladelog.sh b/ladelog.sh index 9ec79c71d..1a329c6f1 100755 --- a/ladelog.sh +++ b/ladelog.sh @@ -233,8 +233,10 @@ processChargepoint(){ else lademoduslogvalue=$lademodus fi - openwbDebugLog "CHARGESTAT" 1 "start=$start; end=$jetzt; timeCharged=${ladedauer}m ($ladedauertext); energyCharged=${bishergeladen}kWh; rangeCharged=${gelr}km; averagePower=${ladegeschw}kW" - sed -i "1i$start,$jetzt,$gelr,$bishergeladen,$ladegeschw,$ladedauertext,$chargePointNumber,$lademoduslogvalue,$rfid" "$monthlyfile" + # calculate costs + kosten=$(echo "scale=2;$bishergeladen * $preisjekwh" |bc) + openwbDebugLog "CHARGESTAT" 1 "start=$start; end=$jetzt; timeCharged=${ladedauer}m ($ladedauertext); energyCharged=${bishergeladen}kWh; rangeCharged=${gelr}km; averagePower=${ladegeschw}kW; costs=${kosten}" + sed -i "1i$start,$jetzt,$gelr,$bishergeladen,$ladegeschw,$ladedauertext,$chargePointNumber,$lademoduslogvalue,$rfid,$kosten" "$monthlyfile" # send push message if configured if (( pushbenachrichtigung == 1 )) ; then if (( pushbstopl == 1 )) ; then diff --git a/web/logging/chargelog/ladelog.js b/web/logging/chargelog/ladelog.js index 8caf0f198..59427cf7e 100644 --- a/web/logging/chargelog/ladelog.js +++ b/web/logging/chargelog/ladelog.js @@ -252,7 +252,6 @@ function putladelogtogether() { var totalprice=0; testout.forEach(function(row) { - var price = "0" rowcount+=1; content += ""; var cellcount=0; @@ -270,10 +269,9 @@ function putladelogtogether() { content += "" + km.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0}) + ""; break; case 4: // geladene kWh - totalkwh = parseFloat(totalkwh) + parseFloat(cell); - price = parseFloat(cell) * PriceForKWh; - totalprice = parseFloat(totalprice) + parseFloat(price); - content += "" + parseFloat(cell).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + ""; + var kWh = parseFloat(cell); + totalkwh += kWh; + content += "" + kWh.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + ""; break; case 5: // Ladeleistung kW var kW = parseFloat(cell); @@ -319,11 +317,16 @@ function putladelogtogether() { } content += ""; break; + // 9: RFID-Tag + case 10: + var price = parseFloat(cell); + totalprice += price; + content += "" + price.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "€" ; + break; default: content += "" + cell + ""; } }); - content += "" + price.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "€" ; content += ""; }); diff --git a/web/logging/chargelog/ladelog.php b/web/logging/chargelog/ladelog.php index 8fcaac56a..4ed3f76f4 100644 --- a/web/logging/chargelog/ladelog.php +++ b/web/logging/chargelog/ladelog.php @@ -39,7 +39,7 @@ - +