-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomEnergyValues.php
More file actions
77 lines (64 loc) · 3.69 KB
/
customEnergyValues.php
File metadata and controls
77 lines (64 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// NrgHomeVis - Energievisualisierung für zu Hause | Repository: <https://github.com/SvenoF54/home-energy-visualizer>
// Licensed under the GNU GPL v3.0 - see <https://www.gnu.org/licenses/gpl-3.0.en.html>
include_once("lib/appLibLoader.php");
// Defaults
$actualConfig = Configuration::getInstance()->customEnergyValuesPage();
$dateOrMonth = $actualConfig->getDefaultMonthOrYear();
// Prepare DB
$hourlyEnergyDataTbl = HourlyEnergyDataTable::getInstance();
if (isset($_POST) && sizeof($_POST)) {
if (StringHelper::formGetBool("performDelete") == true) {
// Delete
$timestamp = StringHelper::formGetString("timestampDelete");
$customRow = $hourlyEnergyDataTbl->getCustomRow($timestamp);
if ($customRow != null) {
$timestampType = $customRow->getTimestampType();
$timestampRaw = $customRow->getTimestampFrom();
$timestampHtml = $timestampType == "month" ? substr(TimeHelper::formatDate($customRow->getTimestampFrom()), 3) : TimeHelper::formatDate($customRow->getTimestampFrom());
$hourlyEnergyDataTbl->deleteCustomRow($timestamp);
$successMsg = "Der Eintrag für den $timestampHtml wurde gelöscht.";
} else {
$errorMsg = "Konnte keine Eintrag finden.";
}
} else {
// Save
$dateOrMonth = StringHelper::formGetString('timestampType', 'month');
$timestamp = $dateOrMonth == "month" ? StringHelper::formGetMonthYear('timestamp') : StringHelper::formGetDate('timestamp');
$timestampFrom = TimeHelper::formatForDatabase($timestamp);
$timestampTo = $dateOrMonth == "month" ? TimeHelper::formatForDatabase(TimeHelper::getEndOfMonth($timestampFrom, true)) : TimeHelper::formatForDatabase(TimeHelper::getEndOfDay($timestampFrom, true));
$outCentPricePerKwh = StringHelper::formGetFloat('outCentPricePerKwh');
$inCentPricePerKwh = StringHelper::formGetFloat('inCentPricePerKwh');
$consumptionKwh = StringHelper::formGetFloat('consumption', 0);
$feedInKwh = StringHelper::formGetFloat('feedIn', 0);
$producedPowerKwh = StringHelper::formGetFloat('producedPower', 0);
$producedPowerPhases = StringHelper::formGetStringArray('phases', array(1, 2, 3));
if (($timestamp == null) || ($outCentPricePerKwh == null) || ($inCentPricePerKwh == null) || ($consumptionKwh == 0 && $feedInKwh == 0 && $producedPowerKwh == 0)) {
$errorMsg = "Bitte den Monat, den Preis und mindestens einen Energiewert angeben.";
} else {
$customValSet = new CustomEnergyValueSet($timestampFrom, $timestampTo, $outCentPricePerKwh / 1000, $inCentPricePerKwh / 1000);
$customValSet->setEmPower($consumptionKwh * 1000, -$feedInKwh * 1000);
$customValSet->setPmPower($producedPowerKwh * 1000, in_array(1, $producedPowerPhases), in_array(2, $producedPowerPhases), in_array(3, $producedPowerPhases));
$succes = $hourlyEnergyDataTbl->saveCustomData($customValSet);
if (! $succes) {
$errorMsg = $hourlyEnergyDataTbl->getError();
} else {
$successMsg = "Die Daten wurden gespeichert.";
$consumptionKwh = "";
$feedInKwh = "";
$producedPowerKwh = "";
}
}
}
}
$customDataList = $hourlyEnergyDataTbl->getCustomDataList();
// configure VIEW
$pageTitle = "Eigene Stromdaten";
$jsHeaderFiles = ["/js/utils.js"];
$jsFooterFiles = ["/js/custom-energy-values/documentReady.js"];
$cssFiles = [];
$jsVars = [];
$partialTop = "views/pages/custom-energy-values/inputform.phtml";
$partialBottom = "views/pages/custom-energy-values/values-list.phtml";
include("views/partials/layout.phtml");
?>