diff --git a/public/userarea/routines/valentino_compliance.php b/public/userarea/routines/valentino_compliance.php new file mode 100644 index 0000000..e3b09ff --- /dev/null +++ b/public/userarea/routines/valentino_compliance.php @@ -0,0 +1,99 @@ + &$row) { + if (!isset($row['data']) || !is_array($row['data'])) { + error_log("Routine field_id 347: invalid row structure at index {$rowIndex}."); + continue; + } + + $selectedValues = []; + + /* + * Check columns from P to AT. + * If the cell contains x, take the related column header. + */ + for ($columnIndex = $startColumnIndex; $columnIndex <= $endColumnIndex; $columnIndex++) { + $cellValue = strtolower(trim((string)($row['data'][$columnIndex] ?? ''))); + + if ($cellValue === 'x') { + $headerTitle = trim((string)($headers[$columnIndex] ?? '')); + + if ($headerTitle !== '') { + $selectedValues[] = $headerTitle; + } + } + } + + /* + * Add free text from column AU. + */ + $extraText = trim((string)($row['data'][$extraColumnIndex] ?? '')); + + if ($extraText !== '') { + $selectedValues[] = $extraText; + } + + /* + * Remove empty and duplicate values. + */ + $selectedValues = array_values(array_unique(array_filter($selectedValues, function ($value) { + return trim((string)$value) !== ''; + }))); + + /* + * Save final value into column P. + * Column P must be mapped to field_id 347 in the template mapping. + */ + $row['data'][$targetColumnIndex] = implode(', ', $selectedValues); + + error_log( + "Routine field_id 347: row " . + ($row['excelrow'] ?? $rowIndex) . + " generated value: " . + $row['data'][$targetColumnIndex] + ); + } + + unset($row); + + error_log("Routine field_id 347 completed."); +}