fixed importedit
This commit is contained in:
@@ -83,7 +83,35 @@ $fixedStmt = $pdo->prepare("
|
||||
ORDER BY 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)
|
||||
function fixedDefaultValue(array $f): string
|
||||
@@ -709,24 +737,29 @@ function fixedDefaultValue(array $f): string
|
||||
$headerIndex++;
|
||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
|
||||
$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)) {
|
||||
$insertedAfterConsegna = false;
|
||||
foreach ($fixedFields as $f) {
|
||||
$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;'>"
|
||||
. htmlspecialchars($label) .
|
||||
"<div class='resizer'></div></div>";
|
||||
$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>
|
||||
<input type="hidden" name="rows[<?= $index ?>][tracking_info]" class="tracking-hidden">
|
||||
</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
|
||||
// ---------------- FIXED FIELDS CELLS ----------------
|
||||
$cellIndex++; // IMPORTANT: move to next data-index after importdate cell
|
||||
|
||||
if (!empty($fixedFields)) {
|
||||
foreach ($fixedFields as $f) {
|
||||
$key = $f['fixed_field_key']; // datadb column name
|
||||
$key = $f['fixed_field_key'];
|
||||
$val = $row[$key] ?? '';
|
||||
if ($val === '' || $val === null) {
|
||||
$val = fixedDefaultValue($f);
|
||||
}
|
||||
|
||||
$requiredClass = ((int)$f['is_required'] === 1 && ($val === '' || $val === null)) ? 'missing-required' : '';
|
||||
$inputClass = 'manual-input';
|
||||
if ((int)$f['is_required'] === 1) $inputClass .= ' required-input';
|
||||
|
||||
echo "<div class='grid-cell editable-cell $requiredClass'
|
||||
data-col='" . htmlspecialchars($key, ENT_QUOTES) . "'
|
||||
data-row='$index'
|
||||
data-index='$cellIndex'
|
||||
style='flex: 0 0 180px;'>";
|
||||
data-col='" . htmlspecialchars($key, ENT_QUOTES) . "'
|
||||
data-row='$index'
|
||||
data-index='$cellIndex'
|
||||
style='flex: 0 0 180px;'>";
|
||||
|
||||
if ($f['data_type'] === 'DATE') {
|
||||
echo "<input type='text'
|
||||
name='rows[$index][$key]'
|
||||
value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "'
|
||||
class='cell-input date-picker $inputClass fixed-input'
|
||||
data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "' "
|
||||
name='rows[$index][$key]'
|
||||
value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "'
|
||||
class='cell-input date-picker $inputClass fixed-input'
|
||||
data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "' "
|
||||
. (((int)$f['is_required'] === 1) ? "required" : "")
|
||||
. ">";
|
||||
} else { // INT → diventa select se è uno dei campi API
|
||||
$isApiField = in_array($key, ['MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService']);
|
||||
} else {
|
||||
$isApiField = in_array($key, ['MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService'], true);
|
||||
$selectClass = $isApiField ? 'api-fixed-select' : '';
|
||||
|
||||
echo "<select
|
||||
name='rows[$index][$key]'
|
||||
class='cell-input $inputClass fixed-input $selectClass'
|
||||
data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "'
|
||||
data-current-value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "'
|
||||
" . (((int)$f['is_required'] === 1) ? "required" : "") . ">
|
||||
<option value=''>Caricamento...</option>
|
||||
</select>";
|
||||
echo "<select
|
||||
name='rows[$index][$key]'
|
||||
class='cell-input $inputClass fixed-input $selectClass'
|
||||
data-fixed-key='" . htmlspecialchars($key, ENT_QUOTES) . "'
|
||||
data-current-value='" . htmlspecialchars((string)$val, ENT_QUOTES) . "'
|
||||
" . (((int)$f['is_required'] === 1) ? "required" : "") . ">
|
||||
<option value=''>Caricamento...</option>
|
||||
</select>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user