various fixing modal
This commit is contained in:
@@ -16,41 +16,45 @@ if (!$iddatadb || empty($parts)) {
|
||||
}
|
||||
|
||||
$part = $parts[0];
|
||||
$partId = $part['id'] ?? null; // part_id თუ არსებობს
|
||||
$partId = $part['id'] ?? null;
|
||||
$partNumber = $part['part_number'] ?? null;
|
||||
$partDescription = $part['part_description'] ?? '';
|
||||
$mix = $part['mix'] ?? 'N';
|
||||
$idmatrice = $part['idmatrice'] ?? null; // Nuovo campo idmatrice
|
||||
|
||||
if ($partDescription) {
|
||||
try {
|
||||
if ($partId) {
|
||||
// UPDATE თუ უკვე არსებობს part
|
||||
// UPDATE se la parte esiste
|
||||
$stmt = $pdo->prepare("UPDATE identification_parts
|
||||
SET part_number = :part_number,
|
||||
part_description = :part_description,
|
||||
mix = :mix,
|
||||
idmatrice = :idmatrice,
|
||||
updated_at = NOW()
|
||||
WHERE id = :id");
|
||||
$stmt->execute([
|
||||
':id' => $partId,
|
||||
':part_number' => $partNumber,
|
||||
':part_description' => $partDescription,
|
||||
':mix' => $mix
|
||||
':mix' => $mix,
|
||||
':idmatrice' => $idmatrice // Può essere NULL
|
||||
]);
|
||||
echo json_encode(['success' => true, 'part_id' => $partId, 'part_number'=>$partNumber, 'message' => 'Parte aggiornata con successo']);
|
||||
echo json_encode(['success' => true, 'part_id' => $partId, 'part_number' => $partNumber, 'message' => 'Parte aggiornata con successo']);
|
||||
} else {
|
||||
// INSERT თუ ახალია
|
||||
// INSERT per nuova parte
|
||||
$stmt = $pdo->prepare("INSERT INTO identification_parts
|
||||
(iddatadb, part_number, part_description, mix, created_at, updated_at)
|
||||
VALUES (:iddatadb, :part_number, :part_description, :mix, NOW(), NOW())");
|
||||
(iddatadb, part_number, part_description, mix, idmatrice, created_at, updated_at)
|
||||
VALUES (:iddatadb, :part_number, :part_description, :mix, :idmatrice, NOW(), NOW())");
|
||||
$stmt->execute([
|
||||
':iddatadb' => $iddatadb,
|
||||
':part_number' => $partNumber,
|
||||
':part_description' => $partDescription,
|
||||
':mix' => $mix
|
||||
':mix' => $mix,
|
||||
':idmatrice' => $idmatrice // Può essere NULL
|
||||
]);
|
||||
$newId = $pdo->lastInsertId();
|
||||
echo json_encode(['success' => true, 'part_id' => $newId, 'part_number'=>$partNumber, 'message' => 'Parte salvata con successo']);
|
||||
echo json_encode(['success' => true, 'part_id' => $newId, 'part_number' => $partNumber, 'message' => 'Parte salvata con successo']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
||||
|
||||
Reference in New Issue
Block a user