eplan/aufmass_order.php
Eduard Wisch 4f09c6e55c
All checks were successful
Deploy Eplan / deploy (push) Successful in 9s
fix: Modul-Beschreibung + Rechte-Labels via Sprachdatei [deploy]
- Module500037Desc/DescLong aus eplan.lang statt hardcodierter deutscher
  Strings im Modul-Descriptor
- Rechte-Labels via EplanRightRead/Write/Admin übersetzbar
- QR-Code-Block auf Auftragstab (aus vorheriger Sitzung)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 09:48:49 +02:00

143 lines
6.5 KiB
PHP

<?php
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
* GPL v3+
*
* Tab "Aufmaß" auf der Auftragskarte
*/
$res = 0;
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if (!$res) die("Include of main fails");
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
$langs->loadLangs(array('orders', 'eplan@eplan'));
$id = GETPOSTINT('id');
$ref = GETPOST('ref', 'alpha');
$object = new Commande($db);
if ($id > 0 || !empty($ref)) {
$object->fetch($id, $ref);
}
if (!$object->id) {
llxHeader('', 'Aufmaß');
print '<div class="error">Auftrag nicht gefunden</div>';
llxFooter();
exit;
}
$pwa_url = getDolGlobalString('EPLAN_PWA_URL');
// Sicherheit
if (!$user->hasRight('eplan', 'read')) accessforbidden();
llxHeader('', 'Aufmaß — '.$object->ref, '', '', 0, 0, '', '', '', 'mod-eplan');
// Auftrag-Header + Tabs
$head = commande_prepare_head($object);
print dol_get_fiche_head($head, 'aufmass', $langs->trans("Order"), -1, 'order');
// Auftrag-Info-Leiste
dol_banner_tab($object, 'ref', '', 1, 'ref', 'ref');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
// PWA-Link mit Auftrags-Kontext
if (!empty($pwa_url)) {
$pwa_link = $pwa_url . '/?auftrag=' . urlencode($object->ref) . '&kunde=' . urlencode($object->thirdparty->name ?? '') . '&auftrag_id=' . $object->id;
print '<div style="background: linear-gradient(135deg, #1565C0 0%, #0D47A1 100%); border-radius: 10px; padding: 20px; margin: 16px 0; color: #fff; box-sizing: border-box;">';
print '<div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px;">';
print '<div style="flex: 1; min-width: 220px;">';
print '<strong style="font-size: 16px;">Aufmaß für ' . dol_escape_htmltag($object->ref) . '</strong>';
if (!empty($object->thirdparty->name)) {
print '<br><span style="opacity: 0.8; font-size: 13px;">' . dol_escape_htmltag($object->thirdparty->name) . '</span>';
}
print '<br><span style="opacity: 0.7; font-size: 12px; margin-top: 8px; display: inline-block;">QR mit Handy scannen oder Button klicken — Auftrag wird automatisch verknüpft.</span>';
print '<div style="margin-top: 12px;">';
print '<a href="' . dol_escape_htmltag($pwa_link) . '" target="_blank" rel="noopener" ';
print 'style="display: inline-block; background: #fff; color: #1565C0; padding: 10px 24px; border-radius: 8px; font-size: 14px; font-weight: 700; text-decoration: none;">';
print '<i class="fas fa-drafting-compass" style="margin-right: 6px;"></i>Aufmaß starten</a>';
print '</div>';
print '</div>';
// QR-Code (clientseitig generiert, kein externer Tracking-Service)
print '<div id="eplan-qr" style="background: #fff; padding: 8px; border-radius: 8px; flex-shrink: 0;"></div>';
print '</div>';
print '</div>';
// qrcode-generator (selbsthosting wäre besser, aber CDN ist akzeptabel —
// bei fehlender Internet-Verbindung bleibt zumindest der Text-Link nutzbar)
print '<script src="https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js"></script>';
print '<script>(function(){';
print ' if (typeof qrcode !== "function") return;';
print ' var q = qrcode(0, "M");';
print ' q.addData(' . json_encode($pwa_link, JSON_UNESCAPED_SLASHES) . ');';
print ' q.make();';
print ' var el = document.getElementById("eplan-qr");';
print ' if (el) el.innerHTML = q.createSvgTag({cellSize: 4, margin: 0});';
print '})();</script>';
} else {
print '<div class="warning" style="margin: 16px 0;">';
print '<i class="fas fa-exclamation-triangle"></i> ElektroPlan PWA-URL nicht konfiguriert. ';
print '<a href="' . dol_buildpath('/eplan/admin/setup.php', 1) . '">Einstellungen öffnen</a>';
print '</div>';
}
// Verknüpfte Aufmaß-Daten (Platzhalter für Backend-Integration)
print '<table class="noborder centpercent" style="margin-top: 16px;">';
print '<tr class="liste_titre">';
print '<td>Grundriss</td><td>Etage</td><td>Räume</td><td>Fläche</td><td>Erstellt</td><td></td>';
print '</tr>';
// Aufmaß-Daten aus dem ElektroPlan-Backend laden
$api_url = getDolGlobalString('EPLAN_PWA_URL');
$raeume = array();
if (!empty($api_url)) {
$ch = curl_init($api_url.'/api/projekte/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$projekte = json_decode($response, true);
if (is_array($projekte)) {
// TODO: Filter nach dolibarr_auftrag_id wenn Backend das unterstützt
foreach ($projekte as $p) {
print '<tr class="oddeven">';
print '<td>'.dol_escape_htmltag($p['name'] ?? '-').'</td>';
print '<td>-</td>';
print '<td>-</td>';
print '<td>-</td>';
print '<td>'.dol_print_date(strtotime($p['erstellt'] ?? ''), 'day').'</td>';
print '<td class="right">';
if (!empty($pwa_url)) {
print '<a href="'.dol_escape_htmltag($pwa_url.'/?projekt='.$p['id']).'" target="_blank" class="butAction butActionSmall">Öffnen</a>';
}
print '</td>';
print '</tr>';
}
}
}
}
if (empty($raeume) && empty($projekte)) {
print '<tr class="oddeven"><td colspan="6" class="opacitymedium" style="text-align: center; padding: 20px;">';
print 'Noch keine Aufmaße verknüpft. Starte ein neues Aufmaß über den Button oben.';
print '</td></tr>';
}
print '</table>';
print '</div>'; // fichecenter
print dol_get_fiche_end();
llxFooter();
$db->close();