this commit is uploaded for testing only, no api calls are made
This commit is contained in:
parent
f89dbd0c23
commit
33e3ae059d
@ -120,4 +120,71 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
96
public/userarea/export_to_lims.php
Normal file
96
public/userarea/export_to_lims.php
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
require_once "class/VisualLimsApiClient.class.php";
|
||||||
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $dbHandler->getConnection();
|
||||||
|
|
||||||
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
|
try {
|
||||||
|
$iddatadb = $_POST['iddatadb'] ?? null;
|
||||||
|
if (!$iddatadb) {
|
||||||
|
throw new Exception("Missing iddatadb");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ⚠️ IMPORTANT: Disable API calls, keep only DB real
|
||||||
|
$simulate = true;
|
||||||
|
|
||||||
|
// 🔹 STEP 1: Fetch Cliente ID from your DB
|
||||||
|
// get client id here
|
||||||
|
|
||||||
|
$clienteId = 12345; // Replace with actual client ID fetching logic
|
||||||
|
|
||||||
|
// 🔹 STEP 2: Fetch Parts (Campioni) for this record
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT part_number, part_description, material, color, mix
|
||||||
|
FROM identification_parts
|
||||||
|
WHERE iddatadb = :iddatadb
|
||||||
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// 🔹 STEP 3: Fetch Field Values from import_data_details
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT mapping_id, field_value
|
||||||
|
FROM import_data_details
|
||||||
|
WHERE id = :iddatadb
|
||||||
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$fieldValues = [];
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$fieldValues[] = [
|
||||||
|
"MappingId" => (int) $row['mapping_id'],
|
||||||
|
"FieldValue" => $row['field_value']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($simulate) {
|
||||||
|
// Simulated CommessaWeb
|
||||||
|
$commessaId = 999999;
|
||||||
|
$commessa = [
|
||||||
|
"IdCommessa" => $commessaId,
|
||||||
|
"CodiceCommessa" => "TEST001",
|
||||||
|
"StatoCommessaWeb" => "Nuova",
|
||||||
|
"Cliente" => $clienteId
|
||||||
|
];
|
||||||
|
|
||||||
|
// Use REAL parts fetched from DB
|
||||||
|
$createdParts = [];
|
||||||
|
foreach ($parts as $p) {
|
||||||
|
$createdParts[] = array_merge($p, [
|
||||||
|
"Commessa" => $commessaId,
|
||||||
|
// optional: give each part a fake Campione ID just for simulation
|
||||||
|
"IdCampione" => rand(1000, 9999)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulated CommessaField values
|
||||||
|
$createdFields = [];
|
||||||
|
foreach ($fieldValues as $f) {
|
||||||
|
$createdFields[] = [
|
||||||
|
"Commessa" => $commessaId,
|
||||||
|
"MappingId" => $f["MappingId"],
|
||||||
|
"FieldValue" => $f["FieldValue"],
|
||||||
|
"IdCommessaField" => rand(2000, 9999)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
"success" => true,
|
||||||
|
"commessaId" => $commessaId,
|
||||||
|
"commessa" => $commessa,
|
||||||
|
"parts" => $createdParts, // now comes from DB
|
||||||
|
"fields" => $createdFields, // simulated push
|
||||||
|
"simulation" => $simulate
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode([
|
||||||
|
"success" => false,
|
||||||
|
"message" => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
@ -709,6 +709,32 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<script src="parts.js"></script>
|
<script src="parts.js"></script>
|
||||||
<script src="tracking.js"></script>
|
<script src="tracking.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
$(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("✅ CommessaWeb created. ID: " + response.commessaId);
|
||||||
|
} else {
|
||||||
|
alert("❌ Error: " + response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
alert("❌ AJAX error: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log("Page loaded, initializing event listeners");
|
console.log("Page loaded, initializing event listeners");
|
||||||
|
|
||||||
@ -1068,4 +1094,4 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user