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 class Abrechnung extends IPSModule
{ {
public function Create() public function Create()
{ {
parent::Create(); parent::Create();
$this->RegisterPropertyString('Users', '[]'); $this->RegisterPropertyString('Users', '[]');
$this->RegisterPropertyString('PowerMeters', '[]'); $this->RegisterPropertyString('PowerMeters', '[]');
$this->RegisterPropertyString('WaterMeters', '[]'); $this->RegisterPropertyString('WaterMeters', '[]');
$this->RegisterPropertyString('Tariffs', '[]'); $this->RegisterPropertyString('Tariffs', '[]');
$this->RegisterVariableInteger('FromDate', 'Startdatum', '~UnixTimestamp', 1); $this->RegisterVariableInteger('FromDate', 'Startdatum', '~UnixTimestamp', 1);
$this->RegisterVariableInteger('ToDate', 'Enddatum', '~UnixTimestamp', 2); $this->RegisterVariableInteger('ToDate', 'Enddatum', '~UnixTimestamp', 2);
$this->RegisterVariableString('LastResult', 'Letzte Abrechnung', '', 3); $this->RegisterVariableString('LastResult', 'Letzte Abrechnung', '', 3);
$this->EnableAction('FromDate'); $this->EnableAction('FromDate');
$this->EnableAction('ToDate'); $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() public function ApplyChanges()
{ {
@@ -29,30 +40,38 @@ class Abrechnung extends IPSModule
IPS_LogMessage('Abrechnung', 'ApplyChanges() ausgeführt'); IPS_LogMessage('Abrechnung', 'ApplyChanges() ausgeführt');
} }
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
{ {
IPS_LogMessage('Abrechnung', "RequestAction aufgerufen: $Ident = $Value"); IPS_LogMessage('Abrechnung', "RequestAction: $Ident");
switch ($Ident) { switch ($Ident) {
case 'FromDate': case 'FromDate':
case 'ToDate': case 'ToDate':
SetValue($this->GetIDForIdent($Ident), $Value); SetValue($this->GetIDForIdent($Ident), $Value);
IPS_LogMessage('Abrechnung', "Wert für $Ident gesetzt: " . date('Y-m-d H:i', $Value)); break;
break;
case 'StartBilling': case 'StartBilling':
IPS_LogMessage('Abrechnung', 'Starte Abrechnung...'); IPS_LogMessage('Abrechnung', 'Starte Abrechnung...');
$pdfPath = $this->GenerateInvoices(); $pdfPath = $this->GenerateInvoices();
if ($pdfPath) {
SetValue($this->GetIDForIdent('LastResult'), basename($pdfPath)); if ($pdfPath && file_exists($pdfPath)) {
IPS_LogMessage('Abrechnung', "✅ Abrechnung erstellt: $pdfPath"); // 🔗 PDF in Media-Objekt speichern
echo "✅ Abrechnung erstellt: " . basename($pdfPath); $mediaID = @IPS_GetObjectIDByIdent('InvoicePDF', $this->InstanceID);
if ($mediaID) {
IPS_SetMediaFile($mediaID, $pdfPath, false);
IPS_LogMessage('Abrechnung', "✅ PDF in Media-Variable aktualisiert: $pdfPath");
} else { } else {
IPS_LogMessage('Abrechnung', '❌ Fehler bei der PDF-Erstellung'); IPS_LogMessage('Abrechnung', "⚠️ Keine Media-Variable gefunden, PDF bleibt im Dateisystem");
echo "❌ Fehler bei der PDF-Erstellung";
} }
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() public function GenerateInvoices()
{ {