fixed saving and modifying parts

This commit is contained in:
Lasha Kapanadze 2025-08-25 19:39:53 +04:00
parent a87423d879
commit 1bda30e957
2 changed files with 8 additions and 7 deletions

View File

@ -179,7 +179,7 @@ $(document).ready(function () {
function addNewRow(nextPartNumber, isMix = false) {
const description = isMix ? "Mix" : "";
const newRow = `
<tr data-part-id="new">
<tr data-part-id="">
<td><input type="number" class="form-control form-control-sm part-number" value="${nextPartNumber || 1}" style="width: 80px;"></td>
<td><input type="text" class="form-control form-control-sm part-description" value="${description}" placeholder="Inserisci descrizione" style="width: 100%;"></td>
<td>
@ -290,13 +290,14 @@ $(document).ready(function () {
contentType: "application/json",
success: function (response) {
if (response.success) {
// თუ ახალია, backend-მა მოგვცა ახალი ID
if (response.part_id) {
$row.data("part-id", response.part_id);
}
$saveLoading.hide();
$saveStatus.show();
updatePartsList();
// თუ ახალია, backend-მა მოგვცა ახალი ID
if (response.part_id) {
$row.attr("data-part-id", response.part_id);
$row.data("part-id", response.part_id);
}
setTimeout(() => $saveStatus.hide(), 2000);
} else {
alert("Errore nel salvataggio: " + response.message);

View File

@ -37,7 +37,7 @@ if ($partDescription) {
':part_description' => $partDescription,
':mix' => $mix
]);
echo json_encode(['success' => true, 'message' => 'Parte aggiornata con successo']);
echo json_encode(['success' => true, 'part_id' => $partId, 'part_number'=>$partNumber, 'message' => 'Parte aggiornata con successo']);
} else {
// INSERT თუ ახალია
$stmt = $pdo->prepare("INSERT INTO identification_parts
@ -50,7 +50,7 @@ if ($partDescription) {
':mix' => $mix
]);
$newId = $pdo->lastInsertId();
echo json_encode(['success' => true, 'message' => 'Parte salvata con successo', 'part_id' => $newId]);
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()]);