Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e19e9e1d4 | |||
| 7caee9c994 | |||
| f8320315f7 | |||
| 7397d86bc2 | |||
| 2deb1f101a | |||
| ed4467337f | |||
| 864714d198 | |||
| 33aacfb469 | |||
| e0e262fd32 | |||
| 5d6302fa9c | |||
| 3da8ff81c9 | |||
| a36dd02771 | |||
| 0a6fb98476 | |||
| 412dce8941 | |||
| 586226ceaf | |||
| ac09d8d0eb | |||
| 33e3ae059d |
+25
-7
@@ -1,16 +1,16 @@
|
|||||||
APP_ENV=production
|
APP_ENV=production
|
||||||
APP_DEBUG=false
|
APP_DEBUG=true
|
||||||
APP_KEY=
|
APP_KEY=base64:C+sutHm6xP5sE4QXhoZFhYjArlVN11s2mDU1F8beUkM=
|
||||||
APP_URL=http://vanguard.test
|
APP_URL=http://vanguard.test
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=localhost
|
DB_HOST="localhost"
|
||||||
DB_DATABASE=vanguard
|
DB_DATABASE="trfcertest"
|
||||||
DB_USERNAME=homestead
|
DB_USERNAME="solocla"
|
||||||
DB_PASSWORD=secret
|
DB_PASSWORD="xxxxxxx"
|
||||||
DB_PREFIX=vg_
|
DB_PREFIX="auth_"
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
BROADCAST_DRIVER=log
|
||||||
CACHE_DRIVER=file
|
CACHE_DRIVER=file
|
||||||
@@ -39,3 +39,21 @@ PUSHER_APP_CLUSTER=mt1
|
|||||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||||
|
|
||||||
|
# Credenziali API VisualLims
|
||||||
|
SIMULATE_EXPORT_LIMS=true
|
||||||
|
API_BASE_URL=https://93.43.5.102/limsapi
|
||||||
|
API_USERNAME=xxxx
|
||||||
|
API_PASSWORD=XXXX
|
||||||
|
|
||||||
|
BASE_URL=http://localhost:8000/userarea/
|
||||||
|
|
||||||
|
# Credenziali ENTRAID
|
||||||
|
|
||||||
|
AZURE_CLIENT_ID=your-client-id
|
||||||
|
AZURE_CLIENT_SECRET=your-client-secret
|
||||||
|
AZURE_REDIRECT_URI=https://your-app.com/auth/azure/callback
|
||||||
|
AZURE_TENANT_ID=
|
||||||
|
|
||||||
|
MICROSOFT_CLIENT_ID=your_client_id_here
|
||||||
|
MICROSOFT_CLIENT_SECRET=your_client_secret_here
|
||||||
|
MICROSOFT_REDIRECT_URI="${APP_URL}/auth/microsoft/callback"
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
ob_start();
|
||||||
|
session_start();
|
||||||
|
require_once '../../vendor/autoload.php';
|
||||||
|
|
||||||
|
$response = ['error' => '', 'rows' => [], 'columns' => [], 'template_id' => 0, 'filename' => '', 'excel_data' => []];
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$input = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$template_id = isset($input['template_id']) ? intval($input['template_id']) : 0;
|
||||||
|
$filename = $input['routine_data']['filename'] ?? '';
|
||||||
|
$headerrow = $input['routine_data']['headerrow'] ?? 1;
|
||||||
|
$excelData = $input['excel_data'] ?? [];
|
||||||
|
$routineData = $input['routine_data'] ?? [];
|
||||||
|
|
||||||
|
if (!$filename || empty($excelData)) {
|
||||||
|
throw new Exception("Dati della routine mancanti.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$routineFile = __DIR__ . '/routines/' . $filename;
|
||||||
|
if (file_exists($routineFile)) {
|
||||||
|
include_once $routineFile;
|
||||||
|
$routineData['xls_headers'] = $_SESSION['headers'] ?? [];
|
||||||
|
applyRoutine($excelData, $routineData); // Modifica $excelData in place
|
||||||
|
error_log("Routine {$routineData['name']} applicata (file: {$filename}) per template {$template_id}, header row: {$headerrow}");
|
||||||
|
} else {
|
||||||
|
throw new Exception("File della routine non trovato: $routineFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiorna la sessione con i dati modificati
|
||||||
|
$_SESSION['excel_data'] = $excelData;
|
||||||
|
|
||||||
|
$response['excel_data'] = $excelData;
|
||||||
|
$response['rows'] = array_column($excelData, 'data');
|
||||||
|
$response['columns'] = $_SESSION['headers'];
|
||||||
|
$response['template_id'] = $template_id;
|
||||||
|
$response['filename'] = $input['filename'] ?? '';
|
||||||
|
} else {
|
||||||
|
$response['error'] = "Richiesta non valida.";
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$response['error'] = "Errore durante l'applicazione della routine: " . $e->getMessage();
|
||||||
|
error_log("Exception in apply_routine.php: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_end_clean();
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($response);
|
||||||
|
exit;
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
require_once "class/VisualLimsApiClient.class.php";
|
||||||
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $dbHandler->getConnection();
|
||||||
|
|
||||||
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
|
// 🔹 Configura directory log (creala se non esiste)
|
||||||
|
$logDir = __DIR__ . '/logs/api/';
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Base URL API
|
||||||
|
$apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/';
|
||||||
|
|
||||||
|
// 🔹 Hardcoded values
|
||||||
|
$iddatadb = 846;
|
||||||
|
$commessaId = 533357;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 🔹 STEP 4: Fetch Field Values with Labels (usa dati reali per iddatadb=845)
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT
|
||||||
|
idd.field_value,
|
||||||
|
m.field_label,
|
||||||
|
m.schema_id,
|
||||||
|
m.field_id
|
||||||
|
FROM
|
||||||
|
import_data_details as idd
|
||||||
|
JOIN template_mapping m ON idd.mapping_id = m.id
|
||||||
|
WHERE idd.id = :iddatadb
|
||||||
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$fieldValues = [];
|
||||||
|
$valueMap = []; // Mappa per field_id -> valore
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$fieldValues[] = [
|
||||||
|
"IdCommesseCustomFields" => (int) $row['field_id'],
|
||||||
|
"Valore" => $row['field_value'],
|
||||||
|
"FieldLabel" => $row['field_label']
|
||||||
|
];
|
||||||
|
$valueMap[(int) $row['field_id']] = $row['field_value']; // Mappa per ID definizione
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logga i fieldValues in error_log
|
||||||
|
$logFieldValues = "FieldValues dal DB (iddatadb={$iddatadb}):\n" . json_encode($fieldValues, JSON_PRETTY_PRINT);
|
||||||
|
error_log($logFieldValues);
|
||||||
|
|
||||||
|
// 🔹 Initialize API client
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// 🔹 STEP A: GET iniziale per CommesseCustomFields con espansione CustomField
|
||||||
|
$expand = "CommesseCustomFields(\$expand=CustomField)"; // Espansione come da istruzioni fornitore
|
||||||
|
$commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
||||||
|
|
||||||
|
// 🔹 STEP B: Prepara payload PATCH (tutti i campi, sovrascrivi se match su CustomField.IdCustomField == field_id)
|
||||||
|
$commessaCustomFields = [];
|
||||||
|
foreach ($commessaWithFields["CommesseCustomFields"] as $customField) {
|
||||||
|
$definitionId = (int) ($customField["CustomField"]["IdCustomField"] ?? 0); // Usa IdCustomField dal CustomField
|
||||||
|
$currentValue = $customField["Valore"] ?? '';
|
||||||
|
$newValue = isset($valueMap[$definitionId]) ? $valueMap[$definitionId] : $currentValue;
|
||||||
|
|
||||||
|
$commessaCustomFields[] = [
|
||||||
|
"IdCommesseCustomFields" => (int) $customField["IdCommesseCustomFields"],
|
||||||
|
"Valore" => $newValue
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Unico file di log per tutto
|
||||||
|
$logFile = $logDir . "commessa_{$commessaId}_patch_and_get_" . time() . ".txt";
|
||||||
|
$logContent = "FieldValues dal DB (iddatadb={$iddatadb}):\n" . json_encode($fieldValues, JSON_PRETTY_PRINT) . "\n\n";
|
||||||
|
|
||||||
|
// Log curl-like per GET iniziale
|
||||||
|
$logContent .= "GET iniziale:\n" .
|
||||||
|
"curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••'\n\n" .
|
||||||
|
"RESPONSE:\n" . json_encode($commessaWithFields, JSON_PRETTY_PRINT) . "\n\n---\n";
|
||||||
|
|
||||||
|
if (!empty($commessaCustomFields)) {
|
||||||
|
$updatePayload = ["CommesseCustomFields" => $commessaCustomFields];
|
||||||
|
|
||||||
|
// Log curl-like per PATCH
|
||||||
|
$jsonPayload = json_encode($updatePayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
|
$logContent .= "PATCH:\n" .
|
||||||
|
"curl --location --request PATCH '{$apiBaseUrl}CommessaWeb({$commessaId})' \\\n" .
|
||||||
|
"--header 'Content-Type: application/json' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••' \\\n" .
|
||||||
|
"--data '{$jsonPayload}'\n\n";
|
||||||
|
|
||||||
|
$patchResponse = $api->patch("CommessaWeb({$commessaId})", $updatePayload);
|
||||||
|
|
||||||
|
$logContent .= "PATCH RESPONSE:\n" . json_encode($patchResponse, JSON_PRETTY_PRINT) . "\n\n---\n";
|
||||||
|
} else {
|
||||||
|
$logContent .= "PATCH: Nessun campo custom da aggiornare\n\n---\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 STEP C: GET di controllo post-PATCH
|
||||||
|
$commessaAfterPatch = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
||||||
|
|
||||||
|
// Log curl-like per GET di controllo
|
||||||
|
$logContent .= "GET di controllo:\n" .
|
||||||
|
"curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••'\n\n" .
|
||||||
|
"RESPONSE:\n" . json_encode($commessaAfterPatch, JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
|
// Salva log unico
|
||||||
|
file_put_contents($logFile, $logContent);
|
||||||
|
|
||||||
|
// 🔹 Output a schermo
|
||||||
|
echo json_encode([
|
||||||
|
"success" => true,
|
||||||
|
"message" => "PATCH eseguito su commessa {$commessaId} con dati da iddatadb {$iddatadb}",
|
||||||
|
"commessaAfterPatch" => $commessaAfterPatch,
|
||||||
|
"totalCustomFieldsUpdated" => count($commessaCustomFields),
|
||||||
|
"fieldValues" => $fieldValues,
|
||||||
|
"logFile" => $logFile
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log("Patch Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
"success" => false,
|
||||||
|
"message" => "Patch failed: " . $e->getMessage(),
|
||||||
|
"logFile" => $logFile ?? 'Nessun log generato'
|
||||||
|
]);
|
||||||
|
}
|
||||||
@@ -120,4 +120,76 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function post($endpoint, $payload)
|
||||||
|
{
|
||||||
|
$token = $this->getToken();
|
||||||
|
$url = "{$this->baseUrl}/api/odata/{$endpoint}";
|
||||||
|
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
"Authorization: Bearer {$token}",
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"Accept: application/json"
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curl_error = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($response === false) {
|
||||||
|
throw new Exception("Errore nella richiesta POST: {$curl_error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($http_code < 200 || $http_code >= 300) {
|
||||||
|
throw new Exception("POST fallito: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function patch($endpoint, $payload)
|
||||||
|
{
|
||||||
|
$token = $this->getToken();
|
||||||
|
$url = "{$this->baseUrl}/api/odata/{$endpoint}";
|
||||||
|
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
"Authorization: Bearer {$token}",
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"Accept: application/json"
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curl_error = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($response === false) {
|
||||||
|
throw new Exception("Errore nella richiesta PATCH: {$curl_error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($http_code < 200 || $http_code >= 300) {
|
||||||
|
throw new Exception("PATCH fallito: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBaseUrl()
|
||||||
|
{
|
||||||
|
return $this->baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -48,7 +48,7 @@ $routines = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<div class="page-content">
|
<div class="page-content">
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="mb-0">UpdateXLS Template</h5>
|
<h5 class="mb-0">Update XLS Template</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="mb-2">Edit the following form in order to update the selected import XLS template</p>
|
<p class="mb-2">Edit the following form in order to update the selected import XLS template</p>
|
||||||
@@ -99,6 +99,30 @@ $routines = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<input type="text" name="target_table" class="form-control" value="<?php echo htmlspecialchars($template['target_table']); ?>" readonly required>
|
<input type="text" name="target_table" class="form-control" value="<?php echo htmlspecialchars($template['target_table']); ?>" readonly required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Button Size</label>
|
||||||
|
<select name="button_size" class="form-control">
|
||||||
|
<option value="small" <?php echo ($template['button_size'] ?? 'medium') === 'small' ? 'selected' : ''; ?>>Small</option>
|
||||||
|
<option value="medium" <?php echo ($template['button_size'] ?? 'medium') === 'medium' ? 'selected' : ''; ?>>Medium</option>
|
||||||
|
<option value="large" <?php echo ($template['button_size'] ?? 'medium') === 'large' ? 'selected' : ''; ?>>Large</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Button Background Color</label>
|
||||||
|
<input type="color" name="button_bg_color" class="form-control" value="<?php echo htmlspecialchars($template['button_bg_color'] ?? '#007bff'); ?>">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Button Text Color</label>
|
||||||
|
<input type="color" name="button_text_color" class="form-control" value="<?php echo htmlspecialchars($template['button_text_color'] ?? '#ffffff'); ?>">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Button Label</label>
|
||||||
|
<input type="text" name="button_label" class="form-control" value="<?php echo htmlspecialchars($template['button_label'] ?? 'Click Me'); ?>">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Select Client *</label>
|
<label class="form-label">Select Client *</label>
|
||||||
<select name="client_id" id="clientSelect" class="form-control" required>
|
<select name="client_id" id="clientSelect" class="form-control" required>
|
||||||
|
|||||||
+252
-204
@@ -1,243 +1,291 @@
|
|||||||
<?php
|
<?php
|
||||||
// File: export_to_lims.php
|
require_once "class/VisualLimsApiClient.class.php";
|
||||||
ini_set('display_errors', '0');
|
include('include/headscript.php');
|
||||||
error_reporting(E_ALL);
|
|
||||||
ini_set('log_errors', 1);
|
|
||||||
ini_set('error_log', __DIR__ . '/logsapi/export_lims_error.log');
|
|
||||||
|
|
||||||
// Includi il file con la connessione al database e Dotenv
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
require_once __DIR__ . '/include/headscript.php';
|
$pdo = $dbHandler->getConnection();
|
||||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
|
||||||
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
|
|
||||||
|
|
||||||
use Dotenv\Dotenv;
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
// Carica il file .env
|
// 🔹 Configura directory log (creala se non esiste)
|
||||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 3)); // Torna al livello di public
|
$logDir = __DIR__ . '/logs/api/';
|
||||||
$dotenv->load();
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Leggi la variabile SIMULATE_EXPORT_LIMS
|
// 🔹 Base URL API
|
||||||
$simulate = filter_var($_ENV['SIMULATE_EXPORT_LIMS'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
$apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/';
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
// 🔹 Funzione per validare e convertire date
|
||||||
|
function validateDate($value)
|
||||||
|
{
|
||||||
|
// Prova a validare come data (accetta formati comuni)
|
||||||
|
$date = DateTime::createFromFormat('Y-m-d', $value) ?: DateTime::createFromFormat('Y-m-d H:i:s', $value);
|
||||||
|
if ($date) {
|
||||||
|
return $date->format('Y-m-d\TH:i:sP'); // Formato ISO 8601
|
||||||
|
}
|
||||||
|
return null; // Imposta null se non è una data valida
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Verifica che la richiesta sia POST e contenga iddatadb
|
$iddatadb = $_POST['iddatadb'] ?? null;
|
||||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['iddatadb'])) {
|
if (!$iddatadb) {
|
||||||
throw new Exception('Richiesta non valida: iddatadb mancante');
|
throw new Exception("Missing iddatadb");
|
||||||
}
|
}
|
||||||
|
|
||||||
$iddatadb = (int)$_POST['iddatadb'];
|
// 🔹 STEP 1+2: Fetch Cliente ID + Schema ID
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
// Crea la cartella logsapi se non esiste
|
SELECT et.idclient AS clienteId, et.idschema AS schemaId
|
||||||
$logDir = __DIR__ . '/logsapi';
|
FROM datadb as d
|
||||||
if (!is_dir($logDir)) {
|
INNER JOIN excel_templates as et ON d.templateid = et.id
|
||||||
mkdir($logDir, 0755, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ottieni connessione al database
|
|
||||||
$db = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $db->getConnection();
|
|
||||||
|
|
||||||
// Step 1: Creazione payload per CommessaWeb
|
|
||||||
$queryCommessa = "
|
|
||||||
SELECT
|
|
||||||
d.iddatadb,
|
|
||||||
e.idclient AS Cliente,
|
|
||||||
e.idschema AS SchemaCustomField
|
|
||||||
FROM datadb d
|
|
||||||
LEFT JOIN excel_templates e ON d.templateid = e.id
|
|
||||||
WHERE d.iddatadb = :iddatadb
|
WHERE d.iddatadb = :iddatadb
|
||||||
";
|
LIMIT 1
|
||||||
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$stmtCommessa = $pdo->prepare($queryCommessa);
|
if (!$result) {
|
||||||
$stmtCommessa->execute(['iddatadb' => $iddatadb]);
|
throw new Exception("No Cliente/Schema found for iddatadb {$iddatadb}");
|
||||||
$recordCommessa = $stmtCommessa->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
if (!$recordCommessa) {
|
|
||||||
throw new Exception("Nessun record trovato per iddatadb: {$iddatadb}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validazione payload
|
$clienteId = (int) $result['clienteId'];
|
||||||
if (empty($recordCommessa['Cliente']) || empty($recordCommessa['SchemaCustomField'])) {
|
$schemaId = (int) $result['schemaId'];
|
||||||
throw new Exception("Dati mancanti per CommessaWeb: Cliente o SchemaCustomField non validi");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Payload per creazione CommessaWeb
|
// 🔹 STEP 3: Fetch Parts (including idmatrice)
|
||||||
$payloadCommessa = [
|
$stmt = $pdo->prepare("
|
||||||
'Cliente' => (int)$recordCommessa['Cliente'],
|
SELECT part_number, part_description, material, color, mix, idmatrice
|
||||||
'SchemaCustomField' => (int)$recordCommessa['SchemaCustomField'],
|
|
||||||
'Richiedente' => null,
|
|
||||||
'Descrizione' => 'example'
|
|
||||||
];
|
|
||||||
|
|
||||||
// Step 2: Creazione payload per campi custom (CommesseCustomFields)
|
|
||||||
$queryCustomFields = "
|
|
||||||
SELECT
|
|
||||||
tm.field_id AS IdCommesseCustomFields,
|
|
||||||
idd.field_value AS Valore
|
|
||||||
FROM import_data_details idd
|
|
||||||
JOIN template_mapping tm ON idd.mapping_id = tm.id
|
|
||||||
WHERE idd.id = :iddatadb
|
|
||||||
";
|
|
||||||
|
|
||||||
$stmtCustomFields = $pdo->prepare($queryCustomFields);
|
|
||||||
$stmtCustomFields->execute(['iddatadb' => $iddatadb]);
|
|
||||||
$customFields = $stmtCustomFields->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
// Costruisci l'array CommesseCustomFields
|
|
||||||
$commesseCustomFields = [];
|
|
||||||
foreach ($customFields as $field) {
|
|
||||||
$commesseCustomFields[] = [
|
|
||||||
'IdCommesseCustomFields' => (int)$field['IdCommesseCustomFields'],
|
|
||||||
'Valore' => $field['Valore'] ?? ''
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Payload per aggiornamento campi custom
|
|
||||||
$payloadCustomFields = [
|
|
||||||
'CommesseCustomFields' => $commesseCustomFields
|
|
||||||
];
|
|
||||||
|
|
||||||
// Step 3: Creazione payload per Campioni (da identification_parts)
|
|
||||||
$queryCampioni = "
|
|
||||||
SELECT
|
|
||||||
part_number,
|
|
||||||
idmatrice AS Matrice,
|
|
||||||
part_description AS NoteWeb
|
|
||||||
FROM identification_parts
|
FROM identification_parts
|
||||||
WHERE iddatadb = :iddatadb
|
WHERE iddatadb = :iddatadb
|
||||||
";
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$stmtCampioni = $pdo->prepare($queryCampioni);
|
// 🔹 STEP 4: Fetch Field Values with Labels
|
||||||
$stmtCampioni->execute(['iddatadb' => $iddatadb]);
|
$stmt = $pdo->prepare("
|
||||||
$campioni = $stmtCampioni->fetchAll(PDO::FETCH_ASSOC);
|
SELECT
|
||||||
|
idd.field_value,
|
||||||
|
m.field_label,
|
||||||
|
m.schema_id,
|
||||||
|
m.field_id
|
||||||
|
FROM
|
||||||
|
import_data_details as idd
|
||||||
|
JOIN template_mapping m ON idd.mapping_id = m.id
|
||||||
|
WHERE idd.id = :iddatadb
|
||||||
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$payloadsCampioni = [];
|
$fieldValues = [];
|
||||||
foreach ($campioni as $campione) {
|
$valueMap = [];
|
||||||
if (empty($campione['Matrice'])) {
|
foreach ($rows as $row) {
|
||||||
throw new Exception("Matrice non valida per campione: {$campione['part_number']}");
|
$fieldValues[] = [
|
||||||
}
|
"IdCommesseCustomFields" => (int) $row['field_id'],
|
||||||
$payloadCampione = [
|
"Valore" => $row['field_value'],
|
||||||
'Commessa' => null, // Sarà impostato dopo
|
"FieldLabel" => $row['field_label']
|
||||||
'Matrice' => (int)$campione['Matrice'],
|
|
||||||
'SottoMatrice' => null,
|
|
||||||
'SchemaCustomField' => 1,
|
|
||||||
'NoteWeb' => $campione['NoteWeb'] ?? ''
|
|
||||||
];
|
];
|
||||||
$payloadsCampioni[] = $payloadCampione;
|
$valueMap[(int) $row['field_id']] = $row['field_value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4: Creazione payload per InviaCommessa
|
// Logga i fieldValues in error_log
|
||||||
$payloadInviaCommessa = [];
|
$logFieldValues = "FieldValues dal DB (iddatadb={$iddatadb}):\n" . json_encode($fieldValues, JSON_PRETTY_PRINT);
|
||||||
|
error_log($logFieldValues);
|
||||||
|
|
||||||
// Variabile per idcommessaweb
|
// 🔹 Initialize API client
|
||||||
$idcommessaweb = null;
|
$api = VisualLimsApiClient::getInstance();
|
||||||
$commessaweb = '';
|
|
||||||
|
|
||||||
if ($simulate) {
|
// 🔹 STEP 5: Create CommessaWeb (NOT WebOrder)
|
||||||
// Flusso simulato
|
$commessaWebPayload = [
|
||||||
$idcommessaweb = 10176; // Fittizio per il test
|
"Cliente" => $clienteId,
|
||||||
|
"SchemaCustomField" => $schemaId,
|
||||||
|
"Richiedente" => "Test Web Import",
|
||||||
|
"Descrizione" => "TEST CommessaWeb",
|
||||||
|
];
|
||||||
|
|
||||||
// Salva idcommessaweb in datadb
|
// Costruisci log curl-like per STEP 5
|
||||||
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb WHERE iddatadb = :iddatadb");
|
$jsonPayload = json_encode($commessaWebPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
$updateStmt->execute(['idcommessaweb' => $idcommessaweb, 'iddatadb' => $iddatadb]);
|
$logContentStep5 = "curl --location --request POST '{$apiBaseUrl}CommessaWeb' \\\n" .
|
||||||
|
"--header 'Content-Type: application/json' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••' \\\n" .
|
||||||
|
"--data '{$jsonPayload}'";
|
||||||
|
|
||||||
// Salva i payload in file JSON
|
$commessaWeb = $api->post("CommessaWeb", $commessaWebPayload);
|
||||||
$outputFileCommessa = $logDir . "/commessaweb_create_{$iddatadb}.json";
|
|
||||||
file_put_contents($outputFileCommessa, json_encode($payloadCommessa, JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
$outputFileCustomFields = $logDir . "/commessaweb_customfields_{$iddatadb}.json";
|
$logContentStep5 .= "\n\nRESPONSE:\n" . json_encode($commessaWeb, JSON_PRETTY_PRINT);
|
||||||
file_put_contents($outputFileCustomFields, json_encode($payloadCustomFields, JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
// Salva log
|
||||||
$payloadCampione['Commessa'] = $idcommessaweb;
|
$logFileStep5 = $logDir . "commessa_create_step5_" . $iddatadb . "_" . time() . ".txt";
|
||||||
$outputFileCampione = $logDir . "/campione_{$iddatadb}_{$campioni[$index]['part_number']}.json";
|
file_put_contents($logFileStep5, $logContentStep5);
|
||||||
file_put_contents($outputFileCampione, json_encode($payloadCampione, JSON_PRETTY_PRINT));
|
|
||||||
|
$commessaId = $commessaWeb["IdCommessa"];
|
||||||
|
$commessaWebCode = substr($commessaWeb["CodiceCommessa"] ?? "TEST CommessaWeb", 0, 30); // Limite a 30 caratteri
|
||||||
|
|
||||||
|
// 🔹 STEP 6: Create Campioni (Samples) for each part
|
||||||
|
$campioni = [];
|
||||||
|
$logContentStep6 = "";
|
||||||
|
|
||||||
|
foreach ($parts as $index => $part) {
|
||||||
|
$matriceId = (int) ($part["idmatrice"] ?? 0);
|
||||||
|
|
||||||
|
if ($matriceId <= 0) {
|
||||||
|
throw new Exception("Invalid or missing idmatrice for part: " . ($part["part_number"] ?? "Unknown"));
|
||||||
}
|
}
|
||||||
|
|
||||||
$outputFileInviaCommessa = $logDir . "/commessaweb_invia_{$iddatadb}.json";
|
$campionePayload = [
|
||||||
file_put_contents($outputFileInviaCommessa, json_encode($payloadInviaCommessa, JSON_PRETTY_PRINT));
|
"Commessa" => $commessaId,
|
||||||
|
"Matrice" => $matriceId,
|
||||||
|
"SottoMatrice" => null,
|
||||||
|
"SchemaCustomField" => $schemaId,
|
||||||
|
"NoteWeb" => $part["part_description"] ?? ""
|
||||||
|
];
|
||||||
|
|
||||||
// Aggiorna lo status a 'l' (To LIMS)
|
// Costruisci curl-like per questo campione
|
||||||
$updateStmt = $pdo->prepare("UPDATE datadb SET status = 'l' WHERE iddatadb = :iddatadb");
|
$jsonPayload = json_encode($campionePayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
$updateStmt->execute(['iddatadb' => $iddatadb]);
|
$logContentStep6 .= "CAMPIONE #{$index}\n" .
|
||||||
|
"curl --location --request POST '{$apiBaseUrl}Campione' \\\n" .
|
||||||
|
"--header 'Content-Type: application/json' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••' \\\n" .
|
||||||
|
"--data '{$jsonPayload}'\n\n";
|
||||||
|
|
||||||
// Risposta di successo (simulazione)
|
$campione = $api->post("Campione", $campionePayload);
|
||||||
echo json_encode([
|
|
||||||
'success' => true,
|
|
||||||
'mode' => 'simulated',
|
|
||||||
'message' => "Payload generati e salvati in {$outputFileCommessa}, {$outputFileCustomFields}, file campioni e {$outputFileInviaCommessa}",
|
|
||||||
'idcommessaweb' => $idcommessaweb,
|
|
||||||
'commessaweb' => $commessaweb,
|
|
||||||
'payload_commessa' => $payloadCommessa,
|
|
||||||
'payload_customfields' => $payloadCustomFields,
|
|
||||||
'payload_campioni' => $payloadsCampioni,
|
|
||||||
'payload_invia_commessa' => $payloadInviaCommessa
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
// Flusso reale
|
|
||||||
$apiClient = VisualLimsApiClient::getInstance();
|
|
||||||
|
|
||||||
// Step 1: Crea CommessaWeb
|
$logContentStep6 .= "RESPONSE:\n" . json_encode($campione, JSON_PRETTY_PRINT) . "\n\n---\n";
|
||||||
$response = $apiClient->post('/api/odata/CommessaWeb', $payloadCommessa);
|
|
||||||
if (!isset($response['success']) || !isset($response['CommessaId'])) {
|
|
||||||
throw new Exception('Errore nella creazione della CommessaWeb: ' . json_encode($response));
|
|
||||||
}
|
|
||||||
$idcommessaweb = (int)$response['CommessaId'];
|
|
||||||
|
|
||||||
// Salva idcommessaweb in datadb
|
$campione["PartNumber"] = $part["part_number"] ?? "";
|
||||||
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb WHERE iddatadb = :iddatadb");
|
$campione["Material"] = $part["material"] ?? "";
|
||||||
$updateStmt->execute(['idcommessaweb' => $idcommessaweb, 'iddatadb' => $iddatadb]);
|
$campione["Color"] = $part["color"] ?? "";
|
||||||
|
$campione["Mix"] = $part["mix"] ?? "";
|
||||||
|
|
||||||
// Logga il successo della creazione CommessaWeb
|
$campioni[] = $campione;
|
||||||
file_put_contents($logDir . '/export_lims_success.log', date('Y-m-d H:i:s') . " - CommessaWeb creata: idcommessaweb {$idcommessaweb} per iddatadb {$iddatadb}\n", FILE_APPEND);
|
|
||||||
|
|
||||||
// Step 2: Aggiorna CommesseCustomFields
|
|
||||||
$apiClient->patch("/api/odata/CommessaWeb({$idcommessaweb})", $payloadCustomFields);
|
|
||||||
|
|
||||||
// Step 3: Crea Campioni
|
|
||||||
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
|
||||||
$payloadCampione['Commessa'] = $idcommessaweb;
|
|
||||||
$apiClient->post('/api/odata/Campione', $payloadCampione);
|
|
||||||
$payloadsCampioni[$index] = $payloadCampione; // Aggiorna il payload con Commessa
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 4: Invia Commessa
|
|
||||||
$apiClient->post("/api/odata/CommessaWeb({$idcommessaweb})/InviaCommessa", $payloadInviaCommessa);
|
|
||||||
|
|
||||||
// Step 5: Recupera il numero commessaweb (opzionale)
|
|
||||||
$commessaData = $apiClient->get("/api/odata/CommessaWeb({$idcommessaweb})");
|
|
||||||
$commessaweb = $commessaData['Numero'] ?? '';
|
|
||||||
if ($commessaweb) {
|
|
||||||
$updateStmt = $pdo->prepare("UPDATE datadb SET commessaweb = :commessaweb WHERE iddatadb = :iddatadb");
|
|
||||||
$updateStmt->execute(['commessaweb' => $commessaweb, 'iddatadb' => $iddatadb]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aggiorna lo status a 'l' (To LIMS)
|
|
||||||
$updateStmt = $pdo->prepare("UPDATE datadb SET status = 'l' WHERE iddatadb = :iddatadb");
|
|
||||||
$updateStmt->execute(['iddatadb' => $iddatadb]);
|
|
||||||
|
|
||||||
// Risposta di successo (flusso reale)
|
|
||||||
echo json_encode([
|
|
||||||
'success' => true,
|
|
||||||
'mode' => 'real',
|
|
||||||
'message' => "Dati inviati al LIMS con successo",
|
|
||||||
'idcommessaweb' => $idcommessaweb,
|
|
||||||
'commessaweb' => $commessaweb,
|
|
||||||
'payload_commessa' => $payloadCommessa,
|
|
||||||
'payload_customfields' => $payloadCustomFields,
|
|
||||||
'payload_campioni' => $payloadsCampioni,
|
|
||||||
'payload_invia_commessa' => $payloadInviaCommessa
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
|
||||||
// Log dell'errore
|
// Salva log per STEP 6
|
||||||
file_put_contents($logDir . '/export_lims_error.log', date('Y-m-d H:i:s') . ' - Flusso ' . ($simulate ? 'simulato' : 'reale') . ' fallito: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
$logFileStep6 = $logDir . "commessa_{$commessaId}_campioni_step6_" . time() . ".txt";
|
||||||
http_response_code(500);
|
file_put_contents($logFileStep6, $logContentStep6);
|
||||||
|
|
||||||
|
// 🔹 STEP 7: Update Custom Fields for CommessaWeb
|
||||||
|
if (!empty($fieldValues)) {
|
||||||
|
// GET con espansione per CustomField
|
||||||
|
$expand = "CommesseCustomFields(\$expand=CustomField)";
|
||||||
|
$commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
||||||
|
|
||||||
|
// Logga il GET
|
||||||
|
$logContentGet = "curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••'\n\n" .
|
||||||
|
"RESPONSE:\n" . json_encode($commessaWithFields, JSON_PRETTY_PRINT);
|
||||||
|
$logFileGet = $logDir . "commessa_{$commessaId}_get_step7_" . time() . ".txt";
|
||||||
|
file_put_contents($logFileGet, $logContentGet);
|
||||||
|
|
||||||
|
// Prepara payload PATCH
|
||||||
|
$commessaCustomFields = [];
|
||||||
|
foreach ($commessaWithFields["CommesseCustomFields"] as $customField) {
|
||||||
|
$definitionId = (int) ($customField["CustomField"]["IdCustomField"] ?? 0);
|
||||||
|
$fieldId = (int) $customField["IdCommesseCustomFields"];
|
||||||
|
$currentValue = $customField["Valore"] ?? '';
|
||||||
|
$fieldType = $customField["CustomField"]["Tipo"] ?? '';
|
||||||
|
$newValue = isset($valueMap[$definitionId]) ? $valueMap[$definitionId] : $currentValue;
|
||||||
|
|
||||||
|
// Valida se il campo è di tipo Data
|
||||||
|
if ($fieldType === 'Data' && $newValue !== $currentValue) {
|
||||||
|
$newValue = validateDate($newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
$commessaCustomFields[] = [
|
||||||
|
"IdCommesseCustomFields" => $fieldId,
|
||||||
|
"Valore" => $newValue
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($commessaCustomFields)) {
|
||||||
|
$updatePayload = ["CommesseCustomFields" => $commessaCustomFields];
|
||||||
|
|
||||||
|
// Logga payload e response
|
||||||
|
$jsonPayload = json_encode($updatePayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
|
$logContentStep7 = "curl --location --request PATCH '{$apiBaseUrl}CommessaWeb({$commessaId})' \\\n" .
|
||||||
|
"--header 'Content-Type: application/json' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••' \\\n" .
|
||||||
|
"--data '{$jsonPayload}'";
|
||||||
|
|
||||||
|
$patchResponse = $api->patch("CommessaWeb({$commessaId})", $updatePayload);
|
||||||
|
|
||||||
|
$logContentStep7 .= "\n\nRESPONSE:\n" . json_encode($patchResponse, JSON_PRETTY_PRINT);
|
||||||
|
$logFileStep7 = $logDir . "commessa_{$commessaId}_update_step7_" . time() . ".txt";
|
||||||
|
file_put_contents($logFileStep7, $logContentStep7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 STEP 8: Update datadb with idcommessaweb, commessaweb, and status
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
UPDATE datadb
|
||||||
|
SET idcommessaweb = :idcommessaweb, commessaweb = :commessaweb, status = 'l'
|
||||||
|
WHERE iddatadb = :iddatadb
|
||||||
|
");
|
||||||
|
$stmt->execute([
|
||||||
|
'idcommessaweb' => $commessaId,
|
||||||
|
'commessaweb' => $commessaWebCode,
|
||||||
|
'iddatadb' => $iddatadb
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 🔹 STEP 9: Send CommessaWeb to laboratory (commentato come richiesto)
|
||||||
|
/*
|
||||||
|
$sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []);
|
||||||
|
|
||||||
|
// Logga il POST
|
||||||
|
$logContentStep9 = "curl --location --request POST '{$apiBaseUrl}CommessaWeb({$commessaId})/InviaCommessa' \\\n" .
|
||||||
|
"--header 'Content-Type: application/json' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••' \\\n" .
|
||||||
|
"--data '{}'\n\n" .
|
||||||
|
"RESPONSE:\n" . json_encode($sendResult, JSON_PRETTY_PRINT);
|
||||||
|
$logFileStep9 = $logDir . "commessa_{$commessaId}_send_step9_" . time() . ".txt";
|
||||||
|
file_put_contents($logFileStep9, $logContentStep9);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 🔹 STEP 10: GET di controllo post-PATCH
|
||||||
|
$expand = "CommesseCustomFields(\$expand=CustomField)";
|
||||||
|
$commessaAfterPatch = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
||||||
|
|
||||||
|
// Logga il GET di controllo
|
||||||
|
$logContentStep10 = "curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••'\n\n" .
|
||||||
|
"RESPONSE:\n" . json_encode($commessaAfterPatch, JSON_PRETTY_PRINT);
|
||||||
|
$logFileStep10 = $logDir . "commessa_{$commessaId}_get_step10_" . time() . ".txt";
|
||||||
|
file_put_contents($logFileStep10, $logContentStep10);
|
||||||
|
|
||||||
|
// 🔹 STEP 11: Prepare final response
|
||||||
|
$finalCommessa = [
|
||||||
|
"Cliente" => $clienteId,
|
||||||
|
"SchemaCustomField" => $schemaId,
|
||||||
|
"Richiedente" => $commessaWeb["Richiedente"] ?? "Web Import",
|
||||||
|
"Descrizione" => $commessaWeb["Descrizione"] ?? "",
|
||||||
|
"CommesseCustomFields" => $commessaAfterPatch["CommesseCustomFields"] ?? [],
|
||||||
|
"Campioni" => $campioni,
|
||||||
|
"Inviata" => 0 // Non inviato, come richiesto
|
||||||
|
];
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'success' => false,
|
"success" => true,
|
||||||
'mode' => $simulate ? 'simulated' : 'real',
|
"commessaWeb" => $finalCommessa,
|
||||||
'message' => 'Errore: ' . $e->getMessage()
|
"commessaWebApiResponse" => $commessaWeb, // Incluso per debug
|
||||||
|
"totalCampioni" => count($campioni),
|
||||||
|
"totalCustomFields" => count($commessaAfterPatch["CommesseCustomFields"] ?? []),
|
||||||
|
"message" => "Export successful",
|
||||||
|
"logFiles" => [
|
||||||
|
"step5_create" => $logFileStep5,
|
||||||
|
"step6_campioni" => $logFileStep6,
|
||||||
|
"step7_patch" => $logFileStep7,
|
||||||
|
"step10_get" => $logFileStep10
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log("LIMS Export Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
"success" => false,
|
||||||
|
"message" => "Export failed: " . $e->getMessage(),
|
||||||
|
"logFiles" => [
|
||||||
|
"step5_create" => $logFileStep5 ?? null,
|
||||||
|
"step6_campioni" => $logFileStep6 ?? null,
|
||||||
|
"step7_patch" => $logFileStep7 ?? null,
|
||||||
|
"step10_get" => $logFileStep10 ?? null
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ error_reporting(E_ALL);
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$api = VisualLimsApiClient::getInstance();
|
$api = VisualLimsApiClient::getInstance();
|
||||||
$rapporto_id = 515081;
|
$rapporto_id = 533329;
|
||||||
|
|
||||||
// Costruzione manuale dell'endpoint con espansione annidata
|
// Costruzione manuale dell'endpoint con espansione annidata
|
||||||
$endpoint = "Rapporto($rapporto_id)?\$expand=CampioniDatiRapporto(\$expand=AnalisiDatiRapporto,CustomFieldsDatiRapporto)";
|
$endpoint = "Rapporto($rapporto_id)?\$expand=CampioniDatiRapporto(\$expand=AnalisiDatiRapporto,CustomFieldsDatiRapporto)";
|
||||||
|
|||||||
@@ -662,6 +662,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
} else {
|
} else {
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
||||||
}
|
}
|
||||||
|
// Status (subito dopo main_field)
|
||||||
|
$fixedColumnsReduced = ['status'];
|
||||||
|
foreach ($fixedColumnsReduced as $col) {
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
||||||
|
}
|
||||||
// Campi automatici (escluso main_field)
|
// Campi automatici (escluso main_field)
|
||||||
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
@@ -712,11 +717,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$manualIndex++;
|
$manualIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Colonne status, Import Reference Code, filename_import
|
// Colonne Import Reference Code, filename_import
|
||||||
$fixedColumnsReduced = ['status'];
|
|
||||||
foreach ($fixedColumnsReduced as $col) {
|
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
|
||||||
}
|
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Import Reference Code
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Import Reference Code
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // filename_import
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // filename_import
|
||||||
// AWB Number e Tracking Info
|
// AWB Number e Tracking Info
|
||||||
@@ -734,6 +735,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mainFieldMapping['field_label']) . "<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mainFieldMapping['field_label']) . "<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
}
|
}
|
||||||
|
// Header per status (subito dopo main_field)
|
||||||
|
foreach ($fixedColumnsReduced as $col) {
|
||||||
|
$displayName = $slugMapping[$col] ?? $col;
|
||||||
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
|
||||||
|
$headerIndex++;
|
||||||
|
}
|
||||||
// Header per campi automatici (escluso main_field)
|
// Header per campi automatici (escluso main_field)
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
@@ -748,12 +755,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Header per status, Import Reference Code, filename_import
|
// Header per Import Reference Code, filename_import
|
||||||
foreach ($fixedColumnsReduced as $col) {
|
|
||||||
$displayName = $slugMapping[$col] ?? $col;
|
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
|
|
||||||
$headerIndex++;
|
|
||||||
}
|
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>File<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>File<div class='resizer'></div></div>";
|
||||||
@@ -770,13 +772,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<div style="display: flex; gap: 5px; justify-content: center;">
|
<div style="display: flex; gap: 5px; justify-content: center;">
|
||||||
<?php if (!$is_readonly): ?>
|
<?php if (!$is_readonly): ?>
|
||||||
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-save"></i></button>
|
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-save"></i></button>
|
||||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
|
|
||||||
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ffc107; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-puzzle-piece"></i></button>
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-save"></i></button>
|
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-save"></i></button>
|
||||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-camera"></i></button>
|
|
||||||
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-puzzle-piece"></i></button>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
|
||||||
|
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ffc107; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-puzzle-piece"></i></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
@@ -806,6 +806,25 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
echo "</div>";
|
echo "</div>";
|
||||||
$cellIndex++;
|
$cellIndex++;
|
||||||
}
|
}
|
||||||
|
// Status (subito dopo main_field)
|
||||||
|
$fixedColumnsReduced = ['status'];
|
||||||
|
foreach ($fixedColumnsReduced as $col) {
|
||||||
|
$value = $row[$col] ?? '';
|
||||||
|
echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||||
|
if ($col === 'status') {
|
||||||
|
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
|
||||||
|
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
|
||||||
|
// Aggiungi il numero di commessaweb se lo status è 'l'
|
||||||
|
if ($value === 'l') {
|
||||||
|
$commessaWeb = isset($row['commessaweb']) ? htmlspecialchars($row['commessaweb']) : '';
|
||||||
|
$badgeText .= " ($commessaWeb)";
|
||||||
|
}
|
||||||
|
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
|
||||||
|
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
|
||||||
|
}
|
||||||
|
echo "</div>";
|
||||||
|
$cellIndex++;
|
||||||
|
}
|
||||||
// Campi automatici (escluso main_field)
|
// Campi automatici (escluso main_field)
|
||||||
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
@@ -863,20 +882,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$manualIndex++;
|
$manualIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Colonna status
|
|
||||||
$fixedColumnsReduced = ['status'];
|
|
||||||
foreach ($fixedColumnsReduced as $col) {
|
|
||||||
$value = $row[$col] ?? '';
|
|
||||||
echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
|
||||||
if ($col === 'status') {
|
|
||||||
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
|
|
||||||
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
|
|
||||||
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
|
|
||||||
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
|
|
||||||
}
|
|
||||||
echo "</div>";
|
|
||||||
$cellIndex++;
|
|
||||||
}
|
|
||||||
// Colonne Import Reference Code e filename_import
|
// Colonne Import Reference Code e filename_import
|
||||||
echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||||
echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>";
|
echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>";
|
||||||
|
|||||||
@@ -1,17 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
// Abilita errori per debug
|
|
||||||
ini_set('display_errors', 1);
|
|
||||||
ini_set('display_startup_errors', 1);
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
ini_set('log_errors', 1);
|
|
||||||
ini_set('error_log', __DIR__ . '/import_debug.log');
|
|
||||||
if (!file_exists(__DIR__ . '/import_debug.log')) {
|
|
||||||
file_put_contents(__DIR__ . '/import_debug.log', "Inizio importazione alle " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log iniziale
|
|
||||||
error_log("Inizio importazione alle " . date('Y-m-d H:i:s'));
|
|
||||||
|
|
||||||
include('include/headscript.php');
|
include('include/headscript.php');
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !isset($_POST['selected_rows']) || !isset($_POST['filename'])) {
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !isset($_POST['selected_rows']) || !isset($_POST['filename'])) {
|
||||||
@@ -25,11 +12,6 @@ $columns = json_decode($_POST['columns'], true) ?? $_SESSION['columns'];
|
|||||||
$rows = json_decode($_POST['rows'], true) ?? $_SESSION['rows'];
|
$rows = json_decode($_POST['rows'], true) ?? $_SESSION['rows'];
|
||||||
$newFilename = htmlspecialchars($_POST['filename']) ?? $_SESSION['filename'];
|
$newFilename = htmlspecialchars($_POST['filename']) ?? $_SESSION['filename'];
|
||||||
|
|
||||||
// Log dei dati ricevuti
|
|
||||||
error_log("Received Data - Template ID: $template_id, Selected Rows: " . json_encode($selected_rows));
|
|
||||||
error_log("Columns: " . json_encode($columns));
|
|
||||||
error_log("Rows: " . json_encode($rows));
|
|
||||||
|
|
||||||
// Recupera l'ID dell'utente loggato
|
// Recupera l'ID dell'utente loggato
|
||||||
$user_id = $iduserlogin ?? 1;
|
$user_id = $iduserlogin ?? 1;
|
||||||
|
|
||||||
@@ -39,8 +21,8 @@ $pdo = $db->getConnection();
|
|||||||
// Genera un UUID univoco per importreferencecode
|
// Genera un UUID univoco per importreferencecode
|
||||||
$importReferenceCode = date('YmdHis') . '-' . uniqid();
|
$importReferenceCode = date('YmdHis') . '-' . uniqid();
|
||||||
|
|
||||||
// Recupera tutti i mapping dal template
|
// Recupera tutti i mapping dal template, includendo is_visible_import
|
||||||
$stmt = $pdo->prepare("SELECT id, excel_column, data_type, is_required, manual_default, is_manual, field_label, field_id, main_field FROM template_mapping WHERE template_id = ?");
|
$stmt = $pdo->prepare("SELECT id, excel_column, data_type, is_required, manual_default, is_manual, field_label, field_id, main_field, is_visible_import FROM template_mapping WHERE template_id = ?");
|
||||||
$stmt->execute([$template_id]);
|
$stmt->execute([$template_id]);
|
||||||
$allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
@@ -52,7 +34,7 @@ if (empty($allMappings)) {
|
|||||||
// Trova il campo main_field
|
// Trova il campo main_field
|
||||||
$mainFieldMapping = null;
|
$mainFieldMapping = null;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if ($mapping['main_field'] == 1) {
|
if ($mapping['main_field'] == 1 && $mapping['is_visible_import'] == 1) {
|
||||||
$mainFieldMapping = $mapping;
|
$mainFieldMapping = $mapping;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -97,6 +79,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
||||||
<?php include('cssinclude.php'); ?>
|
<?php include('cssinclude.php'); ?>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2Lw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2Lw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/flatpickr.min.css">
|
||||||
<style>
|
<style>
|
||||||
.cell-changed {
|
.cell-changed {
|
||||||
background-color: #fff3b0 !important;
|
background-color: #fff3b0 !important;
|
||||||
@@ -415,6 +398,17 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
#exportResponseModal .modal-backdrop {
|
#exportResponseModal .modal-backdrop {
|
||||||
z-index: 1299 !important;
|
z-index: 1299 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.add-part-btn {
|
||||||
|
padding: 2px 5px;
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 1;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flatpickr-input {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
@@ -453,7 +447,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<div class="grid-cell" style="flex: 0 0 150px;">
|
<div class="grid-cell" style="flex: 0 0 150px;">
|
||||||
<?php
|
<?php
|
||||||
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
|
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
|
||||||
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today') {
|
if ($mainFieldMapping['data_type'] === 'Data' && $mainFieldMapping['manual_default'] === 'today') {
|
||||||
$fieldValue = date('Y-m-d');
|
$fieldValue = date('Y-m-d');
|
||||||
}
|
}
|
||||||
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
||||||
@@ -463,8 +457,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
echo "<option value=''>Seleziona...</option>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
|
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
|
||||||
} elseif ($mainFieldMapping['data_type'] === 'DATE') {
|
} elseif ($mainFieldMapping['data_type'] === 'Data') {
|
||||||
echo "<input type='date' class='custom-field $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='text' class='custom-field date-picker $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
||||||
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
|
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
|
||||||
} elseif ($mainFieldMapping['data_type'] === 'INT') {
|
} elseif ($mainFieldMapping['data_type'] === 'INT') {
|
||||||
echo "<input type='number' class='custom-field $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='number' class='custom-field $inputClass' data-column='main_field' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
||||||
@@ -480,7 +474,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<?php
|
<?php
|
||||||
$autoIndex = 0;
|
$autoIndex = 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
|
||||||
$inputClass = 'auto-input';
|
$inputClass = 'auto-input';
|
||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||||
@@ -498,20 +492,20 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
$manualIndex = 0;
|
$manualIndex = 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
|
||||||
$fieldValue = $mapping['manual_default'] ?? '';
|
$fieldValue = $mapping['manual_default'] ?? '';
|
||||||
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
|
if ($mapping['data_type'] === 'Data' && $mapping['manual_default'] === 'today') {
|
||||||
$fieldValue = date('Y-m-d');
|
$fieldValue = date('Y-m-d');
|
||||||
}
|
}
|
||||||
$inputClass = 'manual-input';
|
$inputClass = 'manual-input';
|
||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
||||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
echo "<option value=''>Seleziona...</option>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'Data') {
|
||||||
echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='text' class='custom-field date-picker $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
} elseif ($mapping['data_type'] === 'INT') {
|
} elseif ($mapping['data_type'] === 'INT') {
|
||||||
echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
} else {
|
} else {
|
||||||
@@ -522,6 +516,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$manualIndex++;
|
$manualIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Aggiunta per Tested Component (senza propagate)
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>";
|
echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>";
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>";
|
echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>";
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
||||||
@@ -543,17 +539,20 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<?php
|
<?php
|
||||||
$headerIndex = $mainFieldMapping ? 3 : 2;
|
$headerIndex = $mainFieldMapping ? 3 : 2;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Aggiunta header per Tested Component
|
||||||
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Tested Component<div class='resizer'></div></div>";
|
||||||
|
$headerIndex++;
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
|
||||||
@@ -569,7 +568,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<?php foreach ($importedData as $index => $row): ?>
|
<?php foreach ($importedData as $index => $row): ?>
|
||||||
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
||||||
<div class="grid-cell button-cell" style="flex: 0 0 210px; position: relative;">
|
<div class="grid-cell button-cell" style="flex: 0 0 210px; position: relative;">
|
||||||
<button type="button" class="export-lims-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Export to LIMS" style="background: #eb0b0bff; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-upload"></i></button>
|
<!-- commented only for admin roles -->
|
||||||
|
<?php if ((Auth::user()->hasRole('Admin'))) : ?>
|
||||||
|
<button type="button" class="export-lims-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Export to LIMS" style="background: #eb0b0bff; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-upload"></i></button>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" title="Save" style="background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-save"></i></button>
|
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" title="Save" style="background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-save"></i></button>
|
||||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Photos" style="background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-camera"></i></button>
|
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Photos" style="background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-camera"></i></button>
|
||||||
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Parts" style="background: #ffc107; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-puzzle-piece"></i></button>
|
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Parts" style="background: #ffc107; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-puzzle-piece"></i></button>
|
||||||
@@ -579,7 +582,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$detail = array_filter($manualDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id'] && $d['datadb_id'] == $row['iddatadb']);
|
$detail = array_filter($manualDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id'] && $d['datadb_id'] == $row['iddatadb']);
|
||||||
$detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']];
|
$detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']];
|
||||||
$fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? '';
|
$fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? '';
|
||||||
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today' && empty($fieldValue)) {
|
if ($mainFieldMapping['data_type'] === 'Data' && $mainFieldMapping['manual_default'] === 'today' && empty($fieldValue)) {
|
||||||
$fieldValue = date('Y-m-d');
|
$fieldValue = date('Y-m-d');
|
||||||
}
|
}
|
||||||
$requiredClass = ($mainFieldMapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
$requiredClass = ($mainFieldMapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
||||||
@@ -591,8 +594,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<select name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" class="cell-input dropdown-select <?= $inputClass ?>" data-mapping-id="<?= $mainFieldMapping['id'] ?>" data-field-id="<?= $mainFieldMapping['field_id'] ?>" data-selected-value="<?= htmlspecialchars($fieldValue) ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
<select name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" class="cell-input dropdown-select <?= $inputClass ?>" data-mapping-id="<?= $mainFieldMapping['id'] ?>" data-field-id="<?= $mainFieldMapping['field_id'] ?>" data-selected-value="<?= htmlspecialchars($fieldValue) ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
||||||
<option value="">Seleziona...</option>
|
<option value="">Seleziona...</option>
|
||||||
</select>
|
</select>
|
||||||
<?php elseif ($mainFieldMapping['data_type'] === 'DATE'): ?>
|
<?php elseif ($mainFieldMapping['data_type'] === 'Data'): ?>
|
||||||
<input type="date" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
<input type="text" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input date-picker <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
||||||
<?php elseif ($mainFieldMapping['data_type'] === 'INT'): ?>
|
<?php elseif ($mainFieldMapping['data_type'] === 'INT'): ?>
|
||||||
<input type="number" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
<input type="number" name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" value="<?= htmlspecialchars($fieldValue) ?>" class="cell-input <?= $inputClass ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
@@ -611,7 +614,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
|
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
|
||||||
$autoIndex = 0;
|
$autoIndex = 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
|
||||||
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
||||||
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
||||||
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
||||||
@@ -623,8 +626,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
echo "<option value=''>Seleziona...</option>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'Data') {
|
||||||
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input date-picker $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
} elseif ($mapping['data_type'] === 'INT') {
|
} elseif ($mapping['data_type'] === 'INT') {
|
||||||
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
} else {
|
} else {
|
||||||
@@ -637,11 +640,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
$manualIndex = 0;
|
$manualIndex = 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) {
|
||||||
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
||||||
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
||||||
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
||||||
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today' && empty($fieldValue)) {
|
if ($mapping['data_type'] === 'Data' && $mapping['manual_default'] === 'today' && empty($fieldValue)) {
|
||||||
$fieldValue = date('Y-m-d');
|
$fieldValue = date('Y-m-d');
|
||||||
}
|
}
|
||||||
$requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
$requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
||||||
@@ -652,8 +655,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
echo "<option value=''>Seleziona...</option>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'Data') {
|
||||||
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='text' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input date-picker $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
} elseif ($mapping['data_type'] === 'INT') {
|
} elseif ($mapping['data_type'] === 'INT') {
|
||||||
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
echo "<input type='number' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||||
} else {
|
} else {
|
||||||
@@ -664,6 +667,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$manualIndex++;
|
$manualIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Aggiunta cella per Tested Component
|
||||||
|
echo "<div class='grid-cell editable-cell' data-col='tested_component' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px; display: flex; align-items: center;'>";
|
||||||
|
echo "<input type='text' name='rows[$index][tested_component]' value='' class='cell-input manual-input' style='flex: 1; margin-right: 5px;'>";
|
||||||
|
echo "<button type='button' class='add-part-btn btn btn-sm btn-primary' data-row='$index'><i class='fas fa-plus'></i></button>";
|
||||||
|
echo "</div>";
|
||||||
|
$cellIndex++;
|
||||||
?>
|
?>
|
||||||
<div class="grid-cell" style="flex: 0 0 200px;">
|
<div class="grid-cell" style="flex: 0 0 200px;">
|
||||||
<select name="rows[<?= $index ?>][carrier]" class="carrier-select">
|
<select name="rows[<?= $index ?>][carrier]" class="carrier-select">
|
||||||
@@ -715,22 +724,64 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<?php include('jsinclude.php'); ?>
|
<?php include('jsinclude.php'); ?>
|
||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/flatpickr.min.js"></script>
|
||||||
<script src="photos.js"></script>
|
<script src="photos.js"></script>
|
||||||
<script src="parts.js"></script>
|
<script src="parts.js"></script>
|
||||||
<script src="tracking.js"></script>
|
<script src="tracking.js"></script>
|
||||||
<script src="export_to_lims.js"></script>
|
<script src="export_to_lims.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
// Initialize Flatpickr for all date inputs
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log("Page loaded, initializing event listeners");
|
flatpickr(".date-picker", {
|
||||||
|
dateFormat: "Y-m-d",
|
||||||
|
allowInput: true,
|
||||||
|
onOpen: function(selectedDates, dateStr, instance) {
|
||||||
|
instance.input.closest('.grid-cell').classList.add('expanded');
|
||||||
|
},
|
||||||
|
onClose: function(selectedDates, dateStr, instance) {
|
||||||
|
instance.input.closest('.grid-cell').classList.remove('expanded');
|
||||||
|
// Trigger change event to handle unsaved changes
|
||||||
|
const event = new Event('change');
|
||||||
|
instance.input.dispatchEvent(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const inputs = document.querySelectorAll(".cell-input, .dropdown-select, .carrier-select, .awb-input");
|
$(document).on("click", ".export-lims-btn", function() {
|
||||||
|
let rowId = $(this).data("row");
|
||||||
|
let idDataDb = $(this).data("iddatadb");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "export_to_lims.php",
|
||||||
|
method: "POST",
|
||||||
|
data: {
|
||||||
|
iddatadb: idDataDb
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
beforeSend: function() {
|
||||||
|
alert("Export started in background for row " + rowId);
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.success) {
|
||||||
|
alert(response.message);
|
||||||
|
} else {
|
||||||
|
alert("❌ Error: " + response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
alert("❌ AJAX error: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
const inputs = document.querySelectorAll(".cell-input, .dropdown-select, .carrier-select, .awb-input, .date-picker");
|
||||||
const unsavedDiv = document.getElementById("unsavedChanges");
|
const unsavedDiv = document.getElementById("unsavedChanges");
|
||||||
const changedList = document.getElementById("changedFields");
|
const changedList = document.getElementById("changedFields");
|
||||||
let hasChanges = false;
|
let hasChanges = false;
|
||||||
let changedFields = {};
|
let changedFields = {};
|
||||||
|
|
||||||
function renderChangedList() {
|
function renderChangedList() {
|
||||||
console.log("Rendering changed fields list:", changedFields);
|
|
||||||
changedList.innerHTML = "";
|
changedList.innerHTML = "";
|
||||||
Object.keys(changedFields).forEach(rowIndex => {
|
Object.keys(changedFields).forEach(rowIndex => {
|
||||||
const fields = changedFields[rowIndex];
|
const fields = changedFields[rowIndex];
|
||||||
@@ -745,7 +796,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
|
|
||||||
inputs.forEach(el => {
|
inputs.forEach(el => {
|
||||||
el.addEventListener("change", () => {
|
el.addEventListener("change", () => {
|
||||||
console.log("Input changed:", el.name);
|
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
const gridCell = el.closest(".grid-cell");
|
const gridCell = el.closest(".grid-cell");
|
||||||
const colIndex = gridCell?.dataset.index;
|
const colIndex = gridCell?.dataset.index;
|
||||||
@@ -776,7 +826,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
document.querySelectorAll(".save-btn").forEach(btn => {
|
document.querySelectorAll(".save-btn").forEach(btn => {
|
||||||
btn.addEventListener("click", () => {
|
btn.addEventListener("click", () => {
|
||||||
const rowIndex = btn.dataset.row;
|
const rowIndex = btn.dataset.row;
|
||||||
console.log(`Saving row ${rowIndex}`);
|
|
||||||
const row = btn.closest('.grid-row');
|
const row = btn.closest('.grid-row');
|
||||||
const iddatadb = row.getAttribute('data-id');
|
const iddatadb = row.getAttribute('data-id');
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -803,7 +852,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log("Save response:", data);
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
const cells = row.querySelectorAll('.grid-cell');
|
const cells = row.querySelectorAll('.grid-cell');
|
||||||
cells.forEach(cell => {
|
cells.forEach(cell => {
|
||||||
@@ -827,14 +875,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Save error:", error);
|
|
||||||
alert('Errore durante il salvataggio: ' + error.message);
|
alert('Errore durante il salvataggio: ' + error.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector('.save-all-btn').addEventListener('click', async () => {
|
document.querySelector('.save-all-btn').addEventListener('click', async () => {
|
||||||
console.log("Saving all rows");
|
|
||||||
const rows = document.querySelectorAll('.grid-row');
|
const rows = document.querySelectorAll('.grid-row');
|
||||||
let successCount = 0;
|
let successCount = 0;
|
||||||
let errorMessages = [];
|
let errorMessages = [];
|
||||||
@@ -842,16 +888,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const saveBtn = row.querySelector('.save-btn');
|
const saveBtn = row.querySelector('.save-btn');
|
||||||
if (!saveBtn) {
|
if (!saveBtn) {
|
||||||
console.warn(`No save button found in row with data-id: ${row.getAttribute('data-id')}`);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const rowIndex = saveBtn.dataset.row;
|
const rowIndex = saveBtn.dataset.row;
|
||||||
const iddatadb = row.getAttribute('data-id');
|
const iddatadb = row.getAttribute('data-id');
|
||||||
if (!rowIndex || !iddatadb) {
|
if (!rowIndex || !iddatadb) {
|
||||||
console.warn(`Missing rowIndex or iddatadb in row:`, row);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
console.log(`Processing row ${rowIndex} with iddatadb ${iddatadb}`);
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}][details]"], select[name^="rows[${rowIndex}][details]"]`);
|
const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}][details]"], select[name^="rows[${rowIndex}][details]"]`);
|
||||||
@@ -875,7 +918,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
console.log(`Row ${rowIndex} save response:`, data);
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
successCount++;
|
successCount++;
|
||||||
const cells = row.querySelectorAll('.grid-cell');
|
const cells = row.querySelectorAll('.grid-cell');
|
||||||
@@ -895,14 +937,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${data.message}`);
|
errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${data.message}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Row ${rowIndex} save error:`, error);
|
|
||||||
errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${error.message}`);
|
errorMessages.push(`Riga ${parseInt(rowIndex) + 1}: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderChangedList();
|
renderChangedList();
|
||||||
hasChanges = Object.keys(changedFields).length > 0;
|
hasChanges = Object.keys(changedFields).length > 0;
|
||||||
console.log(`Save all completed: ${successCount} successes, ${errorMessages.length} errors`);
|
|
||||||
|
|
||||||
if (errorMessages.length === 0) {
|
if (errorMessages.length === 0) {
|
||||||
alert(`Tutte le ${successCount} righe salvate con successo!`);
|
alert(`Tutte le ${successCount} righe salvate con successo!`);
|
||||||
@@ -911,8 +951,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", function(e) {
|
window.addEventListener("beforeunload", function(e) {
|
||||||
if (hasChanges) {
|
if (hasChanges) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -924,10 +962,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
// Gestisci la chiusura dei modali per rimuovere i backdrop
|
// Gestisci la chiusura dei modali per rimuovere i backdrop
|
||||||
document.querySelectorAll('#exportConfirmModal, #exportResponseModal').forEach(modal => {
|
document.querySelectorAll('#exportConfirmModal, #exportResponseModal').forEach(modal => {
|
||||||
modal.addEventListener('hidden.bs.modal', () => {
|
modal.addEventListener('hidden.bs.modal', () => {
|
||||||
console.log(`Modal ${modal.id} closed, removing backdrops`);
|
|
||||||
// Rimuovi tutti i backdrop residui
|
// Rimuovi tutti i backdrop residui
|
||||||
document.querySelectorAll('.modal-backdrop').forEach(backdrop => {
|
document.querySelectorAll('.modal-backdrop').forEach(backdrop => {
|
||||||
console.log('Removing backdrop:', backdrop);
|
|
||||||
backdrop.remove();
|
backdrop.remove();
|
||||||
});
|
});
|
||||||
// Ripristina il body
|
// Ripristina il body
|
||||||
@@ -943,7 +979,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log("Initializing cell expansion and propagation");
|
|
||||||
const inputs = document.querySelectorAll('.cell-input');
|
const inputs = document.querySelectorAll('.cell-input');
|
||||||
inputs.forEach(input => {
|
inputs.forEach(input => {
|
||||||
input.addEventListener('focus', function() {
|
input.addEventListener('focus', function() {
|
||||||
@@ -957,7 +992,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
const propagateButtons = document.querySelectorAll('.propagate-btn');
|
const propagateButtons = document.querySelectorAll('.propagate-btn');
|
||||||
propagateButtons.forEach(button => {
|
propagateButtons.forEach(button => {
|
||||||
button.addEventListener('click', function() {
|
button.addEventListener('click', function() {
|
||||||
console.log("Propagating value for column:", this.getAttribute('data-column'));
|
|
||||||
const column = this.getAttribute('data-column');
|
const column = this.getAttribute('data-column');
|
||||||
const input = this.previousElementSibling;
|
const input = this.previousElementSibling;
|
||||||
const value = input.value;
|
const value = input.value;
|
||||||
@@ -979,6 +1013,17 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
targetInput.setAttribute('data-selected-value', value);
|
targetInput.setAttribute('data-selected-value', value);
|
||||||
const event = new Event('change');
|
const event = new Event('change');
|
||||||
targetInput.dispatchEvent(event);
|
targetInput.dispatchEvent(event);
|
||||||
|
} else if (targetInput.classList.contains('date-picker')) {
|
||||||
|
// Update Flatpickr instance
|
||||||
|
const flatpickrInstance = targetInput._flatpickr;
|
||||||
|
if (flatpickrInstance && value) {
|
||||||
|
flatpickrInstance.setDate(value, true);
|
||||||
|
}
|
||||||
|
const event = new Event('change');
|
||||||
|
targetInput.dispatchEvent(event);
|
||||||
|
} else {
|
||||||
|
const event = new Event('change');
|
||||||
|
targetInput.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -994,7 +1039,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
let columnIndex = 0;
|
let columnIndex = 0;
|
||||||
resizers.forEach(resizer => {
|
resizers.forEach(resizer => {
|
||||||
resizer.addEventListener('mousedown', function(e) {
|
resizer.addEventListener('mousedown', function(e) {
|
||||||
console.log("Starting column resize");
|
|
||||||
currentResizer = resizer;
|
currentResizer = resizer;
|
||||||
const header = resizer.parentElement;
|
const header = resizer.parentElement;
|
||||||
columnIndex = header.getAttribute('data-index');
|
columnIndex = header.getAttribute('data-index');
|
||||||
@@ -1017,7 +1061,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
|
|
||||||
function stopResize() {
|
function stopResize() {
|
||||||
if (currentResizer) {
|
if (currentResizer) {
|
||||||
console.log("Stopping column resize");
|
|
||||||
document.removeEventListener('mousemove', resize);
|
document.removeEventListener('mousemove', resize);
|
||||||
document.removeEventListener('mouseup', stopResize);
|
document.removeEventListener('mouseup', stopResize);
|
||||||
currentResizer = null;
|
currentResizer = null;
|
||||||
@@ -1028,13 +1071,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log("Initializing dropdown population");
|
|
||||||
const dropdownData = {};
|
const dropdownData = {};
|
||||||
|
|
||||||
async function populateDropdowns() {
|
async function populateDropdowns() {
|
||||||
const dropdowns = document.querySelectorAll('.dropdown-select');
|
const dropdowns = document.querySelectorAll('.dropdown-select');
|
||||||
if (dropdowns.length === 0) {
|
if (dropdowns.length === 0) {
|
||||||
console.log("No dropdowns found");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,7 +1086,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]);
|
const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]);
|
||||||
|
|
||||||
if (missingFieldIds.length > 0) {
|
if (missingFieldIds.length > 0) {
|
||||||
console.log("Fetching dropdown data for field IDs:", missingFieldIds);
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`get_customfield_values.php?field_ids=${missingFieldIds.join(",")}`
|
`get_customfield_values.php?field_ids=${missingFieldIds.join(",")}`
|
||||||
@@ -1053,16 +1093,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {} else {
|
||||||
console.error("Fetch error:", data.error);
|
|
||||||
} else {
|
|
||||||
for (const fieldId of Object.keys(data)) {
|
for (const fieldId of Object.keys(data)) {
|
||||||
dropdownData[fieldId] = data[fieldId] || [];
|
dropdownData[fieldId] = data[fieldId] || [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {}
|
||||||
console.error("Fetch error:", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dropdowns.forEach(dropdown => {
|
dropdowns.forEach(dropdown => {
|
||||||
@@ -1072,7 +1108,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
|
|
||||||
if (!fieldId || !dropdownData[fieldId]) {
|
if (!fieldId || !dropdownData[fieldId]) {
|
||||||
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
|
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
|
||||||
console.warn(`No data for fieldId ${fieldId}`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,7 +1126,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
|
|
||||||
if ((currentValue || selectedValue) && dropdown.value !== (currentValue || selectedValue)) {
|
if ((currentValue || selectedValue) && dropdown.value !== (currentValue || selectedValue)) {
|
||||||
dropdown.value = '';
|
dropdown.value = '';
|
||||||
console.warn(`Value ${currentValue || selectedValue} not found for fieldId ${fieldId}`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1099,6 +1133,52 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
populateDropdowns();
|
populateDropdowns();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
$(document).on('click', '.add-part-btn', function() {
|
||||||
|
const rowIndex = $(this).data('row');
|
||||||
|
const row = $(this).closest('.grid-row');
|
||||||
|
const iddatadb = row.data('id');
|
||||||
|
const input = row.find(`input[name="rows[${rowIndex}][tested_component]"]`);
|
||||||
|
const description = input.val().trim();
|
||||||
|
|
||||||
|
if (!description) {
|
||||||
|
alert('Inserisci un valore per Tested Component');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
iddatadb: iddatadb,
|
||||||
|
parts: [{
|
||||||
|
part_number: '1', // Imposta part_number a '1'
|
||||||
|
part_description: description,
|
||||||
|
mix: 'N'
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'save_parts.php',
|
||||||
|
method: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.success) {
|
||||||
|
alert('Parte aggiunta con successo!');
|
||||||
|
input.val(''); // Pulisci l'input dopo l'aggiunta
|
||||||
|
// Opzionale: aggiorna la tabella delle parti se il modal è aperto
|
||||||
|
const partsModal = $('#partsModal');
|
||||||
|
if (partsModal.hasClass('show')) {
|
||||||
|
loadParts(iddatadb);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert('Errore: ' + response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Errore durante la richiesta AJAX');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<!-- Modale di conferma per l'esportazione -->
|
<!-- Modale di conferma per l'esportazione -->
|
||||||
<div class="modal fade" id="exportConfirmModal" tabindex="-1" aria-labelledby="exportConfirmModalLabel" aria-hidden="true">
|
<div class="modal fade" id="exportConfirmModal" tabindex="-1" aria-labelledby="exportConfirmModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
|||||||
@@ -17,23 +17,27 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !i
|
|||||||
header("Location: xlstemplates_grid.php?status=error&message=" . urlencode("Richiesta non valida"));
|
header("Location: xlstemplates_grid.php?status=error&message=" . urlencode("Richiesta non valida"));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$template_id = intval($_POST['template_id']);
|
$template_id = intval($_POST['template_id']);
|
||||||
$selected_rows = $_POST['selected_rows'];
|
$selected_rows = array_map('intval', $_POST['selected_rows']);
|
||||||
$columns = json_decode($_POST['columns'], true); // Header dell'XLS
|
$columns = json_decode($_POST['columns'], true);
|
||||||
$rows = json_decode($_POST['rows'], true); // Dati dell'XLS
|
$rows = json_decode($_POST['rows'], true);
|
||||||
|
$excelrows = json_decode($_POST['excelrows'], true);
|
||||||
$newFilename = htmlspecialchars($_POST['filename']);
|
$newFilename = htmlspecialchars($_POST['filename']);
|
||||||
|
|
||||||
$_SESSION['template_id'] = $template_id;
|
$_SESSION['template_id'] = $template_id;
|
||||||
$_SESSION['selected_rows'] = $selected_rows;
|
$_SESSION['selected_rows'] = $selected_rows;
|
||||||
$_SESSION['columns'] = $columns;
|
$_SESSION['columns'] = $columns;
|
||||||
$_SESSION['rows'] = $rows;
|
$_SESSION['rows'] = $rows;
|
||||||
|
$_SESSION['excelrows'] = $excelrows;
|
||||||
$_SESSION['filename'] = $newFilename;
|
$_SESSION['filename'] = $newFilename;
|
||||||
|
|
||||||
error_log("Received Data - Template ID: $template_id, Selected Rows: " . json_encode($selected_rows));
|
error_log("Received Data - Template ID: $template_id, Selected Rows: " . json_encode($selected_rows));
|
||||||
error_log("Columns: " . json_encode($columns));
|
error_log("Columns: " . json_encode($columns));
|
||||||
error_log("Rows: " . json_encode($rows));
|
error_log("Rows: " . json_encode($rows));
|
||||||
|
error_log("Excelrows: " . json_encode($excelrows));
|
||||||
|
|
||||||
$user_id = $iduserlogin ?? 1; // Default a 1 se non definito
|
$user_id = $iduserlogin ?? 1;
|
||||||
|
|
||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
@@ -60,30 +64,38 @@ foreach ($allMappings as $mapping) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inserisci le righe selezionate in datadb (solo campi generici con templateid)
|
// Inserisci le righe selezionate in datadb
|
||||||
$insertedIds = [];
|
$insertedIds = [];
|
||||||
foreach ($selected_rows as $rowIndex) {
|
foreach ($selected_rows as $rowIndex) {
|
||||||
$row = $rows[$rowIndex];
|
$row = $rows[$rowIndex] ?? null;
|
||||||
|
$excelrow = $excelrows[$rowIndex] ?? null;
|
||||||
|
|
||||||
|
if ($row === null || $excelrow === null) {
|
||||||
|
error_log("Errore: riga o excelrow mancante per rowIndex $rowIndex");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$values = [
|
$values = [
|
||||||
$template_id, // templateid
|
$template_id,
|
||||||
$importReferenceCode, // importreferencecode
|
$importReferenceCode,
|
||||||
$newFilename, // filename_import
|
$newFilename,
|
||||||
'i', // status
|
'i',
|
||||||
$user_id, // user_id
|
$user_id,
|
||||||
null, // limscode
|
null,
|
||||||
date('Y-m-d') // importdate
|
date('Y-m-d'),
|
||||||
|
$excelrow // Aggiunto excelrow per la colonna excelrow
|
||||||
];
|
];
|
||||||
$sql = "INSERT INTO datadb (templateid, importreferencecode, filename_import, status, user_id, limscode, importdate) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
$sql = "INSERT INTO datadb (templateid, importreferencecode, filename_import, status, user_id, limscode, importdate, excelrow) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute($values);
|
$stmt->execute($values);
|
||||||
|
|
||||||
$iddatadb = $pdo->lastInsertId();
|
$iddatadb = $pdo->lastInsertId();
|
||||||
$insertedIds[] = $iddatadb;
|
$insertedIds[] = $iddatadb;
|
||||||
|
|
||||||
// Inserisci tutti i campi (automatici e manuali) in import_data_details
|
// Inserisci tutti i campi in import_data_details
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
$fieldValue = null;
|
$fieldValue = null;
|
||||||
if (!$mapping['is_manual']) { // Campi automatici dall'XLS
|
if (!$mapping['is_manual']) {
|
||||||
$excelColumn = trim($mapping['excel_column']);
|
$excelColumn = trim($mapping['excel_column']);
|
||||||
$excelColumnIndex = array_search($excelColumn, array_map('trim', $columns));
|
$excelColumnIndex = array_search($excelColumn, array_map('trim', $columns));
|
||||||
if ($excelColumnIndex !== false && isset($row[$excelColumnIndex]) && $row[$excelColumnIndex] !== '') {
|
if ($excelColumnIndex !== false && isset($row[$excelColumnIndex]) && $row[$excelColumnIndex] !== '') {
|
||||||
@@ -109,7 +121,7 @@ foreach ($selected_rows as $rowIndex) {
|
|||||||
$fieldValue = !empty($fieldValue) ? htmlspecialchars((string)$fieldValue) : ($mapping['manual_default'] ?? '');
|
$fieldValue = !empty($fieldValue) ? htmlspecialchars((string)$fieldValue) : ($mapping['manual_default'] ?? '');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else { // Campi manuali
|
} else {
|
||||||
$fieldValue = $mapping['manual_default'] ?? '';
|
$fieldValue = $mapping['manual_default'] ?? '';
|
||||||
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
|
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
|
||||||
$fieldValue = date('Y-m-d');
|
$fieldValue = date('Y-m-d');
|
||||||
@@ -129,29 +141,26 @@ $_SESSION['inserted_ids'] = $insertedIds;
|
|||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'template_id' => $template_id,
|
'template_id' => $template_id,
|
||||||
'filename' => $newFilename,
|
'filename' => $newFilename,
|
||||||
];
|
];
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<form id="redirectForm" action="import_edit2.php" method="post">
|
<form id="redirectForm" action="import_edit2.php" method="post">
|
||||||
<input type="hidden" name="template_id" value="<?= htmlspecialchars($template_id) ?>">
|
<input type="hidden" name="template_id" value="<?= htmlspecialchars($template_id) ?>">
|
||||||
<input type="hidden" name="filename" value="<?= htmlspecialchars($newFilename) ?>">
|
<input type="hidden" name="filename" value="<?= htmlspecialchars($newFilename) ?>">
|
||||||
|
<?php foreach ($selected_rows as $row): ?>
|
||||||
<?php foreach ($selected_rows as $row): ?>
|
<input type="hidden" name="selected_rows[]" value="<?= htmlspecialchars($row) ?>">
|
||||||
<input type="hidden" name="selected_rows[]" value="<?= htmlspecialchars($row) ?>">
|
<?php endforeach; ?>
|
||||||
<?php endforeach; ?>
|
<?php foreach ($insertedIds as $id): ?>
|
||||||
|
<input type="hidden" name="inserted_ids[]" value="<?= htmlspecialchars($id) ?>">
|
||||||
<?php foreach ($insertedIds as $id): ?>
|
<?php endforeach; ?>
|
||||||
<input type="hidden" name="inserted_ids[]" value="<?= htmlspecialchars($id) ?>">
|
<input type="hidden" name="columns" value='<?= json_encode($columns) ?>'>
|
||||||
<?php endforeach; ?>
|
<input type="hidden" name="rows" value='<?= json_encode($rows) ?>'>
|
||||||
|
<input type="hidden" name="excelrows" value='<?= json_encode($excelrows) ?>'>
|
||||||
<input type="hidden" name="columns" value='<?= json_encode($columns) ?>'>
|
</form>
|
||||||
<input type="hidden" name="rows" value='<?= json_encode($rows) ?>'>
|
<script>
|
||||||
</form>
|
document.getElementById('redirectForm').submit();
|
||||||
<script>
|
</script>
|
||||||
document.getElementById('redirectForm').submit();
|
|
||||||
</script>
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
?>
|
||||||
+207
-128
@@ -21,6 +21,11 @@ if (!$template) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verifica i mapping
|
||||||
|
$stmt = $pdo->prepare("SELECT id FROM template_mapping WHERE template_id = ?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
$hasMappings = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
// Debug del template
|
// Debug del template
|
||||||
error_log("Loaded template: " . print_r($template, true));
|
error_log("Loaded template: " . print_r($template, true));
|
||||||
?>
|
?>
|
||||||
@@ -33,6 +38,7 @@ error_log("Loaded template: " . print_r($template, true));
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
||||||
<?php include('cssinclude.php'); ?>
|
<?php include('cssinclude.php'); ?>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
.table-container {
|
.table-container {
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
@@ -140,43 +146,55 @@ error_log("Loaded template: " . print_r($template, true));
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<!-- Form per caricare il file -->
|
<?php if (!$hasMappings): ?>
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
Nessun mapping trovato per questo template. Configura i mapping prima di procedere.
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
<form id="uploadForm" enctype="multipart/form-data" class="mb-4">
|
<form id="uploadForm" enctype="multipart/form-data" class="mb-4">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="excel_file" class="form-label">Upload XLS File</label>
|
<label for="excel_file" class="form-label">Upload XLS File</label>
|
||||||
<input type="file" class="form-control" id="excel_file" name="excel_file" accept=".xls,.xlsx" required>
|
<input type="file" class="form-control" id="excel_file" name="excel_file" accept=".xls,.xlsx" required>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Upload</button>
|
<button type="submit" class="btn btn-primary" <?= !$hasMappings ? 'disabled' : '' ?>>Upload</button>
|
||||||
<div class="loader" id="loader"></div>
|
<div class="loader" id="loader"></div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Contenitore per messaggi di errore -->
|
|
||||||
<div id="errorContainer" class="alert alert-danger mt-3" style="display: none;"></div>
|
<div id="errorContainer" class="alert alert-danger mt-3" style="display: none;"></div>
|
||||||
|
|
||||||
<!-- Contenitore per la tabella -->
|
|
||||||
<div id="tableContainer"></div>
|
<div id="tableContainer"></div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="routineConfirmModal" tabindex="-1" aria-labelledby="routineConfirmModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="routineConfirmModalLabel">Conferma Applicazione Routine</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p><strong>Routine:</strong> <span id="routineName"></span></p>
|
||||||
|
<p><strong>Descrizione:</strong> <span id="routineDescription"></span></p>
|
||||||
|
<p>Vuoi applicare questa routine al file caricato?</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" id="cancelRoutineBtn">Annulla</button>
|
||||||
|
<button type="button" class="btn btn-primary" id="confirmRoutineBtn">Applica</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--end page wrapper -->
|
|
||||||
<div class="overlay toggle-icon"></div>
|
<div class="overlay toggle-icon"></div>
|
||||||
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
||||||
<?php include('include/footer.php'); ?>
|
<?php include('include/footer.php'); ?>
|
||||||
</div>
|
</div>
|
||||||
<!--end wrapper-->
|
|
||||||
|
|
||||||
<!-- search modal -->
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
|
||||||
<?php //include('include/searchmodal.php');
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
|
||||||
?>
|
|
||||||
<!-- end search modal -->
|
|
||||||
|
|
||||||
<!--start switcher-->
|
|
||||||
<?php //include('include/themeswitcher.php');
|
|
||||||
?>
|
|
||||||
<!--end switcher-->
|
|
||||||
<?php include('jsinclude.php'); ?>
|
<?php include('jsinclude.php'); ?>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
@@ -184,6 +202,12 @@ error_log("Loaded template: " . print_r($template, true));
|
|||||||
const loader = document.getElementById('loader');
|
const loader = document.getElementById('loader');
|
||||||
const errorContainer = document.getElementById('errorContainer');
|
const errorContainer = document.getElementById('errorContainer');
|
||||||
const tableContainer = document.getElementById('tableContainer');
|
const tableContainer = document.getElementById('tableContainer');
|
||||||
|
const routineModal = new bootstrap.Modal(document.getElementById('routineConfirmModal'));
|
||||||
|
const confirmRoutineBtn = document.getElementById('confirmRoutineBtn');
|
||||||
|
const cancelRoutineBtn = document.getElementById('cancelRoutineBtn');
|
||||||
|
let routineData = null;
|
||||||
|
let excelData = null;
|
||||||
|
let responseData = null;
|
||||||
|
|
||||||
form.addEventListener('submit', function(e) {
|
form.addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -202,133 +226,188 @@ error_log("Loaded template: " . print_r($template, true));
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => {
|
||||||
|
console.log('Stato risposta:', response.status);
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
console.log('Risposta JSON:', data);
|
||||||
loader.style.display = 'none';
|
loader.style.display = 'none';
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
errorContainer.textContent = data.error;
|
errorContainer.textContent = data.error;
|
||||||
errorContainer.style.display = 'block';
|
errorContainer.style.display = 'block';
|
||||||
|
} else if (data.apply_routine) {
|
||||||
|
console.log('Routine rilevata:', data.routine_data);
|
||||||
|
routineData = data.routine_data;
|
||||||
|
excelData = data.excel_data;
|
||||||
|
responseData = data;
|
||||||
|
document.getElementById('routineName').textContent = routineData.name || 'Sconosciuta';
|
||||||
|
document.getElementById('routineDescription').textContent = routineData.instruction || 'Nessuna descrizione';
|
||||||
|
routineModal.show();
|
||||||
} else {
|
} else {
|
||||||
let html = `
|
console.log('Nessuna routine, procedo con tabella');
|
||||||
<form id="selectRowsForm" action="import_insert.php" method="POST">
|
showTable(data);
|
||||||
<input type="hidden" name="template_id" value="${data.template_id}">
|
|
||||||
<input type="hidden" name="columns" value='${JSON.stringify(data.columns)}'>
|
|
||||||
<input type="hidden" name="rows" value='${JSON.stringify(data.rows)}'>
|
|
||||||
<input type="hidden" name="filename" value="${data.filename}">
|
|
||||||
<div class="search-container">
|
|
||||||
<input type="text" id="searchInput" class="form-control" placeholder="Cerca nelle righe...">
|
|
||||||
</div>
|
|
||||||
<div class="table-container">
|
|
||||||
<table class="table table-striped table-bordered">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th><input type="checkbox" id="selectAll"> Seleziona</th>
|
|
||||||
${data.columns.map(col => `<th>${col || 'Colonna senza nome'}<div class="resize-handle"></div></th>`).join('')}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
${data.rows.map((row, index) => `
|
|
||||||
<tr>
|
|
||||||
<td><input type="checkbox" class="row-checkbox" name="selected_rows[]" value="${index}"></td>
|
|
||||||
${row.map(cell => `<td>${cell}</td>`).join('')}
|
|
||||||
</tr>
|
|
||||||
`).join('')}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-primary mt-3" id="proceedButton" disabled>Prosegui</button>
|
|
||||||
</form>
|
|
||||||
`;
|
|
||||||
tableContainer.innerHTML = html;
|
|
||||||
|
|
||||||
// Inizializza le variabili dopo aver inserito la tabella
|
|
||||||
const proceedButton = document.getElementById('proceedButton');
|
|
||||||
const selectAllCheckbox = document.getElementById('selectAll');
|
|
||||||
const checkboxes = document.querySelectorAll('.row-checkbox');
|
|
||||||
|
|
||||||
// Funzione per aggiornare lo stato del pulsante Prosegui
|
|
||||||
function updateProceedButton() {
|
|
||||||
proceedButton.disabled = !Array.from(checkboxes).some(cb => cb.checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event listener per il checkbox "Seleziona tutto"
|
|
||||||
selectAllCheckbox.addEventListener('change', function() {
|
|
||||||
checkboxes.forEach(checkbox => {
|
|
||||||
checkbox.checked = this.checked;
|
|
||||||
});
|
|
||||||
updateProceedButton();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Event listener per i checkbox delle righe
|
|
||||||
checkboxes.forEach(checkbox => {
|
|
||||||
checkbox.addEventListener('change', function() {
|
|
||||||
console.log('Checkbox changed, checked: ', this.checked); // Debug
|
|
||||||
// Aggiorna lo stato del checkbox "Seleziona tutto"
|
|
||||||
selectAllCheckbox.checked = Array.from(checkboxes).every(cb => cb.checked);
|
|
||||||
updateProceedButton();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Aggiungi logica per il ridimensionamento delle colonne
|
|
||||||
const thElements = document.querySelectorAll('.table th');
|
|
||||||
thElements.forEach((th, index) => {
|
|
||||||
if (index === 0) return;
|
|
||||||
const resizeHandle = th.querySelector('.resize-handle');
|
|
||||||
if (resizeHandle) {
|
|
||||||
resizeHandle.addEventListener('mousedown', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
const startX = e.clientX;
|
|
||||||
const startWidth = th.offsetWidth;
|
|
||||||
|
|
||||||
const onMouseMove = (e) => {
|
|
||||||
const newWidth = Math.max(50, startWidth + (e.clientX - startX));
|
|
||||||
th.style.width = `${newWidth}px`;
|
|
||||||
th.style.minWidth = `${newWidth}px`;
|
|
||||||
th.style.maxWidth = `${newWidth}px`;
|
|
||||||
|
|
||||||
const cells = document.querySelectorAll(`.table td:nth-child(${index + 1})`);
|
|
||||||
cells.forEach(cell => {
|
|
||||||
cell.style.width = `${newWidth}px`;
|
|
||||||
cell.style.minWidth = `${newWidth}px`;
|
|
||||||
cell.style.maxWidth = `${newWidth}px`;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onMouseUp = () => {
|
|
||||||
document.removeEventListener('mousemove', onMouseMove);
|
|
||||||
document.removeEventListener('mouseup', onMouseUp);
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', onMouseMove);
|
|
||||||
document.addEventListener('mouseup', onMouseUp);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Aggiungi event listener per la ricerca
|
|
||||||
const searchInput = document.getElementById('searchInput');
|
|
||||||
const rows = document.querySelectorAll('.table tbody tr');
|
|
||||||
|
|
||||||
searchInput.addEventListener('input', function() {
|
|
||||||
const searchTerm = this.value.toLowerCase();
|
|
||||||
rows.forEach(row => {
|
|
||||||
const text = Array.from(row.cells).slice(1).map(cell => cell.textContent.toLowerCase()).join(' ');
|
|
||||||
row.style.display = text.includes(searchTerm) ? '' : 'none';
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Abilita il pulsante se ci sono checkbox selezionate all'inizio
|
|
||||||
updateProceedButton();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
console.log('Errore fetch:', error);
|
||||||
loader.style.display = 'none';
|
loader.style.display = 'none';
|
||||||
errorContainer.textContent = 'Errore durante il caricamento del file: ' + error.message;
|
errorContainer.textContent = 'Errore durante il caricamento del file: ' + error.message;
|
||||||
errorContainer.style.display = 'block';
|
errorContainer.style.display = 'block';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
confirmRoutineBtn.addEventListener('click', function() {
|
||||||
|
console.log('Conferma routine:', routineData);
|
||||||
|
routineModal.hide();
|
||||||
|
|
||||||
|
fetch('apply_routine.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
template_id: <?= $id ?>,
|
||||||
|
filename: routineData.filename,
|
||||||
|
headerrow: routineData.headerrow,
|
||||||
|
excel_data: excelData,
|
||||||
|
routine_data: routineData
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
console.log('Stato apply_routine:', response.status);
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log('Risposta apply_routine:', data);
|
||||||
|
if (data.error) {
|
||||||
|
errorContainer.textContent = data.error;
|
||||||
|
errorContainer.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
showTable(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log('Errore apply_routine:', error);
|
||||||
|
errorContainer.textContent = 'Errore durante l\'applicazione della routine: ' + error.message;
|
||||||
|
errorContainer.style.display = 'block';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelRoutineBtn.addEventListener('click', function() {
|
||||||
|
console.log('Routine annullata, procedo con tabella');
|
||||||
|
routineModal.hide();
|
||||||
|
showTable(responseData);
|
||||||
|
});
|
||||||
|
|
||||||
|
function showTable(data) {
|
||||||
|
console.log('Mostro tabella con dati:', data);
|
||||||
|
let html = `
|
||||||
|
<form id="selectRowsForm" action="import_insert.php" method="POST">
|
||||||
|
<input type="hidden" name="template_id" value="${data.template_id}">
|
||||||
|
<input type="hidden" name="columns" value='${JSON.stringify(data.columns)}'>
|
||||||
|
<input type="hidden" name="rows" value='${JSON.stringify(data.rows)}'>
|
||||||
|
<input type="hidden" name="excelrows" value='${JSON.stringify(data.excel_data.map(row => row.excelrow))}'>
|
||||||
|
<input type="hidden" name="filename" value="${data.filename}">
|
||||||
|
<div class="search-container">
|
||||||
|
<input type="text" id="searchInput" class="form-control" placeholder="Cerca nelle righe...">
|
||||||
|
</div>
|
||||||
|
<div class="table-container">
|
||||||
|
<table class="table table-striped table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input type="checkbox" id="selectAll"> Seleziona</th>
|
||||||
|
${data.columns.map(col => `<th>${col || 'Colonna senza nome'}<div class="resize-handle"></div></th>`).join('')}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${data.excel_data.map((row, index) => `
|
||||||
|
<tr>
|
||||||
|
<td><input type="checkbox" class="row-checkbox" name="selected_rows[]" value="${index}" data-excelrow="${row.excelrow}"></td>
|
||||||
|
${row.data.map(cell => `<td>${cell}</td>`).join('')}
|
||||||
|
</tr>
|
||||||
|
`).join('')}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary mt-3" id="proceedButton" disabled>Prosegui</button>
|
||||||
|
</form>
|
||||||
|
`;
|
||||||
|
tableContainer.innerHTML = html;
|
||||||
|
|
||||||
|
const proceedButton = document.getElementById('proceedButton');
|
||||||
|
const selectAllCheckbox = document.getElementById('selectAll');
|
||||||
|
const checkboxes = document.querySelectorAll('.row-checkbox');
|
||||||
|
|
||||||
|
function updateProceedButton() {
|
||||||
|
proceedButton.disabled = !Array.from(checkboxes).some(cb => cb.checked);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectAllCheckbox.addEventListener('change', function() {
|
||||||
|
checkboxes.forEach(checkbox => {
|
||||||
|
checkbox.checked = this.checked;
|
||||||
|
});
|
||||||
|
updateProceedButton();
|
||||||
|
});
|
||||||
|
|
||||||
|
checkboxes.forEach(checkbox => {
|
||||||
|
checkbox.addEventListener('change', function() {
|
||||||
|
console.log('Checkbox changed, checked:', this.checked, 'excelrow:', this.dataset.excelrow);
|
||||||
|
selectAllCheckbox.checked = Array.from(checkboxes).every(cb => cb.checked);
|
||||||
|
updateProceedButton();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const thElements = document.querySelectorAll('.table th');
|
||||||
|
thElements.forEach((th, index) => {
|
||||||
|
if (index === 0) return;
|
||||||
|
const resizeHandle = th.querySelector('.resize-handle');
|
||||||
|
if (resizeHandle) {
|
||||||
|
resizeHandle.addEventListener('mousedown', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const startX = e.clientX;
|
||||||
|
const startWidth = th.offsetWidth;
|
||||||
|
|
||||||
|
const onMouseMove = (e) => {
|
||||||
|
const newWidth = Math.max(50, startWidth + (e.clientX - startX));
|
||||||
|
th.style.width = `${newWidth}px`;
|
||||||
|
th.style.minWidth = `${newWidth}px`;
|
||||||
|
th.style.maxWidth = `${newWidth}px`;
|
||||||
|
|
||||||
|
const cells = document.querySelectorAll(`.table td:nth-child(${index + 1})`);
|
||||||
|
cells.forEach(cell => {
|
||||||
|
cell.style.width = `${newWidth}px`;
|
||||||
|
cell.style.minWidth = `${newWidth}px`;
|
||||||
|
cell.style.maxWidth = `${newWidth}px`;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMouseUp = () => {
|
||||||
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
|
document.removeEventListener('mouseup', onMouseUp);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('mousemove', onMouseMove);
|
||||||
|
document.addEventListener('mouseup', onMouseUp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const searchInput = document.getElementById('searchInput');
|
||||||
|
const rows = document.querySelectorAll('.table tbody tr');
|
||||||
|
|
||||||
|
searchInput.addEventListener('input', function() {
|
||||||
|
const searchTerm = this.value.toLowerCase();
|
||||||
|
rows.forEach(row => {
|
||||||
|
const text = Array.from(row.cells).slice(1).map(cell => cell.textContent.toLowerCase()).join(' ');
|
||||||
|
row.style.display = text.includes(searchTerm) ? '' : 'none';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
updateProceedButton();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
BIN
Binary file not shown.
+46
-18
@@ -185,13 +185,21 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files) {
|
loader.style.display = "flex";
|
||||||
|
console.log(`Inizio upload di ${files.length} file`);
|
||||||
|
|
||||||
|
let successCount = 0;
|
||||||
|
let errorMessages = [];
|
||||||
|
let uploadPromises = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
if (!file.type.startsWith("image/")) {
|
if (!file.type.startsWith("image/")) {
|
||||||
alert("Per favore, carica solo immagini!");
|
alert(`File ${file.name} non è un'immagine, saltato!`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.style.display = "flex";
|
console.log(`Preparazione upload file ${i + 1}: ${file.name}`);
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("photo", file);
|
formData.append("photo", file);
|
||||||
@@ -201,23 +209,43 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
formData.append("iddatadb", iddatadb);
|
formData.append("iddatadb", iddatadb);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const uploadPromise = fetch("upload_photo.php", {
|
||||||
const response = await fetch("upload_photo.php", {
|
method: "POST",
|
||||||
method: "POST",
|
body: formData,
|
||||||
body: formData,
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((result) => {
|
||||||
|
if (result.success) {
|
||||||
|
successCount++;
|
||||||
|
console.log(`Successo per ${file.name}`);
|
||||||
|
} else {
|
||||||
|
errorMessages.push(
|
||||||
|
`Errore per ${file.name}: ${result.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
errorMessages.push(
|
||||||
|
`Errore per ${file.name}: ${error.message}`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
const result = await response.json();
|
|
||||||
if (result.success) {
|
uploadPromises.push(uploadPromise);
|
||||||
loadPopupContent(iddatadb, idquotations);
|
|
||||||
} else {
|
|
||||||
alert("Errore durante il caricamento: " + result.message);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
alert("Errore durante il caricamento: " + error.message);
|
|
||||||
} finally {
|
|
||||||
loader.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all(uploadPromises);
|
||||||
|
|
||||||
|
loader.style.display = "none";
|
||||||
|
console.log(
|
||||||
|
`Fine upload: ${successCount} riusciti, ${errorMessages.length} errori`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (errorMessages.length > 0) {
|
||||||
|
alert("Errori durante l'upload:\n" + errorMessages.join("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ricarica sempre alla fine per aggiornare la lista, anche se parziale successo
|
||||||
|
loadPopupContent(iddatadb, idquotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachPhotoEventListeners(iddatadb, idquotations) {
|
function attachPhotoEventListeners(iddatadb, idquotations) {
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ try {
|
|||||||
$idschema = intval($_POST['idschema'] ?? 0); // Nuovo campo
|
$idschema = intval($_POST['idschema'] ?? 0); // Nuovo campo
|
||||||
$schemaname = trim($_POST['schemaname'] ?? ''); // Corretto da schemamaname
|
$schemaname = trim($_POST['schemaname'] ?? ''); // Corretto da schemamaname
|
||||||
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null; // Aggiunto idroutine
|
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null; // Aggiunto idroutine
|
||||||
|
$button_size = trim($_POST['button_size'] ?? 'medium'); // Nuovo campo
|
||||||
|
$button_bg_color = trim($_POST['button_bg_color'] ?? '#007bff'); // Nuovo campo
|
||||||
|
$button_text_color = trim($_POST['button_text_color'] ?? '#ffffff'); // Nuovo campo
|
||||||
|
$button_label = trim($_POST['button_label'] ?? 'Click Me'); // Nuovo campo
|
||||||
|
|
||||||
// Controllo sui campi obbligatori
|
// Controllo sui campi obbligatori
|
||||||
if (empty($id) || empty($name) || empty($header_row) || empty($start_column) || empty($target_table) || $idschema <= 0) {
|
if (empty($id) || empty($name) || empty($header_row) || empty($start_column) || empty($target_table) || $idschema <= 0) {
|
||||||
@@ -36,10 +40,12 @@ try {
|
|||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
// Aggiorna il database, includendo idschema, schemaname e idroutine
|
// Aggiorna il database, includendo i nuovi campi
|
||||||
$stmt = $pdo->prepare("UPDATE excel_templates
|
$stmt = $pdo->prepare("UPDATE excel_templates
|
||||||
SET name = ?, header_row = ?, start_column = ?, description = ?, target_table = ?,
|
SET name = ?, header_row = ?, start_column = ?, description = ?, target_table = ?,
|
||||||
idclient = ?, clientname = ?, schemaname = ?, idschema = ?, idroutine = ?, updated_at = NOW()
|
idclient = ?, clientname = ?, schemaname = ?, idschema = ?, idroutine = ?,
|
||||||
|
button_size = ?, button_bg_color = ?, button_text_color = ?, button_label = ?,
|
||||||
|
updated_at = NOW()
|
||||||
WHERE id = ?");
|
WHERE id = ?");
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$name,
|
$name,
|
||||||
@@ -52,6 +58,10 @@ try {
|
|||||||
$schemaname,
|
$schemaname,
|
||||||
$idschema,
|
$idschema,
|
||||||
$idroutine,
|
$idroutine,
|
||||||
|
$button_size,
|
||||||
|
$button_bg_color,
|
||||||
|
$button_text_color,
|
||||||
|
$button_label,
|
||||||
$id
|
$id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
// Sopprime eventuali output di errori (li logghiamo invece di mostrarli)
|
// Sopprime eventuali output di errori (li logghiamo invece di mostrarli)
|
||||||
ob_start();
|
ob_start();
|
||||||
ini_set('display_errors', 0); // Disattiva l'output degli errori a schermo
|
ini_set('display_errors', 0);
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Inizia la sessione
|
// Inizia la sessione
|
||||||
@@ -9,9 +9,9 @@ session_start();
|
|||||||
|
|
||||||
// Includi PHPSpreadsheet e la classe DBHandler
|
// Includi PHPSpreadsheet e la classe DBHandler
|
||||||
require_once '../../vendor/autoload.php';
|
require_once '../../vendor/autoload.php';
|
||||||
require_once __DIR__ . '/class/db-functions.php'; // Assumo che DBHandlerSelect sia qui
|
require_once __DIR__ . '/class/db-functions.php';
|
||||||
|
|
||||||
$response = ['error' => '', 'rows' => [], 'columns' => [], 'template_id' => 0, 'filename' => ''];
|
$response = ['error' => '', 'rows' => [], 'columns' => [], 'template_id' => 0, 'filename' => '', 'apply_routine' => false];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['excel_file'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['excel_file'])) {
|
||||||
@@ -29,7 +29,7 @@ try {
|
|||||||
if ($fileError === UPLOAD_ERR_OK) {
|
if ($fileError === UPLOAD_ERR_OK) {
|
||||||
// Recupera l'ID dell'utente loggato
|
// Recupera l'ID dell'utente loggato
|
||||||
if (!isset($iduserlogin)) {
|
if (!isset($iduserlogin)) {
|
||||||
$iduserlogin = 1; // Valore di default
|
$iduserlogin = 1;
|
||||||
error_log("Warning: iduserlogin non definito, usando 1 come default");
|
error_log("Warning: iduserlogin non definito, usando 1 come default");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ try {
|
|||||||
$worksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
$highestRow = $worksheet->getHighestRow();
|
$highestRow = $worksheet->getHighestRow();
|
||||||
$highestColumn = $worksheet->getHighestColumn();
|
$highestColumn = $worksheet->getHighestColumn();
|
||||||
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn); // Corretto
|
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
|
||||||
|
|
||||||
$startRow = max(1, $header_row);
|
$startRow = max(1, $header_row);
|
||||||
$startColumn = max(1, $start_column);
|
$startColumn = max(1, $start_column);
|
||||||
@@ -93,7 +93,7 @@ try {
|
|||||||
$headerRowData[] = htmlspecialchars($cellValue ?: '');
|
$headerRowData[] = htmlspecialchars($cellValue ?: '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estrai i dati a partire dalla riga successiva
|
// Estrai i dati a partire dalla riga successiva, includendo excelrow
|
||||||
for ($row = $startRow + 1; $row <= $highestRow; $row++) {
|
for ($row = $startRow + 1; $row <= $highestRow; $row++) {
|
||||||
$rowData = [];
|
$rowData = [];
|
||||||
for ($col = $startColumn; $col <= $highestColumnIndex; $col++) {
|
for ($col = $startColumn; $col <= $highestColumnIndex; $col++) {
|
||||||
@@ -103,18 +103,46 @@ try {
|
|||||||
$rowData[] = htmlspecialchars($cellValue ?: '');
|
$rowData[] = htmlspecialchars($cellValue ?: '');
|
||||||
}
|
}
|
||||||
if (!empty(array_filter($rowData))) {
|
if (!empty(array_filter($rowData))) {
|
||||||
$excelData[] = $rowData;
|
$excelData[] = ['data' => $rowData, 'excelrow' => $row];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recupera routine dal template
|
||||||
|
$stmt = $pdo->prepare("SELECT idroutine FROM excel_templates WHERE id = ?");
|
||||||
|
$stmt->execute([$template_id]);
|
||||||
|
$template = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($template && $template['idroutine']) {
|
||||||
|
$stmtRoutine = $pdo->prepare("SELECT idroutine, name, filename, headerrow, instruction FROM routine WHERE idroutine = ?");
|
||||||
|
$stmtRoutine->execute([$template['idroutine']]);
|
||||||
|
$routineData = $stmtRoutine->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($routineData) {
|
||||||
|
$response['apply_routine'] = true;
|
||||||
|
$response['routine_data'] = [
|
||||||
|
'name' => $routineData['name'] ?? 'Routine Sconosciuta',
|
||||||
|
'instruction' => $routineData['instruction'] ?? 'Nessuna descrizione disponibile',
|
||||||
|
'filename' => $routineData['filename'] ?? '',
|
||||||
|
'headerrow' => $routineData['headerrow'] ?? $header_row
|
||||||
|
];
|
||||||
|
error_log("Routine rilevata per template {$template_id}: " . print_r($routineData, true));
|
||||||
|
} else {
|
||||||
|
error_log("Errore: Nessuna routine trovata per idroutine {$template['idroutine']}");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log("Nessuna routine associata al template {$template_id}");
|
||||||
|
}
|
||||||
|
|
||||||
// Salva i dati in sessione
|
// Salva i dati in sessione
|
||||||
$_SESSION['excel_data'] = $excelData;
|
$_SESSION['excel_data'] = $excelData;
|
||||||
$_SESSION['template_id'] = $template_id;
|
$_SESSION['template_id'] = $template_id;
|
||||||
$_SESSION['headers'] = $headerRowData;
|
$_SESSION['headers'] = $headerRowData;
|
||||||
$_SESSION['mappings'] = $mappings; // Salva i mapping per l'importazione
|
$_SESSION['mappings'] = $mappings;
|
||||||
|
|
||||||
$response['rows'] = $excelData;
|
// Includi excel_data nella risposta JSON in ogni caso
|
||||||
$response['columns'] = $headerRowData; // Usa gli header reali
|
$response['excel_data'] = $excelData;
|
||||||
|
$response['rows'] = array_column($excelData, 'data');
|
||||||
|
$response['columns'] = $headerRowData;
|
||||||
$response['template_id'] = $template_id;
|
$response['template_id'] = $template_id;
|
||||||
$response['filename'] = $newFilename;
|
$response['filename'] = $newFilename;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('log_errors', 1);
|
||||||
|
ini_set('error_log', __DIR__ . '/routine_debug.log');
|
||||||
|
|
||||||
|
function applyRoutine(&$excelData, $routineData)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Log iniziale
|
||||||
|
error_log("Inizio esecuzione routine Moncler: " . date('Y-m-d H:i:s'));
|
||||||
|
error_log("Dati routine: " . print_r($routineData, true));
|
||||||
|
error_log("Dati excel_data: " . print_r($excelData, true));
|
||||||
|
|
||||||
|
// Verifica se excelData è vuoto
|
||||||
|
if (empty($excelData)) {
|
||||||
|
throw new Exception("excelData è vuoto o non valido.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Estrai informazioni dalla routine con valori predefiniti
|
||||||
|
$action1 = trim($routineData['action1'] ?? 'K');
|
||||||
|
$action2 = trim($routineData['action2'] ?? 'STYLE CODE + STYLE DESCRIPTION');
|
||||||
|
$action3 = trim($routineData['action3'] ?? 'STYLE CODE');
|
||||||
|
$action4 = trim($routineData['action4'] ?? 'STYLE DESCRIPTION');
|
||||||
|
$headers = $routineData['xls_headers'] ?? [];
|
||||||
|
|
||||||
|
if (empty($headers)) {
|
||||||
|
throw new Exception("Nessun header trovato per la routine Moncler.");
|
||||||
|
}
|
||||||
|
error_log("Header ricevuti: " . print_r($headers, true));
|
||||||
|
|
||||||
|
// Normalizza gli header (solo trim)
|
||||||
|
$normalized_headers = array_map('trim', $headers);
|
||||||
|
error_log("Header normalizzati: " . print_r($normalized_headers, true));
|
||||||
|
error_log("Action values - action1: '$action1', action2: '$action2', action3: '$action3', action4: '$action4'");
|
||||||
|
|
||||||
|
// Trova gli indici delle colonne
|
||||||
|
$action1_index = array_search($action1, $normalized_headers);
|
||||||
|
$action2_index = array_search($action2, $normalized_headers);
|
||||||
|
$action3_index = array_search($action3, $normalized_headers);
|
||||||
|
$action4_index = array_search($action4, $normalized_headers);
|
||||||
|
|
||||||
|
if ($action1_index === false || $action2_index === false || $action3_index === false || $action4_index === false) {
|
||||||
|
throw new Exception("Colonne non trovate - action1: '$action1' (index: " . var_export($action1_index, true) . "), action2: '$action2' (index: " . var_export($action2_index, true) . "), action3: '$action3' (index: " . var_export($action3_index, true) . "), action4: '$action4' (index: " . var_export($action4_index, true) . ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log("Indici colonne - action1: $action1_index, action2: $action2_index, action3: $action3_index, action4: $action4_index");
|
||||||
|
|
||||||
|
// Raggruppa le righe per il valore in action1 (colonna K)
|
||||||
|
$grouped_data = [];
|
||||||
|
foreach ($excelData as $row) {
|
||||||
|
if (!isset($row['data']) || !is_array($row['data'])) {
|
||||||
|
error_log("Riga non valida, manca 'data' per excelrow {$row['excelrow']}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$key = $row['data'][$action1_index] ?? '';
|
||||||
|
$key = empty($key) ? '_empty_' : $key;
|
||||||
|
if (!isset($grouped_data[$key])) {
|
||||||
|
$grouped_data[$key] = [
|
||||||
|
'data' => $row['data'],
|
||||||
|
'excelrow' => [$row['excelrow']],
|
||||||
|
'style_codes' => [],
|
||||||
|
'style_descriptions' => []
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$grouped_data[$key]['excelrow'][] = $row['excelrow'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Separa il valore in action2 (STYLE CODE + STYLE DESCRIPTION)
|
||||||
|
$action2_value = $row['data'][$action2_index] ?? '';
|
||||||
|
if (!empty($action2_value)) {
|
||||||
|
$parts = explode(' - ', trim($action2_value));
|
||||||
|
$style_code = $parts[0] ?? '';
|
||||||
|
$style_description = $parts[1] ?? '';
|
||||||
|
if (!empty($style_code)) {
|
||||||
|
$grouped_data[$key]['style_codes'][] = $style_code;
|
||||||
|
}
|
||||||
|
if (!empty($style_description)) {
|
||||||
|
$grouped_data[$key]['style_descriptions'][] = $style_description;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log("Valore vuoto in action2 per excelrow {$row['excelrow']}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea il nuovo array excel_data aggregato
|
||||||
|
$new_excel_data = [];
|
||||||
|
foreach ($grouped_data as $key => $group) {
|
||||||
|
$row_data = $group['data'];
|
||||||
|
// Aggiorna action3 (STYLE CODE) e action4 (STYLE DESCRIPTION) con valori aggregati
|
||||||
|
$row_data[$action3_index] = implode(' - ', array_unique($group['style_codes']));
|
||||||
|
$row_data[$action4_index] = implode(' - ', array_unique($group['style_descriptions']));
|
||||||
|
// Concatena gli excelrow con '+' per le righe aggregate
|
||||||
|
$excelrow_value = count($group['excelrow']) > 1 ? implode('+', $group['excelrow']) : $group['excelrow'][0];
|
||||||
|
$new_excel_data[] = [
|
||||||
|
'data' => $row_data,
|
||||||
|
'excelrow' => $excelrow_value
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modifica excelData in-place
|
||||||
|
$excelData = $new_excel_data;
|
||||||
|
|
||||||
|
error_log("Routine Moncler completata - Righe aggregate: " . count($new_excel_data));
|
||||||
|
error_log("Excelrow aggregati: " . print_r(array_column($new_excel_data, 'excelrow'), true));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log("Eccezione nella routine Moncler: " . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
require_once "class/VisualLimsApiClient.class.php";
|
||||||
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
|
// 🔹 Configura directory log (creala se non esiste)
|
||||||
|
$logDir = __DIR__ . '/logs/api/';
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Base URL API
|
||||||
|
$apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/';
|
||||||
|
|
||||||
|
// 🔹 Hardcoded commessaId
|
||||||
|
$commessaId = 533357;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 🔹 Initialize API client
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// 🔹 STEP 1: POST InviaCommessa
|
||||||
|
$logContentStep1 = "curl --location --request POST '{$apiBaseUrl}CommessaWeb({$commessaId})/InviaCommessa' \\\n" .
|
||||||
|
"--header 'Content-Type: application/json' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••' \\\n" .
|
||||||
|
"--data '{}'\n\n";
|
||||||
|
|
||||||
|
$sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []);
|
||||||
|
|
||||||
|
$logContentStep1 .= "RESPONSE:\n" . json_encode($sendResult, JSON_PRETTY_PRINT);
|
||||||
|
$logFileStep1 = $logDir . "commessa_{$commessaId}_send_step1_" . time() . ".txt";
|
||||||
|
file_put_contents($logFileStep1, $logContentStep1);
|
||||||
|
|
||||||
|
// 🔹 STEP 2: GET di controllo post-invio
|
||||||
|
$expand = "CommesseCustomFields(\$expand=CustomField)";
|
||||||
|
$commessaAfterSend = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
||||||
|
|
||||||
|
// Log curl-like per GET di controllo
|
||||||
|
$logContentStep2 = "curl --location --request GET '{$apiBaseUrl}CommessaWeb({$commessaId})?\$expand=CommesseCustomFields(\$expand=CustomField)' \\\n" .
|
||||||
|
"--header 'Authorization: Bearer ••••••'\n\n" .
|
||||||
|
"RESPONSE:\n" . json_encode($commessaAfterSend, JSON_PRETTY_PRINT);
|
||||||
|
$logFileStep2 = $logDir . "commessa_{$commessaId}_get_step2_" . time() . ".txt";
|
||||||
|
file_put_contents($logFileStep2, $logContentStep2);
|
||||||
|
|
||||||
|
// 🔹 Output a schermo
|
||||||
|
echo json_encode([
|
||||||
|
"success" => true,
|
||||||
|
"message" => "Commessa {$commessaId} inviata e verificata",
|
||||||
|
"sendResult" => $sendResult,
|
||||||
|
"commessaAfterSend" => $commessaAfterSend,
|
||||||
|
"logFiles" => [
|
||||||
|
"step1_send" => $logFileStep1,
|
||||||
|
"step2_get" => $logFileStep2
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log("Send/Check Error: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
"success" => false,
|
||||||
|
"message" => "Operation failed: " . $e->getMessage(),
|
||||||
|
"logFiles" => [
|
||||||
|
"step1_send" => $logFileStep1 ?? null,
|
||||||
|
"step2_get" => $logFileStep2 ?? null
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
@@ -90,11 +90,11 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th><?= htmlspecialchars($nametemplate, ENT_QUOTES, 'UTF-8'); ?></th>
|
<th><?= htmlspecialchars($nametemplate, ENT_QUOTES, 'UTF-8'); ?></th>
|
||||||
<th><?= htmlspecialchars($lastmodtemplate, ENT_QUOTES, 'UTF-8'); ?></th>
|
|
||||||
<th><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?></th>
|
<th><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?></th>
|
||||||
<th><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?></th>
|
<th><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?></th>
|
||||||
<th><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></th>
|
<th><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></th>
|
||||||
<th>Client Name</th>
|
<th>Client Name</th>
|
||||||
|
<th>Button Label</th>
|
||||||
<th>Status</th> <!-- Aggiunta colonna Status -->
|
<th>Status</th> <!-- Aggiunta colonna Status -->
|
||||||
<th><?= htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?></th>
|
<th><?= htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -147,13 +147,7 @@
|
|||||||
data: 'name', // Nome del template
|
data: 'name', // Nome del template
|
||||||
title: "Template Name"
|
title: "Template Name"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
data: 'updated_at', // Ultima modifica, formattata come data leggibile
|
|
||||||
title: "Last Modified",
|
|
||||||
render: function(data) {
|
|
||||||
return new Date(data).toLocaleDateString();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
data: 'header_row', // Riga degli header
|
data: 'header_row', // Riga degli header
|
||||||
title: "Header Row"
|
title: "Header Row"
|
||||||
@@ -176,6 +170,11 @@
|
|||||||
return `${clientName} (ID: ${clientId})`;
|
return `${clientName} (ID: ${clientId})`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
data: 'button_label', // Nuova colonna per Button Label
|
||||||
|
title: "Button Label",
|
||||||
|
defaultContent: 'Click Me'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
data: 'status', // Stato con Toggle Switch
|
data: 'status', // Stato con Toggle Switch
|
||||||
title: "Status",
|
title: "Status",
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in New Issue
Block a user