false, 'error' => 'Missing product_id')); exit; } $db->begin(); // Hole Facture ID $sql = "SELECT m.fk_facture, m.rowid as manager_id"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_lines_manager m"; $sql .= " WHERE m.fk_facturedet = ".(int)$product_id; $resql = $db->query($sql); if (!$resql || $db->num_rows($resql) == 0) { echo json_encode(array('success' => false, 'error' => 'Product not found')); exit; } $obj = $db->fetch_object($resql); $facture_id = $obj->fk_facture; $manager_id = $obj->rowid; // Update parent_section UND line_order if ($new_section_id > 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_lines_manager"; $sql .= " SET parent_section = ".(int)$new_section_id; if ($new_line_order !== null) { $sql .= ", line_order = ".(float)$new_line_order; // ← NEU! } $sql .= " WHERE rowid = ".(int)$manager_id; } else { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_lines_manager"; $sql .= " SET parent_section = NULL"; if ($new_line_order !== null) { $sql .= ", line_order = ".(float)$new_line_order; // ← NEU! } $sql .= " WHERE rowid = ".(int)$manager_id; } $db->query($sql); subtotaltitle_debug_log('✅ parent_section und line_order gesetzt'); // Neuordnen (bereinigt Dezimalzahlen und Lücken) require_once DOL_DOCUMENT_ROOT.'/custom/subtotaltitle/class/actions_subtotaltitle.class.php'; $hook = new ActionsSubtotalTitle($db); $reflection = new ReflectionClass($hook); $method = $reflection->getMethod('reorderLines'); $method->setAccessible(true); $method->invoke($hook, $facture_id); $method = $reflection->getMethod('syncRangFromManager'); $method->setAccessible(true); $method->invoke($hook, $facture_id); $db->commit(); echo json_encode(array('success' => true));