* * 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 . */ /** * \file epcqr/lib/epcqr.lib.php * \ingroup epcqr * \brief Library files with common functions for Epcqr */ /** * Prepare admin pages header * * @return array */ function epcqrAdminPrepareHead() { global $langs, $conf; $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/test_qrcode.php", 1); $head[$h][1] = $langs->trans("Debug"); $head[$h][2] = 'debug'; $h++; $head[$h][0] = dol_buildpath("/epcqr/admin/about.php", 1); $head[$h][1] = $langs->trans("About"); $head[$h][2] = 'about'; $h++; 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 laden - entweder aus System oder manuell $bankDataSource = getDolGlobalString('EPCQR_BANK_DATA_SOURCE', 'manual'); if ($bankDataSource == 'system') { // Bankdaten aus Systembankkonto laden require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $accountHolder = ''; $iban = ''; $bic = ''; // Erstes aktives Bankkonto mit IBAN suchen $sql = "SELECT rowid, label, proprio, iban_prefix, bic FROM ".MAIN_DB_PREFIX."bank_account"; $sql .= " WHERE entity = ".((int) $conf->entity)." AND clos = 0 AND iban_prefix IS NOT NULL AND iban_prefix != ''"; $sql .= " ORDER BY rowid ASC LIMIT 1"; $resql = $db->query($sql); if ($resql && $db->num_rows($resql) > 0) { $obj = $db->fetch_object($resql); $accountHolder = !empty($obj->proprio) ? $obj->proprio : $obj->label; $iban = $obj->iban_prefix; $bic = $obj->bic; dol_syslog("EPCQR: Bankdaten aus System geladen - Inhaber: ".$accountHolder.", IBAN: ".substr($iban, 0, 4)."****", LOG_DEBUG); } else { dol_syslog("EPCQR: Kein Systembankkonto gefunden, verwende manuelle Einstellungen", LOG_WARNING); $accountHolder = getDolGlobalString('EPCQR_ACCOUNT_HOLDER', ''); $iban = getDolGlobalString('EPCQR_IBAN', ''); $bic = getDolGlobalString('EPCQR_BIC', ''); } } else { // Manuelle Bankverbindung aus Konfiguration laden $accountHolder = getDolGlobalString('EPCQR_ACCOUNT_HOLDER', ''); $iban = getDolGlobalString('EPCQR_IBAN', ''); $bic = getDolGlobalString('EPCQR_BIC', ''); } // Prüfen ob Bankdaten vollständig sind if (empty($accountHolder) || empty($iban)) { dol_syslog("EPCQR: Bankdaten unvollständig - Kontoinhaber oder IBAN fehlt", LOG_ERR); return false; } // 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'] = ""; $invoice->insertExtraFields(); // qrcodepfad: URL zum QR-Code als klickbarer Link $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; }