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