fixed saving and modifying parts
This commit is contained in:
parent
24cda34681
commit
a87423d879
@ -266,6 +266,9 @@ $(document).ready(function () {
|
|||||||
const iddatadb = $("#partsModal").data("iddatadb");
|
const iddatadb = $("#partsModal").data("iddatadb");
|
||||||
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
||||||
|
|
||||||
|
// არსებული part-id row-დან (თუ უკვე არსებობს)
|
||||||
|
const partId = $row.data("part-id") || null;
|
||||||
|
|
||||||
if (partDescription && iddatadb) {
|
if (partDescription && iddatadb) {
|
||||||
$saveLoading.show();
|
$saveLoading.show();
|
||||||
$saveStatus.hide();
|
$saveStatus.hide();
|
||||||
@ -277,6 +280,7 @@ $(document).ready(function () {
|
|||||||
iddatadb: iddatadb,
|
iddatadb: iddatadb,
|
||||||
parts: [
|
parts: [
|
||||||
{
|
{
|
||||||
|
id: partId, // გავგზავნე part-ის ID (თუ არის)
|
||||||
part_number: partNumber,
|
part_number: partNumber,
|
||||||
part_description: partDescription,
|
part_description: partDescription,
|
||||||
mix: isMix,
|
mix: isMix,
|
||||||
@ -286,6 +290,7 @@ $(document).ready(function () {
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
// თუ ახალია, backend-მა მოგვცა ახალი ID
|
||||||
if (response.part_id) {
|
if (response.part_id) {
|
||||||
$row.data("part-id", response.part_id);
|
$row.data("part-id", response.part_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
include('include/headscript.php');
|
include('include/headscript.php');
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
@ -17,20 +16,42 @@ if (!$iddatadb || empty($parts)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$part = $parts[0];
|
$part = $parts[0];
|
||||||
|
$partId = $part['id'] ?? null; // part_id თუ არსებობს
|
||||||
$partNumber = $part['part_number'] ?? null;
|
$partNumber = $part['part_number'] ?? null;
|
||||||
$partDescription = $part['part_description'] ?? '';
|
$partDescription = $part['part_description'] ?? '';
|
||||||
$mix = $part['mix'] ?? 'N'; // Aggiunto per gestire il campo mix
|
$mix = $part['mix'] ?? 'N';
|
||||||
|
|
||||||
if ($partDescription) {
|
if ($partDescription) {
|
||||||
try {
|
try {
|
||||||
$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())");
|
if ($partId) {
|
||||||
|
// UPDATE თუ უკვე არსებობს part
|
||||||
|
$stmt = $pdo->prepare("UPDATE identification_parts
|
||||||
|
SET part_number = :part_number,
|
||||||
|
part_description = :part_description,
|
||||||
|
mix = :mix,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE id = :id");
|
||||||
|
$stmt->execute([
|
||||||
|
':id' => $partId,
|
||||||
|
':part_number' => $partNumber,
|
||||||
|
':part_description' => $partDescription,
|
||||||
|
':mix' => $mix
|
||||||
|
]);
|
||||||
|
echo json_encode(['success' => true, 'message' => 'Parte aggiornata con successo']);
|
||||||
|
} else {
|
||||||
|
// INSERT თუ ახალია
|
||||||
|
$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())");
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
':iddatadb' => $iddatadb,
|
':iddatadb' => $iddatadb,
|
||||||
':part_number' => $partNumber,
|
':part_number' => $partNumber,
|
||||||
':part_description' => $partDescription,
|
':part_description' => $partDescription,
|
||||||
':mix' => $mix
|
':mix' => $mix
|
||||||
]);
|
]);
|
||||||
echo json_encode(['success' => true, 'message' => 'Parte salvata con successo']);
|
$newId = $pdo->lastInsertId();
|
||||||
|
echo json_encode(['success' => true, 'message' => 'Parte salvata con successo', 'part_id' => $newId]);
|
||||||
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user