fixed importedit

This commit is contained in:
2026-02-02 08:46:47 +01:00
parent 4e4cae1df8
commit f60dc64b2d
+89 -53
View File
@@ -83,7 +83,35 @@ $fixedStmt = $pdo->prepare("
ORDER BY id ORDER BY id
"); ");
$fixedStmt->execute([$template_id]); $fixedStmt->execute([$template_id]);
$fixedFields = $fixedStmt->fetchAll(PDO::FETCH_ASSOC); $fixedFieldsRaw = $fixedStmt->fetchAll(PDO::FETCH_ASSOC);
// Ordine desiderato: Cliente Responsabile prima, poi gli altri, ConsegnaRichiesta prima delle 3 speciali
$desiredOrder = [
'ClienteResponsabile',
'AnagraficaCertestObject',
'AnagraficaCertestService',
'MoltiplicatorePrezzo',
'ConsegnaRichiesta',
// se ci sono altri campi fixed li mettiamo dopo
];
$fixedFields = [];
$tempMap = [];
foreach ($fixedFieldsRaw as $f) {
$tempMap[$f['fixed_field_key']] = $f;
}
foreach ($desiredOrder as $key) {
if (isset($tempMap[$key])) {
$fixedFields[] = $tempMap[$key];
unset($tempMap[$key]);
}
}
// Aggiunge eventuali campi fixed non elencati sopra (alla fine)
foreach ($tempMap as $f) {
$fixedFields[] = $f;
}
// helper default (DATE can use 'today' if you already use it elsewhere) // helper default (DATE can use 'today' if you already use it elsewhere)
function fixedDefaultValue(array $f): string function fixedDefaultValue(array $f): string
@@ -709,24 +737,29 @@ function fixedDefaultValue(array $f): string
$headerIndex++; $headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>"; echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
$headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . ($slugMapping['filename_import'] ?? 'filename_import') . "<div class='resizer'></div></div>";
$headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . ($slugMapping['importdate'] ?? 'importdate') . "<div class='resizer'></div></div>";
?>
<?php
// ---------------- FIXED FIELDS HEADERS ----------------
$headerIndex++; // IMPORTANT: advance index after importdate
// ---------------- FIXED FIELDS HEADERS ----------------
if (!empty($fixedFields)) { if (!empty($fixedFields)) {
$insertedAfterConsegna = false;
foreach ($fixedFields as $f) { foreach ($fixedFields as $f) {
$key = $f['fixed_field_key']; $key = $f['fixed_field_key'];
$label = $slugMapping[$key] ?? $key; // if slug exists use it, else key $label = $slugMapping[$key] ?? $key;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 180px; position: relative;'>" echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 180px; position: relative;'>"
. htmlspecialchars($label) . . htmlspecialchars($label) .
"<div class='resizer'></div></div>"; "<div class='resizer'></div></div>";
$headerIndex++; $headerIndex++;
// Inseriamo le 3 colonne SOLO dopo ConsegnaRichiesta
if ($key === 'ConsegnaRichiesta' && !$insertedAfterConsegna) {
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
$headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . ($slugMapping['filename_import'] ?? 'filename_import') . "<div class='resizer'></div></div>";
$headerIndex++;
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . ($slugMapping['importdate'] ?? 'importdate') . "<div class='resizer'></div></div>";
$headerIndex++;
$insertedAfterConsegna = true;
}
} }
} }
?> ?>
@@ -862,70 +895,73 @@ function fixedDefaultValue(array $f): string
<span class="tracking-result">Shipment Info</span> <span class="tracking-result">Shipment Info</span>
<input type="hidden" name="rows[<?= $index ?>][tracking_info]" class="tracking-hidden"> <input type="hidden" name="rows[<?= $index ?>][tracking_info]" class="tracking-hidden">
</div> </div>
<div class="grid-cell" data-col="importreferencecode" data-row="<?= $index ?>" data-index="<?= $cellIndex ?>" style="flex: 0 0 150px;">
<span><?= htmlspecialchars($row['importreferencecode']) ?></span>
<input type="hidden" name="rows[<?= $index ?>][importreferencecode]" value="<?= htmlspecialchars($row['importreferencecode']) ?>">
</div>
<?php
$cellIndex++;
?>
<div class="grid-cell editable-cell" data-col="filename_import" data-row="<?= $index ?>" data-index="<?= $cellIndex ?>" style="flex: 0 0 150px;">
<a href="imported_trf/<?= htmlspecialchars($row['filename_import']) ?>" target="_blank">File</a>
<input type="hidden" name="rows[<?= $index ?>][filename_import]" value="<?= htmlspecialchars($row['filename_import']) ?>">
</div>
<?php
$cellIndex++;
?>
<div class="grid-cell editable-cell" data-col="importdate" data-row="<?= $index ?>" data-index="<?= $cellIndex ?>" style="flex: 0 0 150px;">
<span><?= htmlspecialchars($row['importdate']) ?></span>
<input type="hidden" name="rows[<?= $index ?>][importdate]" value="<?= htmlspecialchars($row['importdate']) ?>">
</div>
<?php <?php
// ---------------- FIXED FIELDS CELLS ---------------- // ---------------- FIXED FIELDS CELLS ----------------
$cellIndex++; // IMPORTANT: move to next data-index after importdate cell
if (!empty($fixedFields)) { if (!empty($fixedFields)) {
foreach ($fixedFields as $f) { foreach ($fixedFields as $f) {
$key = $f['fixed_field_key']; // datadb column name $key = $f['fixed_field_key'];
$val = $row[$key] ?? ''; $val = $row[$key] ?? '';
if ($val === '' || $val === null) { if ($val === '' || $val === null) {
$val = fixedDefaultValue($f); $val = fixedDefaultValue($f);
} }
$requiredClass = ((int)$f['is_required'] === 1 && ($val === '' || $val === null)) ? 'missing-required' : ''; $requiredClass = ((int)$f['is_required'] === 1 && ($val === '' || $val === null)) ? 'missing-required' : '';
$inputClass = 'manual-input'; $inputClass = 'manual-input';
if ((int)$f['is_required'] === 1) $inputClass .= ' required-input'; if ((int)$f['is_required'] === 1) $inputClass .= ' required-input';
echo "<div class='grid-cell editable-cell $requiredClass' echo "<div class='grid-cell editable-cell $requiredClass'
data-col='" . htmlspecialchars($key, ENT_QUOTES) . "' data-col='" . htmlspecialchars($key, ENT_QUOTES) . "'
data-row='$index' data-row='$index'
data-index='$cellIndex' data-index='$cellIndex'
style='flex: 0 0 180px;'>"; style='flex: 0 0 180px;'>";
if ($f['data_type'] === 'DATE') { if ($f['data_type'] === 'DATE') {
echo "<input type='text' echo "<input type='text'
name='rows[$index][$key]' name='rows[$index][$key]'
value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "' value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "'
class='cell-input date-picker $inputClass fixed-input' class='cell-input date-picker $inputClass fixed-input'
data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "' " data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "' "
. (((int)$f['is_required'] === 1) ? "required" : "") . (((int)$f['is_required'] === 1) ? "required" : "")
. ">"; . ">";
} else { // INT → diventa select se è uno dei campi API } else {
$isApiField = in_array($key, ['MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService']); $isApiField = in_array($key, ['MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService'], true);
$selectClass = $isApiField ? 'api-fixed-select' : ''; $selectClass = $isApiField ? 'api-fixed-select' : '';
echo "<select
echo "<select name='rows[$index][$key]'
name='rows[$index][$key]' class='cell-input $inputClass fixed-input $selectClass'
class='cell-input $inputClass fixed-input $selectClass' data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "'
data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "' data-current-value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "'
data-current-value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "' " . (((int)$f['is_required'] === 1) ? "required" : "") . ">
" . (((int)$f['is_required'] === 1) ? "required" : "") . "> <option value=''>Caricamento...</option>
<option value=''>Caricamento...</option> </select>";
</select>";
} }
echo "</div>"; echo "</div>";
$cellIndex++; $cellIndex++;
// === INSERIMENTO dopo ConsegnaRichiesta ===
if ($key === 'ConsegnaRichiesta') {
// Import Reference Code
echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>";
echo "<input type='hidden' name='rows[$index][importreferencecode]' value='" . htmlspecialchars($row['importreferencecode']) . "'>";
echo "</div>";
$cellIndex++;
// filename_import
echo "<div class='grid-cell editable-cell' data-col='filename_import' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
echo "<a href='imported_trf/" . htmlspecialchars($row['filename_import']) . "' target='_blank'>File</a>";
echo "<input type='hidden' name='rows[$index][filename_import]' value='" . htmlspecialchars($row['filename_import']) . "'>";
echo "</div>";
$cellIndex++;
// importdate
echo "<div class='grid-cell editable-cell' data-col='importdate' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
echo "<span>" . htmlspecialchars($row['importdate']) . "</span>";
echo "<input type='hidden' name='rows[$index][importdate]' value='" . htmlspecialchars($row['importdate']) . "'>";
echo "</div>";
$cellIndex++;
}
} }
} }
?> ?>