added auto user accettatore id
This commit is contained in:
@@ -55,7 +55,52 @@ $template = $template_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$default_idclient = $template['idclient'] ?? null;
|
||||
|
||||
$insertedIds = $_POST['inserted_ids'] ?? $_SESSION['inserted_ids'];
|
||||
// ------------------------------------------------------------
|
||||
// AUTO SET: schema field_id = 244 with auth_users.lims_user_id (if present)
|
||||
// ------------------------------------------------------------
|
||||
try {
|
||||
// 1) Read logged user lims_user_id
|
||||
$stmtUser = $pdo->prepare("SELECT lims_user_id FROM auth_users WHERE id = ? LIMIT 1");
|
||||
$stmtUser->execute([(int)$user_id]);
|
||||
$limsUserId = $stmtUser->fetchColumn();
|
||||
|
||||
// normalize
|
||||
$limsUserId = ($limsUserId !== false && $limsUserId !== null && $limsUserId !== '') ? (string)$limsUserId : '';
|
||||
|
||||
if ($limsUserId !== '' && !empty($insertedIds)) {
|
||||
|
||||
// 2) Find mapping_id for field_id = 244 in this template
|
||||
$stmtMap = $pdo->prepare("SELECT id FROM template_mapping WHERE template_id = ? AND field_id = 244 LIMIT 1");
|
||||
$stmtMap->execute([(int)$template_id]);
|
||||
$mappingId244 = (int)$stmtMap->fetchColumn();
|
||||
|
||||
if ($mappingId244 > 0) {
|
||||
|
||||
// 3) Upsert value into import_data_details for every inserted datadb row
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$updStmt = $pdo->prepare("UPDATE import_data_details SET field_value = ? WHERE id = ? AND mapping_id = ?");
|
||||
$insStmt = $pdo->prepare("INSERT INTO import_data_details (id, mapping_id, field_value) VALUES (?, ?, ?)");
|
||||
|
||||
foreach ($insertedIds as $iddatadb) {
|
||||
$iddatadb = (int)$iddatadb;
|
||||
if ($iddatadb <= 0) continue;
|
||||
|
||||
$updStmt->execute([$limsUserId, $iddatadb, $mappingId244]);
|
||||
|
||||
if ($updStmt->rowCount() === 0) {
|
||||
$insStmt->execute([$iddatadb, $mappingId244, $limsUserId]);
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Do not block import page if this fails; just log
|
||||
error_log("[AUTO FIELD 244] " . $e->getMessage());
|
||||
if ($pdo->inTransaction()) $pdo->rollBack();
|
||||
}
|
||||
// Recupera i dati appena inseriti con i nomi degli utenti
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT d.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name
|
||||
@@ -68,7 +113,8 @@ $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Recupera i dettagli manuali da import_data_details
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value, m.field_label, m.data_type, m.is_required, m.manual_default
|
||||
SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value,
|
||||
m.field_id, m.field_label, m.data_type, m.is_required, m.manual_default
|
||||
FROM import_data_details d
|
||||
JOIN template_mapping m ON d.mapping_id = m.id
|
||||
WHERE d.id IN (" . implode(',', array_fill(0, count($insertedIds), '?')) . ")
|
||||
@@ -1935,8 +1981,13 @@ function fixedDefaultValue(array $f): string
|
||||
clientData.forEach(client => {
|
||||
const nome = client.Nominativo || "Nome non disponibile";
|
||||
const id = client.IdCliente || "ID non disponibile";
|
||||
const codice = (client.CodiceNazioneFatturazione || '').trim();
|
||||
const option = new Option(`${nome.trim()} - ${codice} (ID: ${id})`, id);
|
||||
|
||||
// CodiceCliente es: "Bl01858_E" -> vogliamo "E"
|
||||
const codiceCliente = (client.CodiceCliente || '').toString().trim();
|
||||
const suffix = (codiceCliente.split('_')[1] || '').trim(); // parte dopo "_"
|
||||
const shortCode = suffix || '--';
|
||||
|
||||
const option = new Option(`${nome.trim()} - ${shortCode} (ID: ${id})`, id);
|
||||
|
||||
if (parseInt(id) === parseInt(<?php echo json_encode($default_idclient ?? 0); ?>)) {
|
||||
option.selected = true;
|
||||
@@ -1967,8 +2018,13 @@ function fixedDefaultValue(array $f): string
|
||||
clientData.forEach(client => {
|
||||
const nome = client.Nominativo || "Nome non disponibile";
|
||||
const id = client.IdCliente || "ID non disponibile";
|
||||
const codice = (client.CodiceNazioneFatturazione || '').trim();
|
||||
const option = new Option(`${nome.trim()} - ${codice} (ID: ${id})`, id);
|
||||
|
||||
// CodiceCliente es: "Bl01858_E" -> vogliamo "E"
|
||||
const codiceCliente = (client.CodiceCliente || '').toString().trim();
|
||||
const suffix = (codiceCliente.split('_')[1] || '').trim(); // parte dopo "_"
|
||||
const shortCode = suffix || '--';
|
||||
|
||||
const option = new Option(`${nome.trim()} - ${shortCode} (ID: ${id})`, id);
|
||||
|
||||
if (String(id) === String(currentValue)) {
|
||||
option.selected = true;
|
||||
|
||||
Reference in New Issue
Block a user