From 377b25f823ee063a106bba4313613d8a3ece60ee Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 15 Jun 2023 10:22:05 +0200 Subject: [PATCH] #11579 Fix inventory table --- .../include/functions_inventory.php | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 3e1aa3b9d0..ba09ddd62f 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -707,17 +707,6 @@ function inventory_get_datatable( ) { global $config; - if ($utimestamp === 0) { - $data_last = db_get_row_sql( - sprintf( - 'SELECT `utimestamp`, `timestamp` - FROM tagente_datos_inventory - ORDER BY utimestamp DESC' - ) - ); - $utimestamp = $data_last['utimestamp']; - } - $offset = (int) get_parameter('offset'); $where = []; @@ -803,12 +792,29 @@ function inventory_get_datatable( $agent_data = []; $rows_tmp = []; foreach ($rows as $row) { - $agent_data[$row['id_agente']][] = $row; + $replace_agent_data = false; + if (isset($agent_data[$row['id_agente']]) === true) { + foreach ($agent_data[$row['id_agente']] as $key => $compare_data) { + if ($compare_data['id_module_inventory'] === $row['id_module_inventory'] + && $row['last_update'] > $compare_data['last_update'] + ) { + $agent_data[$row['id_agente']][$key] = $row; + $replace_agent_data = true; + } + } + } + + if ($replace_agent_data === false) { + $agent_data[$row['id_agente']][] = $row; + } } foreach ($agent_data as $id_agent => $data_agent) { - $rows_tmp['agent'] = $data_agent['name_agent']; foreach ($data_agent as $key => $agent_row) { + if (isset($rows_tmp['agent']) === false) { + $rows_tmp['agent'] = $agent_row['name_agent']; + } + $data_agent[$key]['timestamp'] = $agent_row['last_update_timestamp']; $data_agent[$key]['utimestamp'] = $agent_row['last_update'];