kundenkarte/ajax/anlage_accessory.php
data a14b33b7c7 feat: Firmen-Werkzeuge, Zubehör-System und Produkt-Zuordnung
- Neue Seite werkzeuge.php mit Baumansicht für Firmen-Maschinen/Werkzeuge
- Menüpunkt "Firmen-Werkzeuge" unter Start-Menü
- Neue Klasse AnlageAccessory für Zubehör/Ersatzteile pro Anlage
- AJAX-Endpunkt ajax/anlage_accessory.php (CRUD + Lieferantenbestellung)
- DB: fk_product auf Anlage, has_accessories auf AnlageType, Zubehör-Tabelle
- Neues System WERKZEUG in Systemkategorien
- Admin: Checkbox "Hat Zubehör" im Typ-Editor
- Produkt-Autocomplete, Zubehör-Liste mit Bestellfunktion (CommandeFournisseur)
- Produkt-JOIN in fetchChildren für product_ref im Baum
- Übersetzungen de_DE + en_US

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 20:23:29 +01:00

154 lines
4.3 KiB
PHP

<?php
/* Copyright (C) 2026 Alles Watt lauft
*
* AJAX-Endpunkt für Anlagen-Zubehör Operationen
*/
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
$res = 0;
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");
dol_include_once('/kundenkarte/class/anlageaccessory.class.php');
header('Content-Type: application/json; charset=UTF-8');
$langs->loadLangs(array('kundenkarte@kundenkarte'));
$action = GETPOST('action', 'aZ09');
$response = array('success' => false, 'error' => '');
// Berechtigungsprüfung
if (!$user->hasRight('kundenkarte', 'read')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
echo json_encode($response);
exit;
}
$accessory = new AnlageAccessory($db);
switch ($action) {
case 'list':
// Alle Zubehörteile einer Anlage laden
$anlageId = GETPOSTINT('fk_anlage');
if ($anlageId > 0) {
$accessories = $accessory->fetchAllByAnlage($anlageId);
$result = array();
foreach ($accessories as $acc) {
$result[] = array(
'id' => $acc->id,
'fk_product' => $acc->fk_product,
'product_ref' => $acc->product_ref,
'product_label' => $acc->product_label,
'product_price' => $acc->product_price,
'qty' => $acc->qty,
'note' => $acc->note,
);
}
$response['success'] = true;
$response['accessories'] = $result;
} else {
$response['error'] = 'Missing fk_anlage';
}
break;
case 'add':
// Zubehör hinzufügen
if (!$user->hasRight('kundenkarte', 'write')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
break;
}
$accessory->fk_anlage = GETPOSTINT('fk_anlage');
$accessory->fk_product = GETPOSTINT('fk_product');
$accessory->qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 1;
$accessory->note = GETPOST('note', 'alphanohtml');
$result = $accessory->create($user);
if ($result > 0) {
$response['success'] = true;
$response['id'] = $result;
} else {
$response['error'] = $accessory->error ?: 'Fehler beim Speichern';
}
break;
case 'update':
// Zubehör aktualisieren (Menge, Notiz)
if (!$user->hasRight('kundenkarte', 'write')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
break;
}
$id = GETPOSTINT('id');
if ($id > 0 && $accessory->fetch($id) > 0) {
$accessory->qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : $accessory->qty;
$accessory->note = GETPOST('note', 'alphanohtml');
$result = $accessory->update($user);
if ($result > 0) {
$response['success'] = true;
} else {
$response['error'] = 'Fehler beim Speichern';
}
} else {
$response['error'] = $langs->trans('ErrorRecordNotFound');
}
break;
case 'delete':
// Zubehör löschen
if (!$user->hasRight('kundenkarte', 'delete')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
break;
}
$id = GETPOSTINT('id');
if ($id > 0 && $accessory->fetch($id) > 0) {
$result = $accessory->delete($user);
if ($result > 0) {
$response['success'] = true;
} else {
$response['error'] = 'Fehler beim Löschen';
}
} else {
$response['error'] = $langs->trans('ErrorRecordNotFound');
}
break;
case 'order':
// Lieferantenbestellung aus Zubehör erstellen
if (!$user->hasRight('kundenkarte', 'write')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
break;
}
$anlageId = GETPOSTINT('fk_anlage');
$supplierId = GETPOSTINT('supplier_id');
$idsRaw = GETPOST('ids', 'array');
if ($anlageId > 0 && $supplierId > 0 && !empty($idsRaw)) {
$ids = array_map('intval', $idsRaw);
$result = $accessory->generateSupplierOrder($user, $supplierId, $anlageId, $ids);
if ($result > 0) {
$response['success'] = true;
$response['order_id'] = $result;
} else {
$response['error'] = $accessory->error ?: 'Fehler beim Erstellen der Bestellung';
}
} else {
$response['error'] = 'Fehlende Parameter (Anlage, Lieferant, IDs)';
}
break;
default:
$response['error'] = 'Unknown action';
}
echo json_encode($response);