-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomEnergyPrices.php
76 lines (63 loc) · 3.77 KB
/
customEnergyPrices.php
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
<?php
include_once("lib/appLibLoader.php");
// Prepare DB
$db = Database::getInstance();
$energyPriceTbl = new EnergyPriceTable($db->getPdoConnection());
$hourlyEnergyDataTbl = new HourlyEnergyDataTable($db->getPdoConnection());
if (isset($_POST) && sizeof($_POST)) {
if (StringHelper::formGetBool("performDelete") == true) {
$idPriceRowToDelete = StringHelper::formGetInt('priceRowId', null);
$customRow = $energyPriceTbl->getCustomRow($idPriceRowToDelete);
if ($customRow != null) {
$energyPriceTbl->deleteCustomRow($idPriceRowToDelete);
$successMsg = "Der Eintrag für den Zeitraum zwischen ".TimeHelper::FormatDate($customRow->getTimestampFrom())
." und ".TimeHelper::FormatDate($customRow->getTimestampTo())." wurde gelöscht."
."<br>Es wurden keine Preisdaten bei den Energiewerten angepasst.";
} else {
$errorMsg = "Konnte keine Eintrag finden.";
}
} else {
// Save
$idPriceRow = StringHelper::formGetInt('priceRowId', null);
$timestampFrom = StringHelper::formGetDate('timestampFrom');
$timestampTo = StringHelper::formGetDate('timestampTo');
$outCentPricePerKwh = StringHelper::formGetFloat('outCentPricePerKwh');
$inCentPricePerKwh = StringHelper::formGetFloat('inCentPricePerKwh');
$doesTimeOverlap = $energyPriceTbl->doesTimeOverlap($idPriceRow, $timestampFrom, $timestampTo);
if (($timestampFrom == null) || ($timestampTo == null) || ($outCentPricePerKwh == null) || ($inCentPricePerKwh == null)) {
$errorMsg = "Bitte den Zeitraum und die Preise angeben.";
} elseif ($doesTimeOverlap) {
$errorMsg = "Es gibt bereits einen Preiseintrag, welche innerhalb des Zeitraums ".TimeHelper::FormatDate($timestampFrom)." und ".TimeHelper::FormatDate($timestampTo)." gültig ist.";
} else {
$energyPriceRow = new EnergyPriceRow($idPriceRow, $timestampFrom, $timestampTo, $outCentPricePerKwh / 1000, $inCentPricePerKwh / 1000, 1);
$succes = $idPriceRow != null ? $energyPriceTbl->updateCustomData($energyPriceRow) : $energyPriceTbl->insertCustomData($energyPriceRow);
if (! $succes) {
$errorMsg = $energyPriceTbl->getError();
} else {
$updateTimestampFrom = $timestampFrom . " 00:00:00";
$updateTimestampTo = $timestampTo." 23:59:59";
$hourlyEnergyDataTbl->updatePricesForTimeRange($updateTimestampFrom, $updateTimestampTo, $outCentPricePerKwh / 1000, $inCentPricePerKwh / 1000);
$successMsg = "Die Preisdaten wurden gespeichert und die Preise für den Zeitraum zwischen "
.TimeHelper::formatDateTime($updateTimestampFrom, true)." und ".TimeHelper::formatDateTime($updateTimestampTo, true)
."<br> auf den Einkaufspreis von ".StringHelper::formatCentCurrency($outCentPricePerKwh)
." und dem Verkaufspreis von ".StringHelper::formatCentCurrency($inCentPricePerKwh)." angepasst.";
$idPriceRow = null;
$timestampFrom = "";
$timestampTo = "";
$outCentPricePerKwh = "";
$inCentPricePerKwh = "";
}
}
}
}
$customDataList = $energyPriceTbl->getCustomAndAutomaticPriceRows();
// configure VIEW
$pageTitle = "Eigene Preisdaten";
$jsHeaderFiles = ["/js/utils.js"];
$jsFooterFiles = ["/js/custom-price-values/documentReady.js"];
$cssFiles = [];
$jsVars = [];
$partialTop = "views/pages/custom-price-values/inputform.phtml";
$partialBottom = "views/pages/custom-price-values/values-list.phtml";
include("views/partials/layout.phtml");
?>