update moncler routine
This commit is contained in:
parent
a05d9fed2b
commit
7a486e9dcf
@ -5,71 +5,96 @@ ini_set('error_log', __DIR__ . '/routine_debug.log');
|
|||||||
function applyRoutine(&$excelData, $routineData)
|
function applyRoutine(&$excelData, $routineData)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Log iniziale
|
// Initial log
|
||||||
error_log("Inizio esecuzione routine Moncler: " . date('Y-m-d H:i:s'));
|
error_log("Inizio esecuzione routine Moncler: " . date('Y-m-d H:i:s'));
|
||||||
error_log("Dati routine: " . print_r($routineData, true));
|
error_log("Dati routine: " . print_r($routineData, true));
|
||||||
error_log("Dati excel_data: " . print_r($excelData, true));
|
error_log("Dati excel_data: " . print_r($excelData, true));
|
||||||
|
|
||||||
// Verifica se excelData è vuoto
|
// Check if excelData is empty
|
||||||
if (empty($excelData)) {
|
if (empty($excelData)) {
|
||||||
throw new Exception("excelData è vuoto o non valido.");
|
throw new Exception("excelData è vuoto o non valido.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estrai informazioni dalla routine con valori predefiniti
|
// Extract routine settings with default values
|
||||||
$action1 = trim($routineData['action1'] ?? 'K');
|
$action1 = trim($routineData['action1'] ?? 'K');
|
||||||
$action2 = trim($routineData['action2'] ?? 'STYLE CODE + STYLE DESCRIPTION');
|
$action2 = trim($routineData['action2'] ?? 'STYLE CODE + STYLE DESCRIPTION');
|
||||||
$action3 = trim($routineData['action3'] ?? 'STYLE CODE');
|
$action3 = trim($routineData['action3'] ?? 'STYLE CODE');
|
||||||
$action4 = trim($routineData['action4'] ?? 'STYLE DESCRIPTION');
|
$action4 = trim($routineData['action4'] ?? 'STYLE DESCRIPTION');
|
||||||
$headers = $routineData['xls_headers'] ?? [];
|
$headers = $routineData['xls_headers'] ?? [];
|
||||||
|
|
||||||
|
// Package-related headers
|
||||||
|
$package_header = 'PACKAGE';
|
||||||
|
$other_test_header = 'Other test from Control Matrix';
|
||||||
|
$only_colorfastness_header = 'Only Colorfastness package';
|
||||||
|
$only_chemical_header = 'Only Chemical package';
|
||||||
|
|
||||||
if (empty($headers)) {
|
if (empty($headers)) {
|
||||||
throw new Exception("Nessun header trovato per la routine Moncler.");
|
throw new Exception("Nessun header trovato per la routine Moncler.");
|
||||||
}
|
}
|
||||||
error_log("Header ricevuti: " . print_r($headers, true));
|
error_log("Header ricevuti: " . print_r($headers, true));
|
||||||
|
|
||||||
// Normalizza gli header (solo trim)
|
// Normalize headers
|
||||||
$normalized_headers = array_map('trim', $headers);
|
$normalized_headers = array_map('trim', $headers);
|
||||||
error_log("Header normalizzati: " . print_r($normalized_headers, true));
|
error_log("Header normalizzati: " . print_r($normalized_headers, true));
|
||||||
error_log("Action values - action1: '$action1', action2: '$action2', action3: '$action3', action4: '$action4'");
|
error_log("Action values - action1: '$action1', action2: '$action2', action3: '$action3', action4: '$action4'");
|
||||||
|
|
||||||
// Trova gli indici delle colonne
|
// Find column indexes
|
||||||
$action1_index = array_search($action1, $normalized_headers);
|
$action1_index = array_search($action1, $normalized_headers);
|
||||||
$action2_index = array_search($action2, $normalized_headers);
|
$action2_index = array_search($action2, $normalized_headers);
|
||||||
$action3_index = array_search($action3, $normalized_headers);
|
$action3_index = array_search($action3, $normalized_headers);
|
||||||
$action4_index = array_search($action4, $normalized_headers);
|
$action4_index = array_search($action4, $normalized_headers);
|
||||||
|
|
||||||
|
$package_index = array_search($package_header, $normalized_headers);
|
||||||
|
$other_test_index = array_search($other_test_header, $normalized_headers);
|
||||||
|
$only_colorfastness_index = array_search($only_colorfastness_header, $normalized_headers);
|
||||||
|
$only_chemical_index = array_search($only_chemical_header, $normalized_headers);
|
||||||
|
|
||||||
if ($action1_index === false || $action2_index === false || $action3_index === false || $action4_index === false) {
|
if ($action1_index === false || $action2_index === false || $action3_index === false || $action4_index === false) {
|
||||||
throw new Exception("Colonne non trovate - action1: '$action1' (index: " . var_export($action1_index, true) . "), action2: '$action2' (index: " . var_export($action2_index, true) . "), action3: '$action3' (index: " . var_export($action3_index, true) . "), action4: '$action4' (index: " . var_export($action4_index, true) . ")");
|
throw new Exception(
|
||||||
|
"Colonne non trovate - action1: '$action1' (index: " . var_export($action1_index, true) .
|
||||||
|
"), action2: '$action2' (index: " . var_export($action2_index, true) .
|
||||||
|
"), action3: '$action3' (index: " . var_export($action3_index, true) .
|
||||||
|
"), action4: '$action4' (index: " . var_export($action4_index, true) . ")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($package_index === false) {
|
||||||
|
throw new Exception("Colonna PACKAGE non trovata.");
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("Indici colonne - action1: $action1_index, action2: $action2_index, action3: $action3_index, action4: $action4_index");
|
error_log("Indici colonne - action1: $action1_index, action2: $action2_index, action3: $action3_index, action4: $action4_index");
|
||||||
|
error_log("Indici package - PACKAGE: " . var_export($package_index, true) . ", Other test from Control Matrix: " . var_export($other_test_index, true) . ", Only Colorfastness package: " . var_export($only_colorfastness_index, true) . ", Only Chemical package: " . var_export($only_chemical_index, true));
|
||||||
|
|
||||||
// Raggruppa le righe per il valore in action1 (colonna K)
|
// Group rows by action1 value
|
||||||
$grouped_data = [];
|
$grouped_data = [];
|
||||||
foreach ($excelData as $row) {
|
foreach ($excelData as $row) {
|
||||||
if (!isset($row['data']) || !is_array($row['data'])) {
|
if (!isset($row['data']) || !is_array($row['data'])) {
|
||||||
error_log("Riga non valida, manca 'data' per excelrow {$row['excelrow']}");
|
error_log("Riga non valida, manca 'data' per excelrow {$row['excelrow']}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = $row['data'][$action1_index] ?? '';
|
$key = $row['data'][$action1_index] ?? '';
|
||||||
$key = empty($key) ? '_empty_' : $key;
|
$key = empty($key) ? '_empty_' : $key;
|
||||||
|
|
||||||
if (!isset($grouped_data[$key])) {
|
if (!isset($grouped_data[$key])) {
|
||||||
$grouped_data[$key] = [
|
$grouped_data[$key] = [
|
||||||
'data' => $row['data'],
|
'data' => $row['data'],
|
||||||
'excelrow' => [$row['excelrow']],
|
'excelrow' => [$row['excelrow']],
|
||||||
'style_codes' => [],
|
'style_codes' => [],
|
||||||
'style_descriptions' => []
|
'style_descriptions' => [],
|
||||||
|
'packages' => []
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$grouped_data[$key]['excelrow'][] = $row['excelrow'];
|
$grouped_data[$key]['excelrow'][] = $row['excelrow'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separa il valore in action2 (STYLE CODE + STYLE DESCRIPTION)
|
// Split STYLE CODE + STYLE DESCRIPTION
|
||||||
$action2_value = $row['data'][$action2_index] ?? '';
|
$action2_value = $row['data'][$action2_index] ?? '';
|
||||||
if (!empty($action2_value)) {
|
if (!empty($action2_value)) {
|
||||||
$parts = explode(' - ', trim($action2_value));
|
$parts = explode(' - ', trim($action2_value), 2);
|
||||||
$style_code = $parts[0] ?? '';
|
$style_code = $parts[0] ?? '';
|
||||||
$style_description = $parts[1] ?? '';
|
$style_description = $parts[1] ?? '';
|
||||||
|
|
||||||
if (!empty($style_code)) {
|
if (!empty($style_code)) {
|
||||||
$grouped_data[$key]['style_codes'][] = $style_code;
|
$grouped_data[$key]['style_codes'][] = $style_code;
|
||||||
}
|
}
|
||||||
@ -79,24 +104,52 @@ function applyRoutine(&$excelData, $routineData)
|
|||||||
} else {
|
} else {
|
||||||
error_log("Valore vuoto in action2 per excelrow {$row['excelrow']}");
|
error_log("Valore vuoto in action2 per excelrow {$row['excelrow']}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect values to merge into PACKAGE
|
||||||
|
$package_values = [];
|
||||||
|
|
||||||
|
if ($package_index !== false) {
|
||||||
|
$package_values[] = trim((string)($row['data'][$package_index] ?? ''));
|
||||||
|
}
|
||||||
|
if ($other_test_index !== false) {
|
||||||
|
$package_values[] = trim((string)($row['data'][$other_test_index] ?? ''));
|
||||||
|
}
|
||||||
|
if ($only_colorfastness_index !== false) {
|
||||||
|
$package_values[] = trim((string)($row['data'][$only_colorfastness_index] ?? ''));
|
||||||
|
}
|
||||||
|
if ($only_chemical_index !== false) {
|
||||||
|
$package_values[] = trim((string)($row['data'][$only_chemical_index] ?? ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($package_values as $package_value) {
|
||||||
|
if ($package_value !== '') {
|
||||||
|
$grouped_data[$key]['packages'][] = $package_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea il nuovo array excel_data aggregato
|
// Build the new aggregated excel_data array
|
||||||
$new_excel_data = [];
|
$new_excel_data = [];
|
||||||
foreach ($grouped_data as $key => $group) {
|
foreach ($grouped_data as $key => $group) {
|
||||||
$row_data = $group['data'];
|
$row_data = $group['data'];
|
||||||
// Aggiorna action3 (STYLE CODE) e action4 (STYLE DESCRIPTION) con valori aggregati
|
|
||||||
|
// Update STYLE CODE and STYLE DESCRIPTION with aggregated unique values
|
||||||
$row_data[$action3_index] = implode(' - ', array_unique($group['style_codes']));
|
$row_data[$action3_index] = implode(' - ', array_unique($group['style_codes']));
|
||||||
$row_data[$action4_index] = implode(' - ', array_unique($group['style_descriptions']));
|
$row_data[$action4_index] = implode(' - ', array_unique($group['style_descriptions']));
|
||||||
// Concatena gli excelrow con '+' per le righe aggregate
|
|
||||||
|
// Merge PACKAGE-related columns into PACKAGE
|
||||||
|
$row_data[$package_index] = implode(' - ', array_unique($group['packages']));
|
||||||
|
|
||||||
|
// Concatenate excelrow values with "+"
|
||||||
$excelrow_value = count($group['excelrow']) > 1 ? implode('+', $group['excelrow']) : $group['excelrow'][0];
|
$excelrow_value = count($group['excelrow']) > 1 ? implode('+', $group['excelrow']) : $group['excelrow'][0];
|
||||||
|
|
||||||
$new_excel_data[] = [
|
$new_excel_data[] = [
|
||||||
'data' => $row_data,
|
'data' => $row_data,
|
||||||
'excelrow' => $excelrow_value
|
'excelrow' => $excelrow_value
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica excelData in-place
|
// Modify excelData in-place
|
||||||
$excelData = $new_excel_data;
|
$excelData = $new_excel_data;
|
||||||
|
|
||||||
error_log("Routine Moncler completata - Righe aggregate: " . count($new_excel_data));
|
error_log("Routine Moncler completata - Righe aggregate: " . count($new_excel_data));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user