97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?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()
|
|
]);
|
|
}
|