fixed issue, now works great. // ⚠️ Simulation ON (change it to false to enable real API calls)
$simulate = true;
This commit is contained in:
@@ -13,15 +13,28 @@ try {
|
|||||||
throw new Exception("Missing iddatadb");
|
throw new Exception("Missing iddatadb");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ⚠️ IMPORTANT: Disable API calls, keep only DB real
|
// ⚠️ Simulation ON (change it to false to enable real API calls)
|
||||||
$simulate = true;
|
$simulate = true;
|
||||||
|
|
||||||
// 🔹 STEP 1: Fetch Cliente ID from your DB
|
// 🔹 STEP 1+2: Fetch Cliente ID + Schema ID
|
||||||
// get client id here
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT et.idclient AS clienteId, et.idschema AS schemaId
|
||||||
|
FROM datadb as d
|
||||||
|
INNER JOIN excel_templates as et ON d.templateid = et.id
|
||||||
|
WHERE d.iddatadb = :iddatadb
|
||||||
|
LIMIT 1
|
||||||
|
");
|
||||||
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$clienteId = 12345; // Replace with actual client ID fetching logic
|
if (!$result) {
|
||||||
|
throw new Exception("No Cliente/Schema found for iddatadb {$iddatadb}");
|
||||||
|
}
|
||||||
|
|
||||||
// 🔹 STEP 2: Fetch Parts (Campioni) for this record
|
$clienteId = (int) $result['clienteId'];
|
||||||
|
$schemaId = (int) $result['schemaId'];
|
||||||
|
|
||||||
|
// 🔹 STEP 3: Fetch Parts
|
||||||
$stmt = $pdo->prepare("
|
$stmt = $pdo->prepare("
|
||||||
SELECT part_number, part_description, material, color, mix
|
SELECT part_number, part_description, material, color, mix
|
||||||
FROM identification_parts
|
FROM identification_parts
|
||||||
@@ -30,61 +43,70 @@ try {
|
|||||||
$stmt->execute(['iddatadb' => $iddatadb]);
|
$stmt->execute(['iddatadb' => $iddatadb]);
|
||||||
$parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
// 🔹 STEP 3: Fetch Field Values from import_data_details
|
// 🔹 STEP 4: Fetch Field Values with Labels
|
||||||
$stmt = $pdo->prepare("
|
$stmt = $pdo->prepare("
|
||||||
SELECT mapping_id, field_value
|
SELECT
|
||||||
FROM import_data_details
|
idd.field_value,
|
||||||
WHERE id = :iddatadb
|
m.field_label
|
||||||
|
FROM
|
||||||
|
import_data_details as idd
|
||||||
|
JOIN template_mapping m ON idd.mapping_id = m.id
|
||||||
|
WHERE idd.id = :iddatadb
|
||||||
");
|
");
|
||||||
$stmt->execute(['iddatadb' => $iddatadb]);
|
$stmt->execute([
|
||||||
|
'iddatadb' => $iddatadb
|
||||||
|
]);
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$fieldValues = [];
|
$fieldValues = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$fieldValues[] = [
|
$fieldValues[] = [
|
||||||
"MappingId" => (int) $row['mapping_id'],
|
"FieldLabel" => $row['field_label'],
|
||||||
"FieldValue" => $row['field_value']
|
"FieldValue" => $row['field_value']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔹 Simulation Mode
|
||||||
if ($simulate) {
|
if ($simulate) {
|
||||||
// Simulated CommessaWeb
|
|
||||||
$commessaId = 999999;
|
$commessaId = 999999;
|
||||||
$commessa = [
|
$commessa = [
|
||||||
"IdCommessa" => $commessaId,
|
"IdCommessa" => $commessaId,
|
||||||
"CodiceCommessa" => "TEST001",
|
"CodiceCommessa" => "TEST001",
|
||||||
"StatoCommessaWeb" => "Nuova",
|
"IdCliente" => $clienteId,
|
||||||
"Cliente" => $clienteId
|
"Fields" => $fieldValues
|
||||||
];
|
];
|
||||||
|
} else {
|
||||||
|
// 🔹 REAL API FLOW
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
// Use REAL parts fetched from DB
|
// 1. Create CommessaWeb
|
||||||
$createdParts = [];
|
$commessaPayload = [
|
||||||
foreach ($parts as $p) {
|
"IdCliente" => $clienteId,
|
||||||
$createdParts[] = array_merge($p, [
|
"IdSchemaCustomFields" => $schemaId,
|
||||||
"Commessa" => $commessaId,
|
"Inviato" => 1
|
||||||
// optional: give each part a fake Campione ID just for simulation
|
];
|
||||||
"IdCampione" => rand(1000, 9999)
|
$commessa = $api->post("CommessaWeb", $commessaPayload);
|
||||||
]);
|
$commessaId = $commessa["IdCommessa"];
|
||||||
}
|
|
||||||
|
|
||||||
// Simulated CommessaField values
|
// 2. Push Fields
|
||||||
$createdFields = [];
|
$fields = [];
|
||||||
foreach ($fieldValues as $f) {
|
foreach ($fieldValues as $f) {
|
||||||
$createdFields[] = [
|
$fieldPayload = [
|
||||||
"Commessa" => $commessaId,
|
"Commessa" => $commessaId,
|
||||||
"MappingId" => $f["MappingId"],
|
"FieldLabel" => $f["FieldLabel"],
|
||||||
"FieldValue" => $f["FieldValue"],
|
"FieldValue" => $f["FieldValue"]
|
||||||
"IdCommessaField" => rand(2000, 9999)
|
|
||||||
];
|
];
|
||||||
|
$res = $api->post("CommessaField", $fieldPayload);
|
||||||
|
$fields[] = $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$commessa["Fields"] = $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
"success" => true,
|
"success" => true,
|
||||||
"commessaId" => $commessaId,
|
|
||||||
"commessa" => $commessa,
|
"commessa" => $commessa,
|
||||||
"parts" => $createdParts, // now comes from DB
|
"parts" => $parts,
|
||||||
"fields" => $createdFields, // simulated push
|
|
||||||
"simulation" => $simulate
|
"simulation" => $simulate
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -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.commessaId);
|
alert("✅ CommessaWeb created. ID: " + response.comessa);
|
||||||
} else {
|
} else {
|
||||||
alert("❌ Error: " + response.message);
|
alert("❌ Error: " + response.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user