197 lines
6.5 KiB
PHP
Executable file
197 lines
6.5 KiB
PHP
Executable file
<?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 epcqr/lib/epcqr.lib.php
|
|
* \ingroup epcqr
|
|
* \brief Library files with common functions for Epcqr
|
|
*/
|
|
|
|
/**
|
|
* Prepare admin pages header
|
|
*
|
|
* @return array<array{string,string,string}>
|
|
*/
|
|
function epcqrAdminPrepareHead()
|
|
{
|
|
global $langs, $conf;
|
|
|
|
// global $db;
|
|
// $extrafields = new ExtraFields($db);
|
|
// $extrafields->fetch_name_optionals_label('myobject');
|
|
|
|
$langs->load("epcqr@epcqr");
|
|
|
|
$h = 0;
|
|
$head = array();
|
|
|
|
$head[$h][0] = dol_buildpath("/epcqr/admin/setup.php", 1);
|
|
$head[$h][1] = $langs->trans("Settings");
|
|
$head[$h][2] = 'settings';
|
|
$h++;
|
|
|
|
/*
|
|
$head[$h][0] = dol_buildpath("/epcqr/admin/myobject_extrafields.php", 1);
|
|
$head[$h][1] = $langs->trans("ExtraFields");
|
|
$nbExtrafields = (isset($extrafields->attributes['myobject']['label']) && is_countable($extrafields->attributes['myobject']['label'])) ? count($extrafields->attributes['myobject']['label']) : 0;
|
|
if ($nbExtrafields > 0) {
|
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
|
|
}
|
|
$head[$h][2] = 'myobject_extrafields';
|
|
$h++;
|
|
|
|
$head[$h][0] = dol_buildpath("/epcqr/admin/myobjectline_extrafields.php", 1);
|
|
$head[$h][1] = $langs->trans("ExtraFieldsLines");
|
|
$nbExtrafields = (isset($extrafields->attributes['myobjectline']['label']) && is_countable($extrafields->attributes['myobjectline']['label'])) ? count($extrafields->attributes['myobject']['label']) : 0;
|
|
if ($nbExtrafields > 0) {
|
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
|
|
}
|
|
$head[$h][2] = 'myobject_extrafieldsline';
|
|
$h++;
|
|
*/
|
|
|
|
$head[$h][0] = dol_buildpath("/epcqr/admin/about.php", 1);
|
|
$head[$h][1] = $langs->trans("About");
|
|
$head[$h][2] = 'about';
|
|
$h++;
|
|
|
|
// Show more tabs from modules
|
|
// Entries must be declared in modules descriptor with line
|
|
//$this->tabs = array(
|
|
// 'entity:+tabname:Title:@epcqr:/epcqr/mypage.php?id=__ID__'
|
|
//); // to add new tab
|
|
//$this->tabs = array(
|
|
// 'entity:-tabname:Title:@epcqr:/epcqr/mypage.php?id=__ID__'
|
|
//); // to remove a tab
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'epcqr@epcqr');
|
|
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'epcqr@epcqr', 'remove');
|
|
|
|
return $head;
|
|
}
|
|
|
|
/**
|
|
* Generiert QR-Code für Rechnung und speichert Pfad im Extrafeld
|
|
*
|
|
* @param Facture $invoice Rechnungsobjekt
|
|
* @param DoliDB $db Database handler
|
|
* @return bool true bei Erfolg, false bei Fehler
|
|
*/
|
|
function epcqr_generateQRCodeForInvoice($invoice, $db)
|
|
{
|
|
global $conf;
|
|
|
|
dol_syslog("EPCQR: START generateQRCodeForInvoice für Rechnung ".$invoice->ref, LOG_DEBUG);
|
|
|
|
// QRCodeGenerator-Klasse laden
|
|
require_once __DIR__.'/qrcode.class.php';
|
|
|
|
$qrGen = new QRCodeGenerator($db);
|
|
|
|
// Bankverbindung aus Konfiguration laden
|
|
// TODO: Diese Werte sollten aus der Modul-Konfiguration kommen
|
|
$accountHolder = getDolGlobalString('EPCQR_ACCOUNT_HOLDER', 'Eduard Wisch');
|
|
$iban = getDolGlobalString('EPCQR_IBAN', 'DE70217625500013438147');
|
|
$bic = getDolGlobalString('EPCQR_BIC', 'GENODEF1HUM');
|
|
|
|
// Betrag und Referenz aus Rechnung
|
|
$amount = price2num($invoice->total_ttc, 'MT');
|
|
$reference = $invoice->ref;
|
|
|
|
// QR-Code generieren
|
|
$qrCodePath = $qrGen->generateEPCQRCode($accountHolder, $iban, $bic, $amount, $reference);
|
|
|
|
if ($qrCodePath === false) {
|
|
dol_syslog("EPCQR: Fehler beim Generieren des QR-Codes", LOG_ERR);
|
|
return false;
|
|
}
|
|
|
|
// Extrafelder aktualisieren
|
|
// qrcodepath: Pfad zur lokalen QR-Code-Datei (für ODT-Integration)
|
|
$invoice->array_options['options_qrcodepath'] = $qrCodePath;
|
|
$invoice->insertExtraFields();
|
|
|
|
// qrcode: HTML für Anzeige (Kompatibilität mit alter Version)
|
|
$qrCodeUrl = DOL_URL_ROOT.'/viewimage.php?modulepart=epcqr&file='.urlencode(basename(dirname($qrCodePath)).'/'.basename($qrCodePath));
|
|
$invoice->array_options['options_qrcode'] = "<img src='".$qrCodeUrl."' width='100px'>";
|
|
$invoice->insertExtraFields();
|
|
|
|
// qrcodepfad: URL zum QR-Code (Kompatibilität mit alter Version)
|
|
$invoice->array_options['options_qrcodepfad'] = $qrCodeUrl;
|
|
$invoice->insertExtraFields();
|
|
|
|
dol_syslog("EPCQR: QR-Code erfolgreich generiert: ".$qrCodePath, LOG_INFO);
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Hook für ODT-Generierung: Fügt Bilder nach der Generierung ein
|
|
*
|
|
* @param string $odfFilePath Pfad zur ODT-Datei
|
|
* @param CommonObject $object Dolibarr-Objekt
|
|
* @return bool true bei Erfolg, false bei Fehler
|
|
*/
|
|
function epcqr_processODTImages($odfFilePath, $object)
|
|
{
|
|
dol_syslog("EPCQR: START processODTImages für ".$odfFilePath, LOG_DEBUG);
|
|
|
|
// Substitutionsfunktion laden
|
|
require_once __DIR__.'/../core/substitutions/functions_epcqr.lib.php';
|
|
|
|
// Bilddaten sammeln
|
|
$imageData = array();
|
|
|
|
// QR-Code
|
|
if (isset($object->array_options['options_qrcodepath'])) {
|
|
$qrCodePath = $object->array_options['options_qrcodepath'];
|
|
if (!empty($qrCodePath) && file_exists($qrCodePath)) {
|
|
$imageData['qrcode'] = $qrCodePath;
|
|
dol_syslog("EPCQR: QR-Code gefunden: ".$qrCodePath, LOG_DEBUG);
|
|
}
|
|
}
|
|
|
|
// Weitere Bilder (alle Extrafelder die auf _imagepath enden)
|
|
if (!empty($object->array_options)) {
|
|
foreach ($object->array_options as $key => $value) {
|
|
if (preg_match('/^options_(.+)_imagepath$/', $key, $matches)) {
|
|
$fieldname = $matches[1];
|
|
if (!empty($value) && file_exists($value)) {
|
|
$imageData[$fieldname] = $value;
|
|
dol_syslog("EPCQR: Bild gefunden für ".$fieldname.": ".$value, LOG_DEBUG);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Keine Bilder? Dann nichts zu tun
|
|
if (empty($imageData)) {
|
|
dol_syslog("EPCQR: Keine Bilder zum Einfügen gefunden", LOG_DEBUG);
|
|
return true;
|
|
}
|
|
|
|
// Bilder in ODT einfügen
|
|
$result = epcqr_insertImagesIntoODT($odfFilePath, $imageData);
|
|
|
|
if ($result) {
|
|
dol_syslog("EPCQR: Bilder erfolgreich in ODT eingefügt", LOG_INFO);
|
|
} else {
|
|
dol_syslog("EPCQR: Fehler beim Einfügen der Bilder in ODT", LOG_ERR);
|
|
}
|
|
|
|
return $result;
|
|
}
|