no message

This commit is contained in:
2025-11-04 07:22:21 +01:00
parent 5ae542061c
commit 1c67b9f50b

View File

@@ -3,25 +3,36 @@ declare(strict_types=1);
class Abrechnung extends IPSModule
{
public function Create()
{
parent::Create();
public function Create()
{
parent::Create();
$this->RegisterPropertyString('Users', '[]');
$this->RegisterPropertyString('PowerMeters', '[]');
$this->RegisterPropertyString('WaterMeters', '[]');
$this->RegisterPropertyString('Tariffs', '[]');
$this->RegisterPropertyString('Users', '[]');
$this->RegisterPropertyString('PowerMeters', '[]');
$this->RegisterPropertyString('WaterMeters', '[]');
$this->RegisterPropertyString('Tariffs', '[]');
$this->RegisterVariableInteger('FromDate', 'Startdatum', '~UnixTimestamp', 1);
$this->RegisterVariableInteger('ToDate', 'Enddatum', '~UnixTimestamp', 2);
$this->RegisterVariableString('LastResult', 'Letzte Abrechnung', '', 3);
$this->EnableAction('FromDate');
$this->EnableAction('ToDate');
$this->RegisterVariableInteger('FromDate', 'Startdatum', '~UnixTimestamp', 1);
$this->RegisterVariableInteger('ToDate', 'Enddatum', '~UnixTimestamp', 2);
$this->RegisterVariableString('LastResult', 'Letzte Abrechnung', '', 3);
$this->EnableAction('FromDate');
$this->EnableAction('ToDate');
$this->RegisterScript('StartBilling', 'Abrechnung starten', "<?php IPS_RequestAction(" . $this->InstanceID . ", 'StartBilling', ''); ?>");
$this->RegisterScript('StartBilling', 'Abrechnung starten', "<?php IPS_RequestAction(" . $this->InstanceID . ", 'StartBilling', ''); ?>");
IPS_LogMessage('Abrechnung', 'Create() fertig ausgeführt');
// 🧾 Media-Objekt für PDF-Ergebnis anlegen (falls nicht vorhanden)
$mediaID = @IPS_GetObjectIDByIdent('InvoicePDF', $this->InstanceID);
if ($mediaID === false) {
$mediaID = IPS_CreateMedia(3); // 3 = PDF
IPS_SetParent($mediaID, $this->InstanceID);
IPS_SetIdent($mediaID, 'InvoicePDF');
IPS_SetName($mediaID, 'Letzte Rechnung');
IPS_SetMediaCached($mediaID, false);
$path = IPS_GetKernelDir() . 'media/Abrechnung_Letzte.pdf';
IPS_SetMediaFile($mediaID, $path, false);
IPS_LogMessage('Abrechnung', "Media-Datei erstellt: $path");
}
}
public function ApplyChanges()
{
@@ -29,30 +40,38 @@ class Abrechnung extends IPSModule
IPS_LogMessage('Abrechnung', 'ApplyChanges() ausgeführt');
}
public function RequestAction($Ident, $Value)
{
IPS_LogMessage('Abrechnung', "RequestAction aufgerufen: $Ident = $Value");
switch ($Ident) {
case 'FromDate':
case 'ToDate':
SetValue($this->GetIDForIdent($Ident), $Value);
IPS_LogMessage('Abrechnung', "Wert für $Ident gesetzt: " . date('Y-m-d H:i', $Value));
break;
public function RequestAction($Ident, $Value)
{
IPS_LogMessage('Abrechnung', "RequestAction: $Ident");
switch ($Ident) {
case 'FromDate':
case 'ToDate':
SetValue($this->GetIDForIdent($Ident), $Value);
break;
case 'StartBilling':
IPS_LogMessage('Abrechnung', 'Starte Abrechnung...');
$pdfPath = $this->GenerateInvoices();
if ($pdfPath) {
SetValue($this->GetIDForIdent('LastResult'), basename($pdfPath));
IPS_LogMessage('Abrechnung', "✅ Abrechnung erstellt: $pdfPath");
echo "✅ Abrechnung erstellt: " . basename($pdfPath);
case 'StartBilling':
IPS_LogMessage('Abrechnung', 'Starte Abrechnung...');
$pdfPath = $this->GenerateInvoices();
if ($pdfPath && file_exists($pdfPath)) {
// 🔗 PDF in Media-Objekt speichern
$mediaID = @IPS_GetObjectIDByIdent('InvoicePDF', $this->InstanceID);
if ($mediaID) {
IPS_SetMediaFile($mediaID, $pdfPath, false);
IPS_LogMessage('Abrechnung', "✅ PDF in Media-Variable aktualisiert: $pdfPath");
} else {
IPS_LogMessage('Abrechnung', '❌ Fehler bei der PDF-Erstellung');
echo "❌ Fehler bei der PDF-Erstellung";
IPS_LogMessage('Abrechnung', "⚠️ Keine Media-Variable gefunden, PDF bleibt im Dateisystem");
}
break;
}
SetValue($this->GetIDForIdent('LastResult'), basename($pdfPath));
echo "✅ Abrechnung erstellt: " . basename($pdfPath);
} else {
IPS_LogMessage('Abrechnung', '❌ Fehler bei der PDF-Erstellung');
echo "❌ Fehler bei der PDF-Erstellung";
}
break;
}
}
public function GenerateInvoices()
{