* 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 '
Auftrag nicht gefunden
';
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 '';
print '
';
// 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 '
';
print '
';
print '
';
print 'Aufmaß für ' . dol_escape_htmltag($object->ref) . '';
if (!empty($object->thirdparty->name)) {
print '
' . dol_escape_htmltag($object->thirdparty->name) . '';
}
print '
';
print '
';
print 'Aufmaß starten';
print '
';
print '
';
} else {
print '
';
}
// Verknüpfte Aufmaß-Daten (Platzhalter für Backend-Integration)
print '
';
print '';
print '| Grundriss | Etage | Räume | Fläche | Erstellt | | ';
print '
';
// 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 '';
print '| '.dol_escape_htmltag($p['name'] ?? '-').' | ';
print '- | ';
print '- | ';
print '- | ';
print ''.dol_print_date(strtotime($p['erstellt'] ?? ''), 'day').' | ';
print '';
if (!empty($pwa_url)) {
print 'Öffnen';
}
print ' | ';
print '
';
}
}
}
}
if (empty($raeume) && empty($projekte)) {
print '| ';
print 'Noch keine Aufmaße verknüpft. Starte ein neues Aufmaß über den Button oben.';
print ' |
';
}
print '
';
print '
'; // fichecenter
print dol_get_fiche_end();
llxFooter();
$db->close();