Lims api working version without comment

This commit is contained in:
Lasha Kapanadze 2025-09-22 20:24:53 +04:00
parent 0a6fb98476
commit a36dd02771
2 changed files with 3 additions and 19 deletions

View File

@ -13,8 +13,6 @@ try {
throw new Exception("Missing iddatadb"); throw new Exception("Missing iddatadb");
} }
echo "✅ START Export for iddatadb={$iddatadb}\n";
// 🔹 STEP 1+2: Fetch Cliente ID + Schema ID // 🔹 STEP 1+2: Fetch Cliente ID + Schema ID
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT et.idclient AS clienteId, et.idschema AS schemaId SELECT et.idclient AS clienteId, et.idschema AS schemaId
@ -33,8 +31,6 @@ try {
$clienteId = (int) $result['clienteId']; $clienteId = (int) $result['clienteId'];
$schemaId = (int) $result['schemaId']; $schemaId = (int) $result['schemaId'];
echo "✅ Cliente={$clienteId}, Schema={$schemaId}\n";
// 🔹 STEP 3: Fetch Parts (including idmatrice) // 🔹 STEP 3: Fetch Parts (including idmatrice)
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT part_number, part_description, material, color, mix, idmatrice SELECT part_number, part_description, material, color, mix, idmatrice
@ -44,8 +40,6 @@ try {
$stmt->execute(['iddatadb' => $iddatadb]); $stmt->execute(['iddatadb' => $iddatadb]);
$parts = $stmt->fetchAll(PDO::FETCH_ASSOC); $parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "✅ Parts found: " . count($parts) . "\n";
// 🔹 STEP 4: Fetch Field Values with Labels // 🔹 STEP 4: Fetch Field Values with Labels
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT SELECT
@ -61,8 +55,6 @@ try {
$stmt->execute(['iddatadb' => $iddatadb]); $stmt->execute(['iddatadb' => $iddatadb]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "✅ Field rows found: " . count($rows) . "\n";
$fieldValues = []; $fieldValues = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$fieldValues[] = [ $fieldValues[] = [
@ -81,12 +73,9 @@ try {
"Richiedente" => "Test Web Import", "Richiedente" => "Test Web Import",
"Descrizione" => "TEST CommessaWeb", "Descrizione" => "TEST CommessaWeb",
]; ];
echo "➡️ Creating CommessaWeb...\n";
$commessaWeb = $api->post("CommessaWeb", $commessaWebPayload); $commessaWeb = $api->post("CommessaWeb", $commessaWebPayload);
$commessaId = $commessaWeb["IdCommessa"]; $commessaId = $commessaWeb["IdCommessa"];
echo "✅ CommessaWeb created: ID={$commessaId}\n";
// 🔹 STEP 6: Create Campioni (Samples) for each part // 🔹 STEP 6: Create Campioni (Samples) for each part
$campioni = []; $campioni = [];
@ -105,7 +94,6 @@ try {
"NoteWeb" => $part["part_description"] ?? "" "NoteWeb" => $part["part_description"] ?? ""
]; ];
echo "➡️ Creating Campione {$index} with Matrice={$matriceId}\n";
$campione = $api->post("Campione", $campionePayload); $campione = $api->post("Campione", $campionePayload);
$campione["PartNumber"] = $part["part_number"] ?? ""; $campione["PartNumber"] = $part["part_number"] ?? "";
@ -114,12 +102,10 @@ try {
$campione["Mix"] = $part["mix"] ?? ""; $campione["Mix"] = $part["mix"] ?? "";
$campioni[] = $campione; $campioni[] = $campione;
echo "✅ Campione {$index} created: ID=" . ($campione["IdCampione"] ?? "N/A") . "\n";
} }
// 🔹 STEP 7: Update Custom Fields for CommessaWeb // 🔹 STEP 7: Update Custom Fields for CommessaWeb
if (!empty($fieldValues)) { if (!empty($fieldValues)) {
echo "➡️ Updating CommessaWeb Custom Fields...\n";
$commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=CommesseCustomFields"); $commessaWithFields = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=CommesseCustomFields");
$commessaCustomFields = []; $commessaCustomFields = [];
foreach ($commessaWithFields["CommesseCustomFields"] as $customField) { foreach ($commessaWithFields["CommesseCustomFields"] as $customField) {
@ -137,14 +123,11 @@ try {
if (!empty($commessaCustomFields)) { if (!empty($commessaCustomFields)) {
$updatePayload = ["CommesseCustomFields" => $commessaCustomFields]; $updatePayload = ["CommesseCustomFields" => $commessaCustomFields];
$api->patch("CommessaWeb({$commessaId})", $updatePayload); $api->patch("CommessaWeb({$commessaId})", $updatePayload);
echo "✅ CommessaWeb Custom Fields updated\n";
} }
} }
// 🔹 STEP 9: Send CommessaWeb to laboratory // 🔹 STEP 9: Send CommessaWeb to laboratory
echo "➡️ Sending CommessaWeb...\n";
$sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []); $sendResult = $api->post("CommessaWeb({$commessaId})/InviaCommessa", []);
echo "✅ CommessaWeb sent to Lab\n";
// 🔹 STEP 10: Prepare final response // 🔹 STEP 10: Prepare final response
$finalCommessa = [ $finalCommessa = [
@ -161,7 +144,8 @@ try {
"success" => true, "success" => true,
"commessaWeb" => $finalCommessa, "commessaWeb" => $finalCommessa,
"totalCampioni" => count($campioni), "totalCampioni" => count($campioni),
"totalCustomFields" => count($fieldValues) "totalCustomFields" => count($fieldValues),
"message" => "Export successful"
]); ]);
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -724,7 +724,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
}, },
success: function (response) { success: function (response) {
if (response.success) { if (response.success) {
alert("✅ CommessaWeb created. ID: " + response.webOrder.IdCommessa); alert(response.message);
} else { } else {
alert("❌ Error: " + response.message); alert("❌ Error: " + response.message);
} }