Merge branch 'ent-6424-Cambio-menor-en-el-informe-de-inventario' into 'develop'

new options visual report inventory

See merge request artica/pandorafms!3515
This commit is contained in:
Daniel Rodriguez 2020-11-23 16:18:20 +01:00
commit bafe0942ee
1 changed files with 69 additions and 52 deletions

View File

@ -1492,7 +1492,7 @@ function reporting_html_inventory_changes($table, $item, $pdf=0)
function reporting_html_inventory($table, $item, $pdf=0) function reporting_html_inventory($table, $item, $pdf=0)
{ {
$return_pdf = ''; $return_pdf = '';
if (!empty($item['failed'])) { if (empty($item['failed']) === false) {
if ($pdf === 0) { if ($pdf === 0) {
$table->colspan['failed']['cell'] = 3; $table->colspan['failed']['cell'] = 3;
$table->cellstyle['failed']['cell'] = 'text-align: center;'; $table->cellstyle['failed']['cell'] = 'text-align: center;';
@ -1501,55 +1501,71 @@ function reporting_html_inventory($table, $item, $pdf=0)
$return_pdf .= $item['failed']; $return_pdf .= $item['failed'];
} }
} else { } else {
foreach ($item['data'] as $module_item) { // Grouped type inventory.
$type_modules = array_reduce(
$item['data'],
function ($carry, $it) {
$carry[$it['name']][] = $it;
return $carry;
},
[]
);
if (isset($type_modules) === true
&& is_array($type_modules) === true
) {
foreach ($type_modules as $key_type_module => $type_module) {
$table1 = new stdClass(); $table1 = new stdClass();
$table1->width = '99%'; $table1->width = '99%';
$table1->data = [];
$first = reset($module_item['data']); $table1->head = [];
$count_columns = count($first); $table1->cellstyle = [];
$table1->headstyle = [];
$table1->cellstyle[0][0] = 'background: #373737; color: #FFF;'; if (isset($type_module) === true
$table1->data[0][0] = $module_item['agent_name']; && is_array($type_module) === true
if ($count_columns == 1) { ) {
$table1->colspan[0][0] = ($count_columns + 1); foreach ($type_module as $key_type => $module) {
} else { if (isset($module['data']) === true
$table1->colspan[0][0] = $count_columns; && is_array($module['data']) === true
) {
array_pop($module['data']);
foreach ($module['data'] as $k_module => $v_module) {
$str_key = $key_type_module.'-'.$key_type.'-'.$k_module;
$table1->head[0] = __('Agent');
$table1->head[1] = __('Module');
$table1->head[2] = __('Date');
$table1->headstyle[0] = 'text-align: left';
$table1->headstyle[1] = 'text-align: left';
$table1->headstyle[2] = 'text-align: left';
$table1->cellstyle[$str_key][0] = 'text-align: left;';
$table1->cellstyle[$str_key][1] = 'text-align: left;';
$table1->cellstyle[$str_key][2] = 'text-align: left;';
$table1->data[$str_key][0] = $module['agent_name'];
$table1->data[$str_key][1] = $key_type_module;
$dateModule = explode(' ', $module['timestamp']);
$table1->data[$str_key][2] = $dateModule[0];
if (isset($v_module) === true
&& is_array($v_module) === true
) {
foreach ($v_module as $k => $v) {
$table1->head[$k] = $k;
$table1->headstyle[$k] = 'text-align: left';
$table1->cellstyle[$str_key][$k] = 'text-align: left;';
$table1->data[$str_key][$k] = $v;
}
}
}
} }
$table1->cellstyle[1][0] = 'background: #373737; color: #FFF;';
$table1->cellstyle[1][1] = 'background: #373737; color: #FFF;';
$table1->data[1][0] = $module_item['name'];
if (($count_columns - 1) > 0) {
$table1->colspan[1][0] = ($count_columns - 1);
} }
$table1->data[1][1] = $module_item['timestamp'];
$table1->cellstyle[2] = array_pad(
[],
$count_columns,
'background: #373737; color: #FFF;'
);
$table1->data[2] = array_keys($first);
if (($count_columns - 1) == 0) {
$table1->colspan[2][0] = ($count_columns + 1);
} }
$table1->data = array_merge(
$table1->data,
$module_item['data']
);
if ($pdf === 0) { if ($pdf === 0) {
$table->colspan[$module_item['name'].'_'.$module_item['id_agente']]['cell'] = 3; $table->colspan[$key_type_module]['cell'] = 3;
$table->data[$module_item['name'].'_'.$module_item['id_agente']]['cell'] = html_print_table( $table->data[$key_type_module]['cell'] = html_print_table(
$table1, $table1,
true true
); );
} else { } else {
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
$return_pdf .= html_print_table( $return_pdf .= html_print_table(
$table1, $table1,
true true
@ -1557,6 +1573,7 @@ function reporting_html_inventory($table, $item, $pdf=0)
} }
} }
} }
}
if ($pdf !== 0) { if ($pdf !== 0) {
return $return_pdf; return $return_pdf;