- output_location (Räumlichkeit): Neues Textfeld am Abgang für Raum/Ort des Verbrauchers. DB-Migration, Backend (AJAX), Frontend (Website + PWA), Anzeige im Schaltplan (kursiv) und in PDF-Tabellen. - Verteilungs-Tabellen: Kundenansicht (A4, Nr/Verbraucher/Räumlichkeit) und Technikeransicht (A4, R.Klem/FI/Nr/Verbraucher/Räumlichkeit/Typ) im Leitungslaufplan-PDF. Gruppiert nach Feld/Reihe mit automatischem Seitenumbruch. - Bundled-Terminals Checkbox: Im Website-Abgang-Dialog (war vorher nur PWA). - PWA: Diverse Verbesserungen, Service Worker v12.4, Connection-Modal erweitert. - Typ-Flags: has_product auch für Gebäudetypen, Equipment-Typ Erweiterungen. - CLAUDE.md + Doku aktualisiert. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
154 lines
4.3 KiB
PHP
Executable file
154 lines
4.3 KiB
PHP
Executable file
<?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);
|