Add daily production values.
This commit is contained in:
@@ -24,15 +24,17 @@ function build_date_dropdown(mysqli $db, string $table): array
|
|||||||
|
|
||||||
function get_aggregation(mysqli $db, string $table, $date): array
|
function get_aggregation(mysqli $db, string $table, $date): array
|
||||||
{
|
{
|
||||||
$value_query = 'SELECT date, meter_consumption, power_sensor, grid_feed FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
$value_query = 'SELECT date, meter_consumption, power_sensor, grid_feed, production_eg, production_og FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
||||||
$value_result = $db->query($value_query);
|
$value_result = $db->query($value_query);
|
||||||
|
|
||||||
$values = [];
|
$values = [];
|
||||||
while ($row = $value_result->fetch_assoc()) {
|
while ($row = $value_result->fetch_assoc()) {
|
||||||
|
$production = ($row['production_eg'] + $row['production_og']);
|
||||||
$values['date'][] = $row['date'];
|
$values['date'][] = $row['date'];
|
||||||
$values['meter_consumption'][] = $row['meter_consumption'];
|
$values['meter_consumption'][] = $row['meter_consumption'];
|
||||||
$values['power_sensor'][] = $row['power_sensor'];
|
$values['power_sensor'][] = $row['power_sensor'];
|
||||||
$values['grid_feed'][] = $row['grid_feed'];
|
$values['grid_feed'][] = $row['grid_feed'];
|
||||||
|
$values['production'][] = $production;
|
||||||
$values['min_meter'] = (isset($values['min_meter']) && $values['min_meter'] < $row['meter_consumption']) ? $values['min_meter'] : $row['meter_consumption'];
|
$values['min_meter'] = (isset($values['min_meter']) && $values['min_meter'] < $row['meter_consumption']) ? $values['min_meter'] : $row['meter_consumption'];
|
||||||
$values['max_meter'] = (isset($values['max_meter']) && $values['max_meter'] > $row['meter_consumption']) ? $values['max_meter'] : $row['meter_consumption'];
|
$values['max_meter'] = (isset($values['max_meter']) && $values['max_meter'] > $row['meter_consumption']) ? $values['max_meter'] : $row['meter_consumption'];
|
||||||
$values['avg_meter'] += $row['meter_consumption'];
|
$values['avg_meter'] += $row['meter_consumption'];
|
||||||
@@ -42,11 +44,15 @@ function get_aggregation(mysqli $db, string $table, $date): array
|
|||||||
$values['min_feed'] = (isset($values['min_feed']) && $values['min_feed'] < $row['grid_feed']) ? $values['min_feed'] : $row['grid_feed'];
|
$values['min_feed'] = (isset($values['min_feed']) && $values['min_feed'] < $row['grid_feed']) ? $values['min_feed'] : $row['grid_feed'];
|
||||||
$values['max_feed'] = (isset($values['max_feed']) && $values['max_feed'] > $row['grid_feed']) ? $values['max_feed'] : $row['grid_feed'];
|
$values['max_feed'] = (isset($values['max_feed']) && $values['max_feed'] > $row['grid_feed']) ? $values['max_feed'] : $row['grid_feed'];
|
||||||
$values['avg_feed'] += $row['grid_feed'];
|
$values['avg_feed'] += $row['grid_feed'];
|
||||||
|
$values['min_production'] = (isset($values['min_production']) && $values['min_production'] < $production) ? $values['min_production'] : $production;
|
||||||
|
$values['max_production'] = (isset($values['max_production']) && $values['max_production'] > $production) ? $values['max_production'] : $production;
|
||||||
|
$values['avg_production'] += $production;
|
||||||
}
|
}
|
||||||
|
|
||||||
$values['avg_meter'] /= count($values['meter_consumption']);
|
$values['avg_meter'] /= count($values['meter_consumption']);
|
||||||
$values['avg_power'] /= count($values['power_sensor']);
|
$values['avg_power'] /= count($values['power_sensor']);
|
||||||
$values['avg_feed'] /= count($values['grid_feed']);
|
$values['avg_feed'] /= count($values['grid_feed']);
|
||||||
|
$values['avg_production'] /= count($values['production']);
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
@@ -118,4 +124,17 @@ function get_last_value(mysqli $db, string $table, $date): float
|
|||||||
$data = $value_result->fetch_assoc();
|
$data = $value_result->fetch_assoc();
|
||||||
|
|
||||||
return floatval($data['last_value']) / 1000;
|
return floatval($data['last_value']) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_production_values_for_month(mysqli $db, string $table, $date)
|
||||||
|
{
|
||||||
|
$value_query = 'SELECT date, production_og, production_eg FROM ' . $table . ' WHERE date LIKE "' . $date . '%" ORDER BY date ASC;';
|
||||||
|
$value_result = $db->query($value_query);
|
||||||
|
$production_values = [];
|
||||||
|
|
||||||
|
while ($row = $value_result->fetch_assoc()) {
|
||||||
|
$production_values[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $production_values;
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ for ($date_diff = $interval->days; $date_diff > 0; $date_diff--) {
|
|||||||
$grid_feed = 0;
|
$grid_feed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$aggregation_query = 'INSERT INTO ' . $local_table . ' (`date`, `meter_consumption`, `power_sensor`, `grid_feed`, `last_value`) VALUES ("' . $date->format('Y-m-d') . '", ' . $meter_consumption . ', ' . $power_sensor . ', ' . $grid_feed . ', ' . $consumption_end . ');';
|
$aggregation_query = 'INSERT INTO ' . $local_table . ' (`date`, `meter_consumption`, `power_sensor`, `grid_feed`, `last_value`, `production_eg`, `production_og`) VALUES ("' . $date->format('Y-m-d') . '", ' . $meter_consumption . ', ' . $power_sensor . ', ' . $grid_feed . ', ' . $consumption_end . ', 0, 0);';
|
||||||
|
|
||||||
$local_db->query($aggregation_query);
|
$local_db->query($aggregation_query);
|
||||||
}
|
}
|
||||||
|
|||||||
49
public/css/layout.css
Normal file
49
public/css/layout.css
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
div > span {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.grid-container {
|
||||||
|
display: grid;
|
||||||
|
column-gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.color-1 {
|
||||||
|
background-color: #375BEB;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.color-2 {
|
||||||
|
background-color: #90EB36;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.color-3 {
|
||||||
|
background-color: #EB5F36;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.color-4 {
|
||||||
|
background-color: #DAE32D;
|
||||||
|
}
|
||||||
|
|
||||||
|
form > div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
text-align: center;
|
||||||
|
background-color: rgb(239, 239, 239);
|
||||||
|
border: 2px outset rgb(0, 0 , 0);
|
||||||
|
text-decoration: none;
|
||||||
|
color: rgb(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart-container {
|
||||||
|
position: relative;
|
||||||
|
width: 95vw;
|
||||||
|
height: 95vh;
|
||||||
|
}
|
||||||
131
public/index.php
131
public/index.php
@@ -29,61 +29,17 @@ $month_production = get_month_production($local_db, $table_production, $chosen_d
|
|||||||
$year_production = get_year_production($local_db, $table_production, $chosen_date);
|
$year_production = get_year_production($local_db, $table_production, $chosen_date);
|
||||||
$last_value = get_last_value($local_db, $table_aggregation, $chosen_date);
|
$last_value = get_last_value($local_db, $table_aggregation, $chosen_date);
|
||||||
|
|
||||||
$colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<title>Consumption values</title>
|
<title>Consumption values</title>
|
||||||
<style>
|
<link rel="stylesheet" href="/css/layout.css"/>
|
||||||
body {
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
display: inline-block;
|
|
||||||
width: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.color-1 {
|
|
||||||
background-color: <?php echo $colors[0]; ?>;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.color-2 {
|
|
||||||
background-color: <?php echo $colors[1]; ?>;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.color-3 {
|
|
||||||
background-color: <?php echo $colors[2]; ?>;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.color-4 {
|
|
||||||
background-color: <?php echo $colors[3]; ?>;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.color {
|
|
||||||
display: inline-block;
|
|
||||||
width: 40px;
|
|
||||||
height: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span {
|
|
||||||
display: inline-block;
|
|
||||||
width: 200px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
#chart-container {
|
|
||||||
position: relative;
|
|
||||||
width: 80vw;
|
|
||||||
height: 70vh;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form action="/index.php" method="post" style="display: inline-block;float: left; margin-right: 100px;">
|
<form style="display: grid; grid-template-columns: 5% 5% 20% 5%; gap: 10px;" action="/index.php" method="post">
|
||||||
<select name="date" onchange="submit();">
|
<label for="date">Datum</label>
|
||||||
|
<select name="date" id="date" onchange="submit();">
|
||||||
<?php
|
<?php
|
||||||
foreach ($dates as $date) {
|
foreach ($dates as $date) {
|
||||||
$selected = ($date == $chosen_date) ? ' selected="selected"' : '';
|
$selected = ($date == $chosen_date) ? ' selected="selected"' : '';
|
||||||
@@ -91,51 +47,35 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
<span></span>
|
||||||
|
<a class="button" href="production.php">Werte setzen</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form action="/index.php" method="post">
|
<div style="display: grid; grid-template-columns: 5% 15% 15% 15% 15% 15% 15%; gap: 2px 10px; margin-top: 5px; border-top: 2px solid gray; padding-top: 5px;">
|
||||||
<input type="hidden" name="date" value="<?php echo $chosen_date; ?>"/>
|
|
||||||
<input type="hidden" name="action" value="set_values"/>
|
|
||||||
<label style="text-align: right;" for="EG">EG</label>
|
|
||||||
<input type="number" step="0.001" name="eg" id="EG" value="<?php echo $month_production['eg']; ?>"/>
|
|
||||||
<label style="text-align: right;" for="OG">OG</label>
|
|
||||||
<input type="number" step="0.001" name="og" id="OG" value="<?php echo $month_production['og']; ?>"/>
|
|
||||||
<label style="text-align: right;" for="price">Preis</label>
|
|
||||||
<input type="number" step="0.01" name="price" id="price" value="<?php echo $month_production['price']; ?>"/>
|
|
||||||
<button type="submit">Werte setzen</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div style="margin-top: 20px; font-weight: bold;">
|
|
||||||
<label>Messungen</label>
|
|
||||||
<span class="color"></span>
|
<span class="color"></span>
|
||||||
<span>Monat</span>
|
<label><b>Messungen</b></label>
|
||||||
<span>Jahr</span>
|
<span><b>Monat</b></span>
|
||||||
<span>Min</span>
|
<span><b>Jahr</b></span>
|
||||||
<span>Max</span>
|
<span><b>Min</b></span>
|
||||||
<span>Durchschnitt</span>
|
<span><b>Max</b></span>
|
||||||
</div>
|
<span><b>Durchschnitt</b></span>
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color color-1"></span>
|
<span class="color color-1"></span>
|
||||||
<label>Verbrauch Zählerstand</label>
|
<label>Verbrauch</label>
|
||||||
<span><?php echo number_format($month_values['meter_consumption'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($month_values['meter_consumption'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($year_values['meter_consumption'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($year_values['meter_consumption'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['min_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['min_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['max_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['max_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['avg_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['avg_meter'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color color-2"></span>
|
<span class="color color-2"></span>
|
||||||
<label>Verbrauch berechnet</label>
|
<label>Berechnet</label>
|
||||||
<span><?php echo number_format($month_values['power_sensor'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($month_values['power_sensor'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($year_values['power_sensor'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($year_values['power_sensor'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['min_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['min_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['max_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['max_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['avg_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['avg_power'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color color-3"></span>
|
<span class="color color-3"></span>
|
||||||
<label>Einspeisung</label>
|
<label>Einspeisung</label>
|
||||||
<span><?php echo number_format($month_values['grid_feed'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($month_values['grid_feed'], 3, ',', '.'); ?> KWh</span>
|
||||||
@@ -143,46 +83,42 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
|
|||||||
<span><?php echo number_format($data['min_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['min_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['max_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['max_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($data['avg_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($data['avg_feed'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color color-4"></span>
|
<span class="color color-4"></span>
|
||||||
<label>Produktion EG</label>
|
<label>Produktion EG</label>
|
||||||
<span><?php echo number_format($month_production['eg'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($month_production['eg'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($year_production['eg'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($year_production['eg'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span></span>
|
<span></span>
|
||||||
<span></span>
|
<span></span>
|
||||||
<span><?php echo number_format($month_production['eg'] / count($data['date']), 3, ',', '.'); ?> kWh</span>
|
<span></span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="border-bottom: 1px solid black;">
|
|
||||||
<span class="color color-4"></span>
|
<span class="color color-4"></span>
|
||||||
<label>Produktion OG</label>
|
<label>Produktion OG</label>
|
||||||
<span><?php echo number_format($month_production['og'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($month_production['og'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($year_production['og'], 3, ',', '.'); ?> KWh</span>
|
<span><?php echo number_format($year_production['og'], 3, ',', '.'); ?> KWh</span>
|
||||||
<span></span>
|
<span><?php echo number_format($data['min_production'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span></span>
|
<span><?php echo number_format($data['max_production'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
<span><?php echo number_format($month_production['og'] / count($data['date']), 3, ',', '.'); ?> kWh</span>
|
<span><?php echo number_format($data['avg_production'] / 1000, 3, ',', '.'); ?> KWh</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color"></span>
|
<span class="color"></span>
|
||||||
<label><b>Ersparnis</b></label>
|
<label><b>Ersparnis</b></label>
|
||||||
<span><b><?php echo number_format(($month_production['eg'] + $month_production['og'] - $month_values['grid_feed']) * $month_production['price'] / 100, 2, ',', '.'); ?> €</b></span>
|
<span><b><?php echo number_format(($month_production['eg'] + $month_production['og'] - $month_values['grid_feed']) * $month_production['price'] / 100, 2, ',', '.'); ?> €</b></span>
|
||||||
<span><b><?php echo number_format(($year_production['eg_price'] + $year_production['og_price'] - array_sum($grid_feed_by_month)), 2, ',', '.'); ?> €</b></span>
|
<span><b><?php echo number_format(($year_production['eg_price'] + $year_production['og_price'] - array_sum($grid_feed_by_month)), 2, ',', '.'); ?> €</b></span>
|
||||||
</div>
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color"></span>
|
<span class="color"></span>
|
||||||
<label><b>Eigenverbrauch</b></label>
|
<label><b>Eigenverbrauch</b></label>
|
||||||
<span><b><?php echo ($month_production['eg'] + $month_production['og'] > 0) ? number_format(100 - $month_values['grid_feed'] * 100 / ($month_production['eg'] + $month_production['og']), 2, ',', '.') : 0; ?> %</b></span>
|
<span><b><?php echo ($month_production['eg'] + $month_production['og'] > 0) ? number_format(100 - $month_values['grid_feed'] * 100 / ($month_production['eg'] + $month_production['og']), 2, ',', '.') : 0; ?> %</b></span>
|
||||||
<span><b><?php echo number_format(100 - $year_values['grid_feed'] * 100 / ($year_production['eg'] + $year_production['og']), 2, ',', '.'); ?> %</b></span>
|
<span><b><?php echo number_format(100 - $year_values['grid_feed'] * 100 / ($year_production['eg'] + $year_production['og']), 2, ',', '.'); ?> %</b></span>
|
||||||
</div>
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
|
||||||
<div>
|
|
||||||
<span class="color"></span>
|
<span class="color"></span>
|
||||||
<label><b>Letzter Zählerstand</b></label>
|
<label><b>Zählerstand</b></label>
|
||||||
<span><b><?php echo number_format($last_value, 3, ',', '.'); ?> kWh</b></span>
|
<span><b><?php echo number_format($last_value, 1, ',', '.'); ?> kWh</b></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="chart-container">
|
<div id="chart-container">
|
||||||
@@ -201,17 +137,22 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
|
|||||||
{
|
{
|
||||||
label: 'Verbrauch Zählerstand',
|
label: 'Verbrauch Zählerstand',
|
||||||
data: <?php echo json_encode($data['meter_consumption']); ?>,
|
data: <?php echo json_encode($data['meter_consumption']); ?>,
|
||||||
backgroundColor: '<?php echo $colors[0]; ?>',
|
backgroundColor: '#375BEB',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Verbrauch berechnet',
|
label: 'Verbrauch berechnet',
|
||||||
data: <?php echo json_encode($data['power_sensor']); ?>,
|
data: <?php echo json_encode($data['power_sensor']); ?>,
|
||||||
backgroundColor: '<?php echo $colors[1]; ?>',
|
backgroundColor: '#90EB36',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Einspeisung',
|
label: 'Einspeisung',
|
||||||
data: <?php echo json_encode($data['grid_feed']); ?>,
|
data: <?php echo json_encode($data['grid_feed']); ?>,
|
||||||
backgroundColor: '<?php echo $colors[2]; ?>',
|
backgroundColor: '#EB5F36',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Erzeugung',
|
||||||
|
data: <?php echo json_encode($data['production']); ?>,
|
||||||
|
backgroundColor: '#DAE32D',
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -222,4 +163,4 @@ $colors = ['#375BEB', '#90EB36', '#EB5F36', '#DAE32D'];
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
88
public/production.php
Normal file
88
public/production.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$app = require(__DIR__ . '/../bootstrap.php');
|
||||||
|
$local_db = $app['local_db'];
|
||||||
|
|
||||||
|
$table_aggregation = $app['config']['local']['table_aggregation'];
|
||||||
|
$table_production = $app['config']['local']['table_production'];
|
||||||
|
|
||||||
|
require_once(__DIR__ . '/../functions/functions.php');
|
||||||
|
|
||||||
|
if (isset($_POST['action']) && $_POST['action'] == 'set_values') {
|
||||||
|
$sum_eg = 0;
|
||||||
|
$sum_og = 0;
|
||||||
|
|
||||||
|
foreach ($_POST['values'] as $key => $value) {
|
||||||
|
$update_query = 'UPDATE ' . $table_aggregation . ' SET production_eg = ' . $value['production_eg'] . ', production_og = ' . $value['production_og'] . ' WHERE `date` = "' . $key . '" LIMIT 1;';
|
||||||
|
$local_db->query($update_query);
|
||||||
|
$sum_eg += $value['production_eg'] / 1000;
|
||||||
|
$sum_og += $value['production_og'] / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
$check_query = 'SELECT date FROM ' . $table_production . ' WHERE date = "' . $_POST['date'] . '-01";';
|
||||||
|
$check_result = $local_db->query($check_query);
|
||||||
|
|
||||||
|
if ($check_result->num_rows === 0) {
|
||||||
|
$query = 'INSERT INTO ' . $table_production . ' (date, eg, og, price) VALUES ("' . $_POST['date'] . '-01", ' . $sum_eg . ', ' . $sum_og . ', ' . $_POST['price'] . ');';
|
||||||
|
} else {
|
||||||
|
$query = 'UPDATE ' . $table_production . ' SET eg = "' . $sum_eg . '", og = "' . $sum_og . '", price = "' . $_POST['price'] . '" WHERE date = "' . $_POST['date'] . '-01";';
|
||||||
|
}
|
||||||
|
$local_db->query($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dates = build_date_dropdown($local_db, $table_aggregation);
|
||||||
|
$chosen_date = (isset($_POST['date'])) ? $_POST['date'] : $dates[0];
|
||||||
|
$production_values = get_production_values_for_month($local_db, $table_aggregation, $chosen_date);
|
||||||
|
$month_production = get_month_production($local_db, $table_production, $chosen_date);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<title>Consumption values</title>
|
||||||
|
<link rel="stylesheet" href="/css/layout.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form style="display: grid; grid-template-columns: 5% 5% 5% 5% 5%; gap: 10px; border-bottom: 1px solid black;" action="/production.php" method="post">
|
||||||
|
<label for="date">Datum</label>
|
||||||
|
<select name="date" id="date" onchange="submit();">
|
||||||
|
<?php
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
$selected = ($date == $chosen_date) ? ' selected="selected"' : '';
|
||||||
|
echo '<option value="' . $date . '"' . $selected . '>' . $date . '</option>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<a class="button" href="index.php">Übersicht</a>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form action="production.php" method="post"
|
||||||
|
style="display: grid; grid-template-columns: 5% 5% 5% 5% 5%; gap: 2px 10px; margin-top: 10px;">
|
||||||
|
<?php
|
||||||
|
foreach ($production_values as $daily_production) {
|
||||||
|
?>
|
||||||
|
<span><?php echo $daily_production['date']; ?></span>
|
||||||
|
<label style="text-align: right;" for="production_eg[<?php echo $daily_production['date']; ?>]">EG</label>
|
||||||
|
<input type="number" step="0.01" name="values[<?php echo $daily_production['date']; ?>][production_eg]"
|
||||||
|
id="production_eg[<?php echo $daily_production['date']; ?>]"
|
||||||
|
value="<?php echo $daily_production['production_eg']; ?>"/>
|
||||||
|
<label style="text-align: right;" for="production_og[<?php echo $daily_production['date']; ?>]">OG</label>
|
||||||
|
<input type="number" step="0.01" name="values[<?php echo $daily_production['date']; ?>][production_og]"
|
||||||
|
id="production_og[<?php echo $daily_production['date']; ?>]"
|
||||||
|
value="<?php echo $daily_production['production_og']; ?>"/>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<span>Preis</span>
|
||||||
|
<label style="text-align: right;">Cent / kWh</label>
|
||||||
|
<input type="number" step="0.01" name="price" value="<?php echo $month_production['price']; ?>"/>
|
||||||
|
<span></span>
|
||||||
|
<button type="submit">Speichern</button>
|
||||||
|
<input type="hidden" name="action" value="set_values"/>
|
||||||
|
<input type="hidden" name="date" value="<?php echo $chosen_date; ?>"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user