diff --git a/public/userarea/annotationsModal.js b/public/userarea/annotationsModal.js index ad66692..8f4a79f 100644 --- a/public/userarea/annotationsModal.js +++ b/public/userarea/annotationsModal.js @@ -614,17 +614,11 @@ $(document).ready(function () { partsListData.forEach((part) => { const partNumber = part.part_number; const partDescription = part.part_description; + const isMixPart = String(part.mix || "N").toUpperCase() === "Y"; + const partColor = - partColors[partNumber] || - (partDescription.toLowerCase().startsWith("mix") - ? "#0000ff" - : "#ff0000"); - if ( - partNumber && - partDescription && - (showMixParts || - !partDescription.toLowerCase().startsWith("mix")) - ) { + partColors[partNumber] || (isMixPart ? "#0000ff" : "#ff0000"); + if (partNumber && partDescription && (showMixParts || !isMixPart)) { const colorOptions = predefinedColors .map( (color) => @@ -922,11 +916,10 @@ $(document).ready(function () { ) { partsListData = response.parts; response.parts.forEach((part) => { - const defaultColor = part.part_description - .toLowerCase() - .startsWith("mix") - ? "#0000ff" - : "#ff0000"; + const isMixPart = + String(part.mix || "N").toUpperCase() === "Y"; + const defaultColor = isMixPart ? "#0000ff" : "#ff0000"; + partColors[part.part_number] = defaultColor; }); updatePartsList(); @@ -1003,11 +996,10 @@ $(document).ready(function () { (p) => p.part_number == marker.partNumber, ); const partDescription = part ? part.part_description : ""; - if ( - !showMixParts && - partDescription && - partDescription.toLowerCase().startsWith("mix") - ) { + const isMixPart = + part && String(part.mix || "N").toUpperCase() === "Y"; + + if (!showMixParts && isMixPart) { console.log("Ignoro marker per parte Mix:", marker.partNumber); return; } @@ -1115,11 +1107,10 @@ $(document).ready(function () { } const partsList = partsListData - .filter( - (part) => - showMixParts || - !part.part_description.toLowerCase().startsWith("mix"), - ) + .filter((part) => { + const isMixPart = String(part.mix || "N").toUpperCase() === "Y"; + return showMixParts || !isMixPart; + }) .map((part) => `${part.part_number} ${part.part_description}`); const text = partsList.join("\n"); diff --git a/public/userarea/load_parts.php b/public/userarea/load_parts.php index 6fb0076..59bef0b 100644 --- a/public/userarea/load_parts.php +++ b/public/userarea/load_parts.php @@ -33,9 +33,9 @@ try { if ($extraFieldId) { $stmt = $pdo->prepare(" SELECT - p.id, p.iddatadb, p.part_number, p.part_description, p.idmatrice, p.note, p.dateexpiry, - cf.value_id AS extra_value_id, - cf.value_text AS extra_value_text + p.id, p.iddatadb, p.part_number, p.part_description, p.mix, p.idmatrice, p.note, p.dateexpiry, + cf.value_id AS extra_value_id, + cf.value_text AS extra_value_text FROM identification_parts p LEFT JOIN identification_parts_customfields cf ON cf.part_id = p.id AND cf.field_id = :extraFieldId @@ -48,8 +48,8 @@ try { ]); } else { $stmt = $pdo->prepare(" - SELECT id, iddatadb, part_number, part_description, idmatrice, note, dateexpiry, - NULL AS extra_value_id, NULL AS extra_value_text + SELECT id, iddatadb, part_number, part_description, mix, idmatrice, note, dateexpiry, + NULL AS extra_value_id, NULL AS extra_value_text FROM identification_parts WHERE iddatadb = :iddatadb ORDER BY part_number ASC diff --git a/public/userarea/partsTable.js b/public/userarea/partsTable.js index 2ed3109..7f5c6e8 100644 --- a/public/userarea/partsTable.js +++ b/public/userarea/partsTable.js @@ -235,6 +235,17 @@ $(document).ready(function () { $row.data("__pid", id); } + function setRowMix($row, isMix) { + const mixValue = isMix === true || isMix === "Y" ? "Y" : "N"; + $row.attr("data-is-mix", mixValue); + $row.data("is-mix", mixValue); + } + + function getRowMix($row) { + const value = $row.attr("data-is-mix") || $row.data("is-mix"); + return value === "Y" ? "Y" : "N"; + } + // =================== // VOICE RECOGNITION SETUP // =================== @@ -698,7 +709,7 @@ $(document).ready(function () { const $saveLoading = $row.find(".save-loading"); const iddatadb = $("#partsModal").data("iddatadb"); const idquotations = $("#partsModal").data("idquotations"); - const isMix = partDescription.startsWith("Mix") ? "Y" : "N"; + const isMix = getRowMix($row); // EXTRA FIELD (0/1) const extra_field_id = $row.find(".part-extra-field-id").val() || null; @@ -837,11 +848,7 @@ $(document).ready(function () { let $mixRow = $("#partsTableBody tr") .filter(function () { - return $(this) - .find(".part-description") - .val() - .trim() - .startsWith("Mix"); + return getRowMix($(this)) === "Y"; }) .last(); @@ -897,7 +904,7 @@ $(document).ready(function () { function addNewRow(nextPartNumber, isMix = false) { const description = isMix ? "Mix" : ""; const newRow = ` - + @@ -918,6 +925,7 @@ $(document).ready(function () { `; $("#partsTableBody").append(newRow); const $newRow = $("#partsTableBody tr:last"); + setRowMix($newRow, isMix ? "Y" : "N"); const $select = $newRow.find(".part-matrice"); const selectedMacro = $("#macro-matrice-filter").val() || ""; @@ -1394,7 +1402,7 @@ $(document).ready(function () { ? $("
").text(part.note).html() : ""; const newRow = ` - + @@ -1418,7 +1426,7 @@ $(document).ready(function () { const $row = $( `#partsTableBody tr[data-part-id="${part.id}"]`, ); - + setRowMix($row, part.mix === "Y" ? "Y" : "N"); if ( part.extra_value_id !== undefined && part.extra_value_id !== null @@ -1883,7 +1891,7 @@ $(document).ready(function () { id: part.partId, part_number: index + 1, part_description: part.partDescription, - mix: part.partDescription.startsWith("Mix") ? "Y" : "N", + mix: getRowMix($rows.eq(index)), idmatrice: partMatrice[index + 1] || null, note: part.note, dateexpiry: part.dateexpiry, @@ -2238,7 +2246,7 @@ $(document).on("change", ".propagate-date-input", function () { const partId = $row.data("part-id"); const partNumber = $row.find(".part-number").val(); const partDescription = $row.find(".part-description").val().trim(); - const mix = partDescription.startsWith("Mix") ? "Y" : "N"; + const mix = $row.attr("data-is-mix") === "Y" ? "Y" : "N"; const idmatrice = $row.find(".part-matrice").val() || null; const note = $row.data("note") || null; @@ -2349,7 +2357,7 @@ $(document).on("click", ".save-common-note-btn", function () { const partId = $row.data("part-id"); const partNumber = $row.find(".part-number").val(); const partDescription = $row.find(".part-description").val().trim(); - const mix = partDescription.startsWith("Mix") ? "Y" : "N"; + const mix = $row.attr("data-is-mix") === "Y" ? "Y" : "N"; const idmatrice = $row.find(".part-matrice").val() || null; const dateexpiry = $row.find(".part-dateexpiry").val() || null;