no message
This commit is contained in:
+40
-6
@@ -100,6 +100,12 @@ class Abrechnung extends IPSModule
|
|||||||
private function RegisterTariffWebhook()
|
private function RegisterTariffWebhook()
|
||||||
{
|
{
|
||||||
$webhook = $this->GetTariffWebhookPath();
|
$webhook = $this->GetTariffWebhookPath();
|
||||||
|
|
||||||
|
if (method_exists($this, 'RegisterHook')) {
|
||||||
|
$this->RegisterHook($webhook);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$ids = @IPS_GetInstanceListByModuleID('{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}');
|
$ids = @IPS_GetInstanceListByModuleID('{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}');
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return;
|
return;
|
||||||
@@ -464,8 +470,7 @@ form.onsubmit=function(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
form.querySelector('input[name=payload]').value=JSON.stringify(rows);
|
form.querySelector('input[name=payload]').value=JSON.stringify(rows);
|
||||||
status.textContent='Speichern...';
|
status.textContent='Speichern gesendet.';
|
||||||
window.setTimeout(function(){status.textContent='Gesendet. Tabelle wird nach dem Speichern aktualisiert.';},800);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
@@ -484,10 +489,10 @@ form.onsubmit=function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
return '<tr>'
|
return '<tr>'
|
||||||
. '<td><select data-field="unit_type">' . $options . '</select></td>'
|
. '<td><select data-field="unit_type" name="unit_type[]">' . $options . '</select></td>'
|
||||||
. '<td><input data-field="start" type="date" value="' . $this->h($start) . '"></td>'
|
. '<td><input data-field="start" name="start[]" type="date" value="' . $this->h($start) . '"></td>'
|
||||||
. '<td><input data-field="end" type="date" value="' . $this->h($end) . '"></td>'
|
. '<td><input data-field="end" name="end[]" type="date" value="' . $this->h($end) . '"></td>'
|
||||||
. '<td><input data-field="price" class="num" type="number" min="0" step="0.001" value="' . $this->h($price) . '"></td>'
|
. '<td><input data-field="price" name="price[]" class="num" type="number" min="0" step="0.001" value="' . $this->h($price) . '"></td>'
|
||||||
. '<td><button type="button" class="danger" data-action="delete">Löschen</button></td>'
|
. '<td><button type="button" class="danger" data-action="delete">Löschen</button></td>'
|
||||||
. '</tr>';
|
. '</tr>';
|
||||||
}
|
}
|
||||||
@@ -543,6 +548,31 @@ form.onsubmit=function(){
|
|||||||
return count($tariffs) . ' Tarif(e) gespeichert.';
|
return count($tariffs) . ' Tarif(e) gespeichert.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function SaveTariffTableFromPost(array $post)
|
||||||
|
{
|
||||||
|
$types = $post['unit_type'] ?? [];
|
||||||
|
$starts = $post['start'] ?? [];
|
||||||
|
$ends = $post['end'] ?? [];
|
||||||
|
$prices = $post['price'] ?? [];
|
||||||
|
|
||||||
|
if (!is_array($types) || !is_array($starts) || !is_array($ends) || !is_array($prices)) {
|
||||||
|
throw new Exception('Ungültige Formularwerte.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
$count = max(count($types), count($starts), count($ends), count($prices));
|
||||||
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
$rows[] = [
|
||||||
|
'unit_type' => $types[$i] ?? '',
|
||||||
|
'start' => $starts[$i] ?? '',
|
||||||
|
'end' => $ends[$i] ?? '',
|
||||||
|
'price' => $prices[$i] ?? ''
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->SaveTariffTableFromPayload(json_encode($rows));
|
||||||
|
}
|
||||||
|
|
||||||
private function FormatDateInput($timestamp)
|
private function FormatDateInput($timestamp)
|
||||||
{
|
{
|
||||||
return $timestamp ? date('Y-m-d', (int)$timestamp) : '';
|
return $timestamp ? date('Y-m-d', (int)$timestamp) : '';
|
||||||
@@ -645,7 +675,11 @@ form.onsubmit=function(){
|
|||||||
$message = '';
|
$message = '';
|
||||||
try {
|
try {
|
||||||
$payload = $_POST['payload'] ?? '';
|
$payload = $_POST['payload'] ?? '';
|
||||||
|
if (trim((string)$payload) !== '') {
|
||||||
$message = $this->SaveTariffTableFromPayload($payload);
|
$message = $this->SaveTariffTableFromPayload($payload);
|
||||||
|
} else {
|
||||||
|
$message = $this->SaveTariffTableFromPost($_POST);
|
||||||
|
}
|
||||||
SetValue($this->GetIDForIdent('VisuTariffStatus'), $message);
|
SetValue($this->GetIDForIdent('VisuTariffStatus'), $message);
|
||||||
$this->UpdateTariffOverview();
|
$this->UpdateTariffOverview();
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user