epcqr/test_qrcode.php

285 lines
9.6 KiB
PHP

<?php
/**
* Test-Script für QR-Code und Bildintegration
* Aufruf: http://localhost/custom/epcqr/test_qrcode.php
*/
// Dolibarr laden
$res = 0;
if (!$res && file_exists("../../main.inc.php")) {
$res = @include "../../main.inc.php";
}
if (!$res) {
die("Fehler: main.inc.php nicht gefunden");
}
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
// Header
llxHeader('', 'EPCQR Test & Debug');
print '<h1>EPCQR Modul - Test & Debug</h1>';
// 1. Modul-Status prüfen
print '<h2>1. Modul-Status</h2>';
print '<table class="border" width="100%">';
print '<tr><td width="30%">Modul aktiviert</td><td>';
print isModEnabled('epcqr') ? '<span style="color: green;">✓ Ja</span>' : '<span style="color: red;">✗ Nein</span>';
print '</td></tr>';
// 2. Modul-Konfiguration prüfen
print '<tr><td>Substitutionen aktiviert</td><td>';
$module_parts = $conf->modules_parts;
$subst_active = isset($module_parts['substitutions']) && in_array('epcqr', $module_parts['substitutions']);
print $subst_active ? '<span style="color: green;">✓ Ja</span>' : '<span style="color: red;">✗ Nein (in modEpcqr.class.php aktivieren!)</span>';
print '</td></tr>';
print '<tr><td>Hooks aktiviert</td><td>';
$hooks_active = isset($module_parts['hooks']) && isset($module_parts['hooks']['epcqr']);
print $hooks_active ? '<span style="color: green;">✓ Ja</span>' : '<span style="color: red;">✗ Nein</span>';
if ($hooks_active) {
print '<br>Hooks: '.implode(', ', $module_parts['hooks']['epcqr']);
}
print '</td></tr>';
print '</table>';
// 3. Dateien prüfen
print '<h2>2. Dateien vorhanden</h2>';
print '<table class="border" width="100%">';
$files = array(
'QR-Code Generator' => __DIR__.'/lib/qrcode.class.php',
'Substitutionen' => __DIR__.'/core/substitutions/functions_epcqr.lib.php',
'Hook-Klasse' => __DIR__.'/class/actions_epcqr.class.php',
'Hilfsfunktionen' => __DIR__.'/lib/epcqr.lib.php',
);
foreach ($files as $name => $file) {
print '<tr><td width="30%">'.$name.'</td><td>';
if (file_exists($file)) {
print '<span style="color: green;">✓ Vorhanden</span> ('.$file.')';
} else {
print '<span style="color: red;">✗ Fehlt!</span> ('.$file.')';
}
print '</td></tr>';
}
print '</table>';
// 4. Extrafelder prüfen
print '<h2>3. Extrafelder</h2>';
print '<table class="border" width="100%">';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label('facture');
$required_fields = array('qrcode', 'qrcodepfad', 'qrcodepath');
foreach ($required_fields as $field) {
print '<tr><td width="30%">'.$field.'</td><td>';
if (isset($extrafields->attributes['facture']['label'][$field])) {
print '<span style="color: green;">✓ Vorhanden</span>';
print ' - Typ: '.$extrafields->attributes['facture']['type'][$field];
} else {
print '<span style="color: red;">✗ Fehlt!</span> (SQL-Update ausführen!)';
}
print '</td></tr>';
}
print '</table>';
// 5. Verzeichnisse prüfen
print '<h2>4. Verzeichnisse</h2>';
print '<table class="border" width="100%">';
$qrCodeDir = $conf->epcqr->dir_output.'/qrcodes';
print '<tr><td width="30%">QR-Code Cache</td><td>';
if (is_dir($qrCodeDir)) {
print '<span style="color: green;">✓ Vorhanden</span> ('.$qrCodeDir.')';
if (is_writable($qrCodeDir)) {
print ' - <span style="color: green;">Beschreibbar</span>';
} else {
print ' - <span style="color: red;">Nicht beschreibbar!</span>';
}
} else {
print '<span style="color: orange;">⚠ Fehlt</span> (wird automatisch erstellt)';
}
print '</td></tr>';
print '</table>';
// 6. Test: QR-Code generieren
print '<h2>5. Test: QR-Code generieren</h2>';
require_once __DIR__.'/lib/qrcode.class.php';
try {
$qrGen = new QRCodeGenerator($db);
$testPath = $qrGen->generateEPCQRCode(
'Test Firma',
'DE89370400440532013000',
'COBADEFFXXX',
99.99,
'TEST-001'
);
print '<p><span style="color: green;">✓ QR-Code erfolgreich generiert!</span></p>';
print '<p>Pfad: '.$testPath.'</p>';
if (file_exists($testPath)) {
print '<p><img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=epcqr&file='.urlencode(basename(dirname($testPath)).'/'.basename($testPath)).'" width="200"></p>';
}
} catch (Exception $e) {
print '<p><span style="color: red;">✗ Fehler: '.$e->getMessage().'</span></p>';
}
// 7. Letzte Rechnungen mit QR-Codes prüfen
print '<h2>6. Letzte 5 Rechnungen mit QR-Codes</h2>';
$sql = "SELECT f.rowid, f.ref, f.total_ttc, f.datef";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE f.entity = ".((int) $conf->entity);
$sql .= " ORDER BY f.datef DESC";
$sql .= " LIMIT 5";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0) {
print '<table class="border" width="100%">';
print '<tr class="liste_titre">';
print '<th>Rechnung</th>';
print '<th>Betrag</th>';
print '<th>QR-Code Path</th>';
print '<th>Datei existiert?</th>';
print '</tr>';
while ($obj = $db->fetch_object($resql)) {
$invoice = new Facture($db);
$invoice->fetch($obj->rowid);
$invoice->fetch_optionals();
print '<tr>';
print '<td>'.$invoice->getNomUrl(1).'</td>';
print '<td>'.price($obj->total_ttc).'</td>';
$qrPath = isset($invoice->array_options['options_qrcodepath']) ? $invoice->array_options['options_qrcodepath'] : '';
print '<td>';
if (!empty($qrPath)) {
print $qrPath;
print '<td>';
if (file_exists($qrPath)) {
print '<span style="color: green;">✓ Ja</span>';
} else {
print '<span style="color: red;">✗ Nein</span>';
}
print '</td>';
} else {
print '<span style="color: orange;">Nicht gesetzt</span>';
print '<td>-</td>';
}
print '</tr>';
}
print '</table>';
} else {
print '<p>Keine Rechnungen gefunden.</p>';
}
} else {
print '<p style="color: red;">SQL-Fehler: '.$db->lasterror().'</p>';
}
// 8. Logs prüfen
print '<h2>7. Letzte Log-Einträge (EPCQR)</h2>';
$logFile = DOL_DATA_ROOT.'/dolibarr.log';
if (file_exists($logFile)) {
$lines = file($logFile);
$epcqrLogs = array();
foreach (array_reverse($lines) as $line) {
if (stripos($line, 'EPCQR') !== false || stripos($line, 'epcqr') !== false) {
$epcqrLogs[] = $line;
if (count($epcqrLogs) >= 10) break;
}
}
if (!empty($epcqrLogs)) {
print '<pre style="background: #f5f5f5; padding: 10px; border: 1px solid #ddd; overflow-x: auto;">';
foreach (array_reverse($epcqrLogs) as $log) {
print htmlspecialchars($log);
}
print '</pre>';
} else {
print '<p>Keine EPCQR-Log-Einträge gefunden.</p>';
}
} else {
print '<p style="color: orange;">Log-Datei nicht gefunden: '.$logFile.'</p>';
}
// 9. Anleitung
print '<h2>8. Nächste Schritte</h2>';
print '<div class="info">';
print '<ol>';
print '<li><strong>Modul neu aktivieren:</strong> Wenn Substitutionen oder Hooks rot sind → Modul deaktivieren und wieder aktivieren</li>';
print '<li><strong>Rechnung validieren:</strong> Erstellen Sie eine Test-Rechnung und validieren Sie diese</li>';
print '<li><strong>ODT generieren:</strong> Template mit {qrcode} erstellen und Dokument generieren</li>';
print '<li><strong>Logs prüfen:</strong> Schauen Sie in documents/dolibarr.log nach EPCQR-Einträgen</li>';
print '</ol>';
print '</div>';
print '<h2>9. Schnelltest: ODT-Bildverarbeitung</h2>';
print '<form method="POST">';
print '<input type="hidden" name="action" value="test_odt">';
print '<p>Test-Rechnung ID: <input type="text" name="invoice_id" value="" placeholder="123"></p>';
print '<input type="submit" class="button" value="ODT-Verarbeitung testen">';
print '</form>';
if (GETPOST('action') == 'test_odt' && GETPOST('invoice_id')) {
$invoice_id = GETPOST('invoice_id', 'int');
print '<h3>Test-Ergebnis:</h3>';
$invoice = new Facture($db);
if ($invoice->fetch($invoice_id) > 0) {
$invoice->fetch_optionals();
print '<p>Rechnung: '.$invoice->ref.'</p>';
// QR-Code Path prüfen
$qrPath = isset($invoice->array_options['options_qrcodepath']) ? $invoice->array_options['options_qrcodepath'] : '';
print '<p>QR-Code Path: '.($qrPath ? $qrPath : '<span style="color: red;">Nicht gesetzt!</span>').'</p>';
if (!empty($qrPath) && file_exists($qrPath)) {
print '<p style="color: green;">✓ QR-Code-Datei existiert</p>';
// Test: Bilddaten sammeln
require_once __DIR__.'/lib/epcqr.lib.php';
require_once __DIR__.'/core/substitutions/functions_epcqr.lib.php';
$imageData = array();
if (!empty($qrPath) && file_exists($qrPath)) {
$imageData['qrcode'] = $qrPath;
}
print '<p>Bilddaten gesammelt: '.count($imageData).' Bilder</p>';
if (!empty($imageData)) {
print '<pre>';
print_r($imageData);
print '</pre>';
}
} else {
print '<p style="color: red;">✗ QR-Code-Datei nicht gefunden</p>';
print '<p><strong>Lösung:</strong> Rechnung neu validieren (Draft → Validate)</p>';
}
} else {
print '<p style="color: red;">Rechnung nicht gefunden!</p>';
}
}
// Footer
llxFooter();
$db->close();