';
if ($permissiontoadd) {
@@ -929,6 +1016,23 @@ if (empty($customerSystems)) {
printTreeOptions($tree, $selectedParent, $excludeId);
print '';
+ // Produkt-Zuordnung
+ $productValue = '';
+ $productId = 0;
+ if (($isEdit || $isCopy) && $anlage->fk_product > 0) {
+ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+ $product = new Product($db);
+ if ($product->fetch($anlage->fk_product) > 0) {
+ $productValue = $product->ref.' - '.$product->label;
+ $productId = $product->id;
+ }
+ }
+ print '
';
@@ -1122,6 +1226,168 @@ print dol_get_fiche_end();
// Tooltip container
print '
';
+// Produkt-Autocomplete + Zubehör-AJAX (nur wenn Formular oder Detailansicht aktiv)
+if (in_array($action, array('create', 'edit', 'copy', 'view'))) {
+ print '';
+
+ // CSS für Autocomplete
+ print '';
+}
+
llxFooter();
$db->close();
diff --git a/tabs/contact_anlagen.php b/tabs/contact_anlagen.php
index 490ddb7..1a843a7 100755
--- a/tabs/contact_anlagen.php
+++ b/tabs/contact_anlagen.php
@@ -29,6 +29,7 @@ dol_include_once('/kundenkarte/class/anlagefile.class.php');
dol_include_once('/kundenkarte/class/equipmentpanel.class.php');
dol_include_once('/kundenkarte/class/equipmentcarrier.class.php');
dol_include_once('/kundenkarte/class/equipment.class.php');
+dol_include_once('/kundenkarte/class/anlageaccessory.class.php');
dol_include_once('/kundenkarte/lib/kundenkarte.lib.php');
// Load translation files
@@ -178,6 +179,7 @@ if ($action == 'add' && $permissiontoadd) {
$anlage->fk_anlage_type = GETPOSTINT('fk_anlage_type');
$anlage->fk_parent = GETPOSTINT('fk_parent');
$anlage->fk_system = $systemId;
+ $anlage->fk_product = GETPOSTINT('fk_product') > 0 ? GETPOSTINT('fk_product') : null;
$anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : '';
$anlage->status = 1;
@@ -220,6 +222,7 @@ if ($action == 'update' && $permissiontoadd) {
$anlage->label = GETPOST('label', 'alphanohtml');
$anlage->fk_anlage_type = GETPOSTINT('fk_anlage_type');
$anlage->fk_parent = GETPOSTINT('fk_parent');
+ $anlage->fk_product = GETPOSTINT('fk_product') > 0 ? GETPOSTINT('fk_product') : null;
$anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : '';
// Get type - but keep current system for GLOBAL types (buildings)
@@ -588,6 +591,21 @@ if (empty($customerSystems)) {
print '
';
+ // Zugeordnetes Produkt
+ if ($anlage->fk_product > 0) {
+ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+ $product = new Product($db);
+ if ($product->fetch($anlage->fk_product) > 0) {
+ print '
';
+ }
+ }
+
// Dynamic fields - all fields come from type definition
$fieldValues = $anlage->getFieldValues();
$typeFieldsList = $type->fetchFields();
@@ -795,6 +813,73 @@ if (empty($customerSystems)) {
';
}
+ // Zubehör-Bereich (nur wenn Typ has_accessories hat)
+ if (!empty($type->has_accessories)) {
+ $accessoryObj = new AnlageAccessory($db);
+ $accessories = $accessoryObj->fetchAllByAnlage($anlageId);
+
+ print '
';
if ($permissiontoadd) {
@@ -927,6 +1012,23 @@ if (empty($customerSystems)) {
printTreeOptions($tree, $selectedParent, $excludeId);
print '';
+ // Produkt-Zuordnung
+ $productValue = '';
+ $productId = 0;
+ if (($isEdit || $isCopy) && $anlage->fk_product > 0) {
+ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+ $product = new Product($db);
+ if ($product->fetch($anlage->fk_product) > 0) {
+ $productValue = $product->ref.' - '.$product->label;
+ $productId = $product->id;
+ }
+ }
+ print '
| '.$langs->trans('Product').' | ';
+ print '';
+ print '';
+ print '';
+ print ' |
';
+
// Dynamic fields will be inserted here via JavaScript
print '
';
@@ -1120,6 +1222,163 @@ print dol_get_fiche_end();
// Tooltip container
print '
';
+// Produkt-Autocomplete + Zubehör-AJAX (nur wenn Formular oder Detailansicht aktiv)
+if (in_array($action, array('create', 'edit', 'copy', 'view'))) {
+ print '';
+
+ print '';
+}
+
llxFooter();
$db->close();
diff --git a/werkzeuge.php b/werkzeuge.php
index bb597bf..5409941 100644
--- a/werkzeuge.php
+++ b/werkzeuge.php
@@ -1,8 +1,8 @@
hasRight('kundenkarte', 'delete');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
+$systemId = GETPOSTINT('system');
$anlageId = GETPOSTINT('anlage_id');
$parentId = GETPOSTINT('parent_id');
-// Virtuelle Firma-ID für Werkzeuge - braucht keinen echten Societe-Eintrag
+// Virtuelle Firma-ID für "Mein Betrieb" - braucht keinen echten Societe-Eintrag
// Die Anlage-Tabelle verwendet diese ID nur als Gruppierung
$socId = 99999999;
-// WERKZEUG-System ermitteln
-$werkzeugSystemId = 0;
-$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE code = 'WERKZEUG' AND active = 1";
+// ALLE verfügbaren Systeme laden
+$allSystems = array();
+$sql = "SELECT rowid, code, label, picto, color FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE active = 1 ORDER BY position ASC";
$resql = $db->query($sql);
-if ($resql && $db->num_rows($resql) > 0) {
- $obj = $db->fetch_object($resql);
- $werkzeugSystemId = $obj->rowid;
+if ($resql) {
+ while ($obj = $db->fetch_object($resql)) {
+ $allSystems[$obj->rowid] = $obj;
+ }
}
-if ($werkzeugSystemId <= 0) {
- setEventMessages('System WERKZEUG nicht gefunden. Bitte Modul deaktivieren und wieder aktivieren.', null, 'errors');
- llxHeader('', 'Firmen-Werkzeuge');
- llxFooter();
- exit;
+// Für diesen virtuellen Betrieb aktivierte Systeme laden
+$customerSystems = array();
+$sql = "SELECT ss.rowid, ss.fk_system, s.code, s.label, s.picto, s.color";
+$sql .= " FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system ss";
+$sql .= " JOIN ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system s ON s.rowid = ss.fk_system";
+$sql .= " WHERE ss.fk_soc = ".((int) $socId)." AND (ss.fk_contact IS NULL OR ss.fk_contact = 0) AND ss.active = 1 AND s.active = 1";
+$sql .= " AND s.code != 'GLOBAL'";
+$sql .= " ORDER BY s.position ASC";
+$resql = $db->query($sql);
+if ($resql) {
+ while ($obj = $db->fetch_object($resql)) {
+ $customerSystems[$obj->fk_system] = $obj;
+ }
}
-$systemId = $werkzeugSystemId;
-
-// Sicherstellen dass WERKZEUG für eigene Firma aktiviert ist
-$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system";
-$sql .= " WHERE fk_soc = ".((int) $socId)." AND fk_system = ".((int) $systemId);
-$sql .= " AND (fk_contact IS NULL OR fk_contact = 0) AND active = 1";
-$resql = $db->query($sql);
-if (!$resql || $db->num_rows($resql) == 0) {
- // Automatisch aktivieren
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."kundenkarte_societe_system";
- $sql .= " (entity, fk_soc, fk_contact, fk_system, date_creation, fk_user_creat, active)";
- $sql .= " VALUES (".$conf->entity.", ".((int) $socId).", 0, ".((int) $systemId).", NOW(), ".((int) $user->id).", 1)";
- $db->query($sql);
+// Standard: Erstes aktiviertes System falls nicht angegeben
+if (empty($systemId) && !empty($customerSystems)) {
+ $systemId = array_key_first($customerSystems);
}
// Objekte initialisieren
@@ -79,6 +79,53 @@ $anlageType = new AnlageType($db);
* Actions
*/
+// System hinzufügen
+if ($action == 'add_system' && $permissiontoadd) {
+ $newSystemId = GETPOSTINT('new_system_id');
+ if ($newSystemId > 0 && !isset($customerSystems[$newSystemId])) {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."kundenkarte_societe_system";
+ $sql .= " (entity, fk_soc, fk_contact, fk_system, date_creation, fk_user_creat, active)";
+ $sql .= " VALUES (".$conf->entity.", ".((int) $socId).", 0, ".((int) $newSystemId).", NOW(), ".((int) $user->id).", 1)";
+ $result = $db->query($sql);
+ if ($result) {
+ setEventMessages($langs->trans('SystemAdded'), null, 'mesgs');
+ header('Location: '.$_SERVER['PHP_SELF'].'?system='.$newSystemId);
+ exit;
+ } else {
+ setEventMessages($db->lasterror(), null, 'errors');
+ }
+ }
+ $action = '';
+}
+
+// System entfernen
+if ($action == 'confirm_remove_system' && $confirm == 'yes' && $permissiontodelete) {
+ $removeSystemId = GETPOSTINT('remove_system_id');
+ if ($removeSystemId > 0) {
+ // Prüfen ob System noch Elemente hat
+ $sql = "SELECT COUNT(*) as cnt FROM ".MAIN_DB_PREFIX."kundenkarte_anlage WHERE fk_soc = ".((int) $socId)." AND (fk_contact IS NULL OR fk_contact = 0) AND fk_system = ".((int) $removeSystemId);
+ $resql = $db->query($sql);
+ $obj = $db->fetch_object($resql);
+
+ if ($obj->cnt > 0) {
+ setEventMessages($langs->trans('ErrorSystemHasElements'), null, 'errors');
+ } else {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system WHERE fk_soc = ".((int) $socId)." AND (fk_contact IS NULL OR fk_contact = 0) AND fk_system = ".((int) $removeSystemId);
+ $db->query($sql);
+ setEventMessages($langs->trans('SystemRemoved'), null, 'mesgs');
+
+ unset($customerSystems[$removeSystemId]);
+ if (!empty($customerSystems)) {
+ $systemId = array_key_first($customerSystems);
+ } else {
+ $systemId = 0;
+ }
+ }
+ }
+ header('Location: '.$_SERVER['PHP_SELF'].($systemId ? '?system='.$systemId : ''));
+ exit;
+}
+
if ($action == 'add' && $permissiontoadd) {
$anlage->label = GETPOST('label', 'alphanohtml');
$anlage->fk_soc = $socId;
@@ -107,7 +154,7 @@ if ($action == 'add' && $permissiontoadd) {
$result = $anlage->create($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
- header('Location: '.$_SERVER['PHP_SELF']);
+ header('Location: '.$_SERVER['PHP_SELF'].'?system='.$systemId);
exit;
} else {
setEventMessages($anlage->error, $anlage->errors, 'errors');
@@ -141,7 +188,7 @@ if ($action == 'update' && $permissiontoadd) {
$result = $anlage->update($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
- header('Location: '.$_SERVER['PHP_SELF']);
+ header('Location: '.$_SERVER['PHP_SELF'].'?system='.$systemId);
exit;
} else {
setEventMessages($anlage->error, $anlage->errors, 'errors');
@@ -175,10 +222,10 @@ print load_fiche_titre($title, '', 'fa-wrench');
print '
';
-// Bestätigungsdialog
+// Bestätigungsdialoge
if ($action == 'delete') {
print $form->formconfirm(
- $_SERVER['PHP_SELF'].'?anlage_id='.$anlageId,
+ $_SERVER['PHP_SELF'].'?system='.$systemId.'&anlage_id='.$anlageId,
$langs->trans('DeleteElement'),
$langs->trans('ConfirmDeleteElement'),
'confirm_delete',
@@ -188,8 +235,109 @@ if ($action == 'delete') {
);
}
-// Typen für WERKZEUG-System laden
-$types = $anlageType->fetchAllBySystem($systemId, 1, 1); // excludeGlobal=1, nur WERKZEUG-Typen
+if ($action == 'remove_system') {
+ $removeSystemId = GETPOSTINT('remove_system_id');
+ $sysLabel = isset($customerSystems[$removeSystemId]) ? $customerSystems[$removeSystemId]->label : '';
+ print $form->formconfirm(
+ $_SERVER['PHP_SELF'].'?remove_system_id='.$removeSystemId,
+ $langs->trans('RemoveSystem'),
+ $langs->trans('ConfirmRemoveSystem', $sysLabel),
+ 'confirm_remove_system',
+ '',
+ 'yes',
+ 1
+ );
+}
+
+// System-Tabs
+print '
';
+print '
';
+foreach ($customerSystems as $sysId => $sys) {
+ $activeClass = ($sysId == $systemId) ? ' active' : '';
+ print '
';
+}
+
+// System hinzufügen Button
+if ($permissiontoadd) {
+ $availableSystems = array_diff_key($allSystems, $customerSystems);
+ // GLOBAL ausschließen
+ foreach ($availableSystems as $k => $v) {
+ if ($v->code === 'GLOBAL') unset($availableSystems[$k]);
+ }
+ if (!empty($availableSystems)) {
+ print '
';
+ }
+}
+print '
';
+
+// Steuerungs-Buttons (nur in Baumansicht)
+$isTreeView = !in_array($action, array('create', 'edit', 'view'));
+if ($isTreeView && $systemId > 0) {
+ print '
';
+ print '';
+ print '';
+ print '';
+ print '';
+ print '
';
+}
+
+print '
'; // End system-tabs-wrapper
+
+// System-Hinzufügen-Formular (versteckt)
+if ($permissiontoadd && !empty($availableSystems)) {
+ print '
';
+ print '';
+ print '
';
+}
+
+// Prüfen ob Systeme konfiguriert sind
+if (empty($customerSystems)) {
+ print '
';
+ print '
';
+ print $langs->trans('NoSystemsConfigured').'
';
+ if ($permissiontoadd && !empty($allSystems)) {
+ print $langs->trans('ClickAddSystemToStart');
+ } else {
+ print $langs->trans('ContactAdminToAddSystems');
+ }
+ print '
';
+} elseif ($systemId > 0) {
+
+// Typen für ausgewähltes System laden
+$types = $anlageType->fetchAllBySystem($systemId, 1, 1);
if (in_array($action, array('create', 'edit', 'view'))) {
// Formular oder Detail-Ansicht
@@ -337,12 +485,12 @@ if (in_array($action, array('create', 'edit', 'view'))) {
// Aktions-Buttons
print '
';
} else {
@@ -350,9 +498,10 @@ if (in_array($action, array('create', 'edit', 'view'))) {
$isEdit = ($action == 'edit');
$formAction = $isEdit ? 'update' : 'add';
- print '
';
@@ -430,28 +579,12 @@ if (in_array($action, array('create', 'edit', 'view'))) {
if ($permissiontoadd) {
print '
';
}
- // Steuerungs-Buttons
- print '
';
- print '';
- print '';
- print '';
- print '';
- print '
';
-
// Baum laden
$tree = $anlage->fetchTree($socId, $systemId);
@@ -478,12 +611,14 @@ if (in_array($action, array('create', 'edit', 'view'))) {
print '
';
print $langs->trans('NoToolsYet').'
';
if ($permissiontoadd) {
- print '
'.$langs->trans('AddFirstTool').'';
+ print '
'.$langs->trans('AddFirstTool').'';
}
print '
';
}
}
+} // Ende elseif ($systemId > 0)
+
print '
'; // fichecenter
// Tooltip Container
@@ -739,7 +874,7 @@ function werkzeuge_printTree($nodes, $socid, $systemId, $canEdit, $canDelete, $l
print '
';
// Label
- $viewUrl = $_SERVER['PHP_SELF'].'?action=view&anlage_id='.$node->id;
+ $viewUrl = $_SERVER['PHP_SELF'].'?system='.$systemId.'&action=view&anlage_id='.$node->id;
print '