213 lines
6.2 KiB
PHP
213 lines
6.2 KiB
PHP
<?php
|
|
/* Copyright (C) 2025 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* \file class/actions_epcqr.class.php
|
|
* \ingroup epcqr
|
|
* \brief Hook-Klasse für QR-Code und Bild-Integration
|
|
*/
|
|
|
|
/**
|
|
* Hook-Klasse für EPCQR-Modul
|
|
* Verarbeitet ODT-Dokumente und fügt Bilder/QR-Codes ein
|
|
*/
|
|
class ActionsEpcqr
|
|
{
|
|
private $db;
|
|
private $conf;
|
|
private $langs;
|
|
public $errors = array();
|
|
public $resprints;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param DoliDB $db Database handler
|
|
*/
|
|
public function __construct($db)
|
|
{
|
|
$this->db = $db;
|
|
|
|
global $conf, $langs;
|
|
$this->conf = $conf;
|
|
$this->langs = $langs;
|
|
}
|
|
|
|
/**
|
|
* Hook nach ODT-Generierung
|
|
* Wird aufgerufen nachdem ein ODT-Dokument erstellt wurde
|
|
*
|
|
* @param array $parameters Hook-Parameter
|
|
* @param object $object Dolibarr-Objekt
|
|
* @param string $action Aktuelle Aktion
|
|
* @return int 0 = OK, <0 = Fehler
|
|
*/
|
|
public function afterODTCreation($parameters, &$object, &$action)
|
|
{
|
|
global $conf;
|
|
|
|
dol_syslog("EPCQR Hook: afterODTCreation aufgerufen", LOG_DEBUG);
|
|
|
|
// Prüfen ob Parameter vorhanden sind
|
|
if (empty($parameters['file'])) {
|
|
dol_syslog("EPCQR Hook: Kein Dateipfad in Parametern", LOG_DEBUG);
|
|
return 0;
|
|
}
|
|
|
|
$odfFilePath = $parameters['file'];
|
|
|
|
// Prüfen ob Datei existiert
|
|
if (!file_exists($odfFilePath)) {
|
|
dol_syslog("EPCQR Hook: ODT-Datei existiert nicht: ".$odfFilePath, LOG_WARNING);
|
|
return 0;
|
|
}
|
|
|
|
// Nur ODT-Dateien verarbeiten
|
|
if (pathinfo($odfFilePath, PATHINFO_EXTENSION) !== 'odt') {
|
|
dol_syslog("EPCQR Hook: Keine ODT-Datei, überspringe", LOG_DEBUG);
|
|
return 0;
|
|
}
|
|
|
|
// Prüfen ob Objekt gültig ist
|
|
if (!is_object($object) || empty($object->id)) {
|
|
dol_syslog("EPCQR Hook: Ungültiges Objekt", LOG_DEBUG);
|
|
return 0;
|
|
}
|
|
|
|
// Bilder in ODT einfügen
|
|
require_once __DIR__.'/../lib/epcqr.lib.php';
|
|
$result = epcqr_processODTImages($odfFilePath, $object);
|
|
|
|
if ($result) {
|
|
dol_syslog("EPCQR Hook: Bilder erfolgreich in ODT eingefügt", LOG_INFO);
|
|
} else {
|
|
dol_syslog("EPCQR Hook: Fehler beim Einfügen der Bilder", LOG_WARNING);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Hook vor ODT-Speicherung
|
|
* Fügt QR-Code-Bild in ODT ein bevor es gespeichert wird
|
|
*
|
|
* @param array $parameters Hook-Parameter (enthält odfHandler)
|
|
* @param object $object Dolibarr-Objekt
|
|
* @param string $action Aktuelle Aktion
|
|
* @return int 0 = OK, <0 = Fehler
|
|
*/
|
|
public function beforeODTSave($parameters, &$object, &$action)
|
|
{
|
|
global $conf;
|
|
|
|
dol_syslog("EPCQR Hook: beforeODTSave aufgerufen", LOG_DEBUG);
|
|
|
|
// Prüfen ob odfHandler vorhanden ist
|
|
if (empty($parameters['odfHandler'])) {
|
|
dol_syslog("EPCQR Hook: Kein odfHandler in Parametern", LOG_DEBUG);
|
|
return 0;
|
|
}
|
|
|
|
$odfHandler = $parameters['odfHandler'];
|
|
|
|
// Das Rechnungsobjekt ist in $parameters['object'], nicht in $object!
|
|
$invoice = isset($parameters['object']) ? $parameters['object'] : null;
|
|
|
|
// Prüfen ob Objekt gültig ist
|
|
if (!is_object($invoice) || empty($invoice->id)) {
|
|
dol_syslog("EPCQR Hook: Ungültiges Rechnungsobjekt in parameters", LOG_DEBUG);
|
|
return 0;
|
|
}
|
|
|
|
dol_syslog("EPCQR Hook: Verarbeite Rechnung ".$invoice->ref, LOG_DEBUG);
|
|
|
|
// Extrafelder laden falls nicht vorhanden
|
|
if (empty($invoice->array_options)) {
|
|
$invoice->fetch_optionals();
|
|
}
|
|
|
|
// QR-Code-Pfad aus Extrafeld holen
|
|
$qrcodepath = '';
|
|
if (isset($invoice->array_options['options_qrcodepath'])) {
|
|
$qrcodepath = $invoice->array_options['options_qrcodepath'];
|
|
}
|
|
|
|
dol_syslog("EPCQR Hook: QR-Code-Pfad aus Extrafeld: ".$qrcodepath, LOG_DEBUG);
|
|
|
|
if (empty($qrcodepath) || !file_exists($qrcodepath)) {
|
|
dol_syslog("EPCQR Hook: Kein QR-Code-Pfad oder Datei nicht gefunden: ".$qrcodepath, LOG_WARNING);
|
|
return 0;
|
|
}
|
|
|
|
// QR-Code als Bild in ODT einfügen
|
|
try {
|
|
// setImage erwartet: Variablenname (ohne Klammern), Bildpfad, Größenverhältnis
|
|
// Ratio 0.3 = ca. 2-3cm bei typischen QR-Code-Größen
|
|
$ratio = getDolGlobalString('EPCQR_IMAGE_RATIO', '0.3');
|
|
$odfHandler->setImage('qrcode', $qrcodepath, (float) $ratio);
|
|
dol_syslog("EPCQR Hook: QR-Code-Bild erfolgreich eingefügt: ".$qrcodepath." (ratio: ".$ratio.")", LOG_INFO);
|
|
} catch (Exception $e) {
|
|
dol_syslog("EPCQR Hook: Fehler beim Einfügen des QR-Codes: ".$e->getMessage(), LOG_ERR);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Hook für PDF-Generierung (falls später benötigt)
|
|
*
|
|
* @param array $parameters Hook-Parameter
|
|
* @param object $object Dolibarr-Objekt
|
|
* @param string $action Aktuelle Aktion
|
|
* @return int 0 = OK, <0 = Fehler
|
|
*/
|
|
public function beforePDFCreation($parameters, &$object, &$action)
|
|
{
|
|
// Hier könnte später Code für PDF-Verarbeitung eingefügt werden
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Hook für completesubstitutionarray
|
|
* Fügt zusätzliche Substitutionswerte hinzu
|
|
*
|
|
* @param array $parameters Hook-Parameter
|
|
* @param object $object Dolibarr-Objekt
|
|
* @param string $action Aktuelle Aktion
|
|
* @return int 0 = OK, <0 = Fehler
|
|
*/
|
|
public function completesubstitutionarray($parameters, &$object, &$action)
|
|
{
|
|
dol_syslog("EPCQR Hook: completesubstitutionarray aufgerufen", LOG_DEBUG);
|
|
|
|
if (empty($parameters['substitutionarray'])) {
|
|
dol_syslog("EPCQR Hook: Kein substitutionarray in Parametern", LOG_DEBUG);
|
|
return 0;
|
|
}
|
|
|
|
// Substitutionsfunktion aufrufen
|
|
require_once __DIR__.'/../core/substitutions/functions_epcqr.lib.php';
|
|
epcqr_completesubstitutionarray(
|
|
$parameters['substitutionarray'],
|
|
$this->langs,
|
|
$object,
|
|
isset($parameters['outputlangs']) ? $parameters['outputlangs'] : null
|
|
);
|
|
|
|
return 0;
|
|
}
|
|
}
|